Professional Documents
Culture Documents
CSC415
CSC415
CONFIDENTIAL
COURSE
COURSE CODE
CSC415
EXAMINATION
APRIL 2008
TIME
3 HOURS
INSTRUCTIONS TO CANDIDATES
1.
This question paper consists of two (2) parts : PART A (10 Questions)
PART B (5 Questions)
2.
Answer ALL questions from all two (2) parts. Answer PART A and PART B in the Answer
Booklet. Start each answer on a new page.
3.
Do not bring any material into the examination room unless permission is given by the
invigilator.
4.
Please check to make sure that this examination pack consists of:
i)
ii)
CONFIDENTIAL
CONFIDENTIAL
CS/APR 2008/CSC415
1.
2.
ii.
iii.
iv.
link
compilation
execute
precompilation
A.
B.
C.
D.
3.
The correct definition for a variable called r i n g g i t which can be used to store currency is
A.
B.
C.
D.
4.
ringgit : real;
real ringgit;
float ringgit;
ringgit float;
The correct scanf statement to read a string of characters into the array called words is
A.
B.
C.
D.
5.
include stdio.h;
include conio.h;
#include <stdio.h>
#include conio.h
scanf("%s\n", words);
scanf("%c\n", words);
scanf("%t", words);
scanf ("%c", words-);
char num;
int num;
float num;
real num;
CONFIDENTIAL
CS/APR2008/CSC415
CONFIDENTIAL
6.
=3;
int
j = 5;
Which of the following condition will cause the word "TRUE" to be displayed?
A.
B.
C.
D.
7.
if
if
if
if
((i
((i
((i
((i
printf("TRUE");
== j)) printf("TRUE");
==2)) printf("TRUE");
printf("TRUE");
A.
B.
C.
D.
10
12
16
18
The statement which can be used to declare a character based array called s t r of six
elements is
A.
B.
C.
D.
char str[6];
string str;
char str[5];
string str[6];
Which of the following statements will print out the contents of the character based array
called l e t t e r s ?
A.
B.
C.
D.
printf("%s\n",
printf("%c\n",
printf("%d\n",
printf("%s\n",
letters);
letters);
letters);
letters[2]);
CONFIDENTIAL
CONFIDENTIAL
10.
CS/APR 2008/CSC415
CONFIDENTIAL
CS/APR2008/CSC415
CONFIDENTIAL
reserved words
variables
(4 marks)
b)
(7 marks)
c)
Declare a char variable status and set the value of grade to 'L'
(1 mark)
ii.
(1 mark)
iii.
3
3
Area = a
(f -+Jb
17
(2 marks)
CONFIDENTIAL
CS/APR2008/CSC415
CONFIDENTIAL
QUESTION 2
a)
b)
Update the value of newitem by adding the value of the named constant V A L U E .
Then display the output of the newitem with an appropriate message.
(3 marks)
ii.
Prompt the user to enter positive numbers and then store the number into
newData. Display the error message if the user input an invalid number.
(3 marks)
sum = 65;
if
(2 marks)
CONFIDENTIAL
CS/APR2008/CSC415
CONFIDENTIAL
c)
Correct the syntax and logic error of the code below that count the number of students
who score within 80 to 100 in a test until a sentinel value-1 is entered.
float score;
int countA = C ;
scanf ("%d",&score);
while (score === -1)
t
if ((score >= 80) || (score <= 100))
countA++ r
scanf("%d", &score);
}
(5 marks)
QUESTION 3
a)
void main ()
{
i n t x, y;
printf("Please enter an integer:");
scanf("%d",&x);
while (x > 0)
{
if (x % 2 == 0)
printf("The number is XXX\n");
else
printf("The number is YYY\n");
printf("Please enter an integer:");
scanf("%d",&x);
i.
ii.
Show the output of the above program using the following data as input:
13
4 - 7
(3 marks)
CONFIDENTIAL
CONFIDENTIAL
iii.
b)
CS/APR 2008/CSC415
Based on the results on ii., what is the appropriate word to replace xxx and YYY in
the output statements?
(2 marks)
(5 marks)
ii.
Use a w h i l e loop to print integer values from start to end value. The user has to
input the s t a r t and end value. For example, if user input s t a r t value = 3 and
end value = 10, the output will be as follows:
Input start value: 3
Input end value: 10
Output:
3 4 5 6 7 8 9
10
(5 marks)
iii.
Declare an integer array called numbers to store five elements entered by the user.
Use a f o r loop to total the contents of numbers. Store the result in an integer
called t o t a l .
(5 marks)
CONFIDENTIAL
CONFIDENTIAL
CS/APR 2008/CSC415
QUESTION 4
a)
average () that receives three integers, calculate and returns the average.
(2 marks)
ii.
b)
}
}
(5,
# ' ) ;
(3 marks)
CONFIDENTIAL
CONFIDENTIAL
CS/APR2008/CSC415
10
QUESTION 5
Tariff
89.00
100.00
125.00
135.00
Every client is charged 5% government tax and 10% service charge. Write a program that will
help the reservation counter to input the quantity and type of room booked by clients. The
program will calculate the total price that client has to pay. This process will continue until end of
day and will terminate when reservation counter requests to stop.
The program must produce the following report at the end of the day:
CONFIDENTIAL