Programming Past Exam Questions
Programming Past Exam Questions
(b) Write code snippets that will accept an invalid identifier and perform the following tasks:
(i) If it is too long truncate it and discard the right most part. [5]
(ii) It then checks if there are any illegal characters and removes them. [12]
Hint: You may use the function defined in part (a) to perform checks by calling them.
3. Write a program code that will use a loop to create the array given below and accept its
values.
4. (a) A gas board has about 500 customers, each with a gas meter identified by a
unique code of 8 digits which include a check digit. The meter readings are taken every 3
months. If a meter cannot be read, an estimated reading is calculated.
(i) Write specifications of the data structure for the customer including the following details;
field name, type size and validation. [4]
(ii) Write a program that accepts gas meter code, previous reading, current reading and
calculates the amount of gas used using a rate of $3 per kg., calculates the amount due for
payment and displays the information on the screen. [14]
(b) Write a program to grade marks for 12 courses for a college student. Use any selection
statement of your choice. The grades are as follows:
>= 75 Distinction
60 – 74 Merit
50 – 59 Pass
40 – 49 Supplementary
<=39 Fail [12]
(c) (i) Draw a flowchart of a program that reads a number of seconds from
the user and display the number of hours, minutes and seconds. For example, if 10 000 is
typed in, the program should display 2 hours, 46 minutes and 40 seconds. [6]
(ii) Write a program and print the source code for the scenario in (i). [9]