Professional Documents
Culture Documents
Duration: 2 Hours
None
UFMFN7-15-1 Page 1 of 9
Instructions to Candidates:
(a) Consider the following problem specification that requires the development of software
that computes the monthly water bill for the West of England (WoE) Water customers.
• A customer’s monthly bill includes a £25 water demand charge plus a consumption
(usage) charge of £0.90 for every thousand gallons of water used.
• Consumption of water is figured from current and previous meter readings (in
thousands of gallons). Current meter reading is the one most recently taken and
the previous meter reading is the one taken at the end of the previous quarter.
• If the customer’s unpaid balance is greater than zero, a £5 late charge is added to
the bill as well.
Design a structure chart (structure diagram) for the water bill software. The structure chart
should show information passing between the modules.
(10 marks)
UFMFN7-15-1 Page 2 of 9
(b) Consider the following pseudocode which represents the functional steps of a program
to control a phone that can be only used to dial but not to receive calls.
Repeat Forever{
Wait for a new Event
Switch(state){
case Idle:
if (Event == Pickup)
state = Dialling
case Dialling:
if (Event == ReceiveRingTone)
state = RemoteEndRinging
if (Event == HangUp)
state = Idle
case RemoteEndRinging:
if (Event == RemoteEndAnswers)
state = Connected
if (Event == HangUp)
state = Idle
case Connected:
if (Event == HangUp)
state = Idle
} /*end switch*/
} /*end repeat*/
You are required to draw a State Transition Diagram to represent the pseudocode above.
(10 marks)
UFMFN7-15-1 Page 3 of 9
Question 2 (20 marks)
(a) Explain the following terms as used in a C-Program, providing examples to justify
your answer.
(i) Variable
(ii) Data type
(iii) Pre-processor directive
(9 marks)
1. #include <stdio.h>
2. #include <stdlib.h>
3.
4. void foo1(int a, int b){
5. static int c = 5;
6. if (a>b)
7. c = c + a;
8. else
9. c = c + b;
10. return c;
11. }
12.
13. int main(void) {
14. for(i=0 ; i<4 ; i++){
15. printf("\nResult: %d ", foo1(i,2));
16. }
17. return 0;
18. }
(i) The above program will fail to compile due to syntax errors. Identify the syntax
errors and correct the program for it to compile successfully.
(ii) Explain the purpose of the keyword static in the above C-program.
(iii) What is printed on the standard output when the above program is executed?
(11 marks)
UFMFN7-15-1 Page 4 of 9
Question 3 (20 marks)
start
Declare x and y
Read values
for x and y
Decrement x
true
Increment y
x>y?
false
e
Display values
for x and y
stop
(6 marks)
(ii) What value is printed on standard output with the following values: x=4,
y=2;
(2 marks)
UFMFN7-15-1 Page 5 of 9
(a) Explain, using an appropriate example what you understand by a nested loop.
(4 marks)
#include <stdio.h>
#include <stdlib.h>
int main(void) {
return 0;
}
The above program needs to request the user to enter a floating point value from
the standard input and test whether that value is within the specified range ( range1
< value < range2), assuming that the values for range1 and range2 are already
provided in the program. The program then displays a message on the standard
output to indicate whether the value entered was within range or out-of-range.
(8 marks)
UFMFN7-15-1 Page 6 of 9
Question 4 (20 marks)
(b) Explain, using appropriate examples, what the following operators are used for
when using pointers in a C-program:
(i) addressing operator
(ii) dereferencing operator
(6 marks)
The function is called from main() using the statement swap(x,y) where x and y
are integers defined in main(). The intention is that the values of x and y in main()
are swapped.
(3 marks)
(ii) Re-write the function implementation of swap for it to achieve its purpose and show
how it is called in main(). (Hint: use pointers)
(5 marks)
UFMFN7-15-1 Page 7 of 9
Question 5 (20 marks)
(b) Write the implementation of a C-Program function named CheckSign that takes as
input an integer number and returns a ‘1’ if the number is positive, a ‘-1’ if the
number is negative, or otherwise it returns a ‘0’.
(5 marks)
#include <stdio.h>
int main(void) {
int myArr[]={-2,3,-4};
return 0;
}
The program will need to make function calls to the CheckSign function defined in
(b) to check the sign of the each value in the array myArr[] and will need to
convert any negative value to a positive value.
(4 marks)
(d) Explain what you understand by the term ‘modular decomposition’ when writing C-
programs.
(3 marks)
(e) List TWO advantages of using a modular decomposition approach when coding C-
programs.
(4 marks)
UFMFN7-15-1 Page 8 of 9
Question 6 (20 marks)
(a) Write a C-program code segment that allows you to insert a software delay in a
program.
(4 marks)
(i) What is the result of executing the above function when n=2.
(ii) Rewrite the function but this time using a while loop.
(6 marks)
(d) Explain, using an appropriate example, what is the purpose of using the break
statement within switch-case statement in C-programs.
(5 marks)
UFMFN7-15-1 Page 9 of 9