Mock Exam Dec 2014
Mock Exam Dec 2014
Carry out ALL the tasks given. For your guidance, the approximate mark for each
part of a task is indicated in brackets.
Great importance is attached to the accuracy, layout and labeling of diagram and
computer-generated outputs.
You are reminded of the necessity for good English and orderly presentation of
your answers.
Record in the booklet provided any information requested or that you believe
would make it easier to understand how you carried out task and answered
questions
If need be, supervisors will assist you in recording details of intermediate work
carried out on the computer
INSTRUCTIONS
A folder should be created on the desktop carrying your name. All of your files should be saved
in that folder. Only the extension .c is accepted for any c program file and .docx for any word
processor document.
1. Type faithfully the program, save it as TaskA (make sure that your extension is .c). Compile
it, and make sure it contains no error. (4 mks)
2. Run the program using the following data: 12 4 11 18 9, capture the screen and paste it in a
blank word document to be saved as outputA1 (2 mks)
3. In your answer booklet copy and complete the following able (3 mks)
Variable Data type Its role in the program
k integer Represent the counter of values in the for loop
… … …
4. Justify why “%f” is used in line 10 instead of “%d” an in lines 9 and 16 (2 mks)
5. Explain the meaning of line 13 of the program and give another way of writing it. (2 mks)
6. What is the role of the instruction “#include<stdio.h>”? (2 mks)
(NB: to capture an active screen on windows press ALT+PRTSCR and paste it in the
concerned word document)
1- Modify the program TaskA to receive 8 maks instead of 5 and save it as TaskB1. Use the
following data for the execution 12 4 11 18 9 6 14 10 (2 mks)
2- Modify the program TaskA to display the number of people who failed the test instead the
number who passed. Save it as TaskB2 (2 mks)
3- Rewrite the program TaskA using a while loop instead of the for loop and save it as TaskB3
(no execution is needed for this question ) (3 mks)
4- Modify the program TaskA to calculate and display the sum of all the passed marks entered
and save it as TaskB4 (3 mks)
5- Modify the program TaskA to calculate and display the sum of all the marks entered and save
it as TaskB5 (3 mks)
6- Modify the program TaskA to calculate and display the average of the marks entered and
save it as TaskB6 (3 mks)
7- Modify the program TaskA to prompt the user for the number of marks to enter. Use the
following data for input: 6 12 4 11 18 9 10 The expected output is shown in the appendix 2
(4 mks)
APPENDIX 1: Progrm to analyse marks APPENDIX 2: Example of output for Task B question 7
1 #include<stdio.h>
2
3 int main()
4 {
5 float mark;
6 int k, pass=0;
7 for(k=1;k<=5; k++)
8 {
9 printf("Enter mark for student %d: ", k);
10 scanf("%f", &mark);
11 if(mark>=10)
12 {
13 pass++;
14 }
15 }
16 printf ("%d people passed the test", pass);
17 return 0; APPENDIX 3: Example of output for Task C
18 }