August
1999 QUESTION 5 Total Marks: 20 Marks |
Click here to access other
questions
SUGGESTED SOLUTIONS |
(a) | Explain what an expression is in C. | [2] |
An expression is
|
||
(b) | An assignment is one kind of expression in C. Explain what is meant by the term assignment. | [2] |
An assignment is the
way in which
|
||
(c) | Write a function, called RunningTotal, which takes on value parameter, x, and returns a running total of all the values passed to the function during the execution of the program so far. | [4] |
A sample definition of
RunningTotal follows: int
RunningTotal(int x) {
|
||
(d) | Using a switch statement, write a function foobar, which takes a character as a parameter. If the character passed in is "a" or "A", the function should exit immediately. If the character passed in is "b" or "B", nothing should happen. For any other value, the function should cause the program to exit immediately with a value of -1. | [6] |
A sample definition of
foobar follows: void
foobar(char x) {
|
||
(e) | Write a function called fun that prompts the user to enter a number in the range 0-9. If the number entered is outside the required range, the prompt to the user should be repeated, otherwise the function will return the integer selected by the user. | [6] |
A sample definition of fun follows: int fun( ) {
|