SECTION A: PROGRAMMING (50 marks)
I STRUCTURED PROGRAMMING (in c programming language) (25 marks)
a. The strength of the password system relies on the fact that the value MUST be TRUE to
have access. Write a program that prints “enter the passdigit” the first time , gets a value
from the user and keeps printing “enter the correct passdigit” until the correct value is
entered and prints “condition is satisfied, you may have access”. The value of the passdigit
is “1234” [4 mks]
b. Write a c program that swaps two integers passed by reference. The program should show
function declaration, function definition and function call. Prompt the user to enter two
integers. Display them before and after the call of swap function. First write the program
in your answer sheet before implementing practically [3 mks]
c. Write a recursive function to take the value 3 to the power of another number. For example,
if 4 is passed, the function will return 81. . First write the program in your answer sheet
before implementing practical [3 mks]
d. An election consist of five candidates Paul Biya, Kamto , Joeshua Osi,Cabral Linii, Adamou
Dam Njoya . Create an array of structures to store names, age and the number of votes of
each voter. Each polling station has registered voters. We are considering only one polling
station and we are not managing cases of double voting or identification before voting. The
program will prompt a poling stating to enter the number of registered voters in that station.
Then the program will prompt all the users to vote a single candidate using a do while loop.
When the voter casts a vote, the number of votes of that particular voter is incremented.
Using your knowledge in pointers and their relationship with arrays, display the election
results starting from the winer to the worst loser. The result should be displayed in a table
comprising all information stored about all the candidates.[15 mks]
II. OBJECT ORIENTED PROGRAMMING ( In C++ or Java ) (25 marks)
a. Imagine a publishing company that markets both book and audiocassette versions of its
works. Create a class publication that stores the title (a string) and price (type float) of a
publication. From this class derive two classes: book, which adds a page count (type int), and tape, which adds a playing time in minutes (type float). Each of these three classes
should have a getdata() function to get its data from the user at the keyboard, and a
putdata() function to display its data. Write a main() program to test the book and tape
classes by creating instances of them, asking the user to fill in data with getdata(), and
then displaying the data with putdata(). [15 mks]
b. Start with the publication, book, and tape classes of Exercise .a. bove, Add a base class sales
that holds an array of three floats so that it can record the dollar sales of a particular
publication for the last three months. Include a getdata() function to get three sales amounts
from the user, and a putdata() function to display the sales figures. Alter the book and tape
classes so they are derived from both publication and sales. An object of class book or tape
should input and output sales data along with its other data. Write a main() function to create
a book object and a tape object and exercise their input/output capabilities. [5 mks]
c. Assume that the publisher in Exercises a. and b. decides to add a third way to distribute
books: on computer disk, for those who like to do their reading on their laptop. Add a disk
class that, like book and tape, is derived from publication. The disk class should incorporate
the same member functions as the other classes. The data item unique to this class is the
disk type: either CD or DVD. You can use an enum type to store this item. The user could
select the appropriate type by typing c or d. [5 mks]