Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

CS/APR2008/CSC415

CONFIDENTIAL

UNIVERSITI TEKNOLOGI MARA


FINAL EXAMINATION

COURSE

FUNDAMENTALS OF COMPUTER PROBLEM


SOLVING

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)

the Question Paper


an Answer Booklet - provided by the Faculty

DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO


This examination paper consists of 10 printed pages
Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/APR 2008/CSC415

PART A (20 MARKS)

1.

Stages of compilation in order are:


I.

2.

ii.
iii.
iv.

link
compilation
execute
precompilation

A.
B.
C.
D.

i, ii, iii and iv


ii, iii, iv and i
iv, i, ii and iii
iii, i, ii and iv

Which of these commands would give you access to the p r i n t f function?


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-);

Which of the following declarations could store the number 8 . 5?


A.
B.
C.
D.

char num;
int num;
float num;
real num;

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CS/APR2008/CSC415

CONFIDENTIAL

6.

Given two variables:


int

=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

= 3) && (j <> i))


== (j - 2)) || (i
!= j) && ((i - j)
== j) && (i < j))

printf("TRUE");
== j)) printf("TRUE");
==2)) printf("TRUE");
printf("TRUE");

What is the output of the following program segment?

int count = 0, sum = 0;


while (count < 5)
{ sum = sum + 3 * count;
count = count + 2;
printf("%d", sum) ;

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",

Hak Cipta Universiti Teknologi MARA

letters);
letters);
letters);
letters[2]);

CONFIDENTIAL

CONFIDENTIAL

10.

CS/APR 2008/CSC415

The following statements about parameter passing by value is correct EXCEPT


A.
B.
C.
D.

the actual and formal parameters must be of similar types.


the actual parameters in a function may be constants or variables.
a copy of the value of actual parameters is made in the memory.
changes made by the called function on formal parameters will be reflected on the
corresponding actual parameters.

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CS/APR2008/CSC415

CONFIDENTIAL

PART B (80 MARKS)


QUESTION 1
a)

Define the following terms:


i.
ii.

reserved words
variables
(4 marks)

b)

Convert the following pseudo code into C statements:

if salary is less than or equal to RM10,000


begin
tax = 0 .03 x (salary - RM8000)
print " Tax rate is 3%."
end
else
begin
tax = 0 .05 x (salary - RM5000)
print " Tax rate is 5%/"
end
end if
print tax

(7 marks)

c)

Write a C assignment statement for each of the following:


i.

Declare a char variable status and set the value of grade to 'L'

(1 mark)

ii.

Update the value of an i n t variable count by adding 8 to it.

(1 mark)

iii.

3
3
Area = a
(f -+Jb
17

(2 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CS/APR2008/CSC415

CONFIDENTIAL

QUESTION 2

a)

b)

Write a C program segment for each of the following:


i.

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)

Given the following declaratbn:


int

sum = 65;

Show the output to the program segment below:


i.

if

(sum > 50)


printf( "nice try");
else if (sum > 60)
printf( "try again");
else
printf( "good guess");
(2 marks)
if

(sum > 50)


printf ("nice try");
if (sum > 60)
printf ("try again");
if (sum > 70)
printf ("good guess");

(2 marks)

Hak Cipta Universiti Teknologi MARA

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)

Given a complete C program below:

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.

Correct the indentation to make the program more readable.


(3 marks)

ii.

Show the output of the above program using the following data as input:
13

4 - 7

(3 marks)

Hak Cipta Universiti Teknologi MARA

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)

Write a program segment to solve each of the following problems:


i.

Use a nested f o r loops to produce the following output:


a
bb
ccc
dddd
eeeee

(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)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/APR 2008/CSC415

QUESTION 4

a)

Write the definition for each of the following functbns:


i.

average () that receives three integers, calculate and returns the average.
(2 marks)

ii.

C y l i n d e r V o i u m e () that receives the radius and height of a cylinder, calculate


and returns the volume using the formula:
volume = pi * radius 2 * height.
where pi is an constant value p i = 3.14159
(2 marks)

b)

Consider the following function:

void shape(int size , char ch)


r
{

for (int k = 1; k <= size; k++)


r

for(int j = 1;j <= size; j++)


if ((k == j ) II ((k + j) == (size + 1)))
printf(" -s c ", ch) ;
else
printf (" ") ;
printf(" \n ") ;

}
}

Write an appropriate function prototype for the function shape.


(2 marks)
What is the output after the function call in the following statement is executed?
shape

(5,

# ' ) ;
(3 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/APR2008/CSC415

10

QUESTION 5

Hotel Season View offers various types of room for reservation.


reservation based on the following information:
Types of Room
Economy
Standard
Double
Deluxe

Each client can make a

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:

The number of clients


The most popular room and number of its reservation made for that day
The total reservation for each type of room
Total reservation for that day
(18 marks)

END OF QUESTION PAPER

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

You might also like