15.01.2015 Views

CCSB163 Final - Mar 2007.pdf - MetaLab - Universiti Tenaga Nasional

CCSB163 Final - Mar 2007.pdf - MetaLab - Universiti Tenaga Nasional

CCSB163 Final - Mar 2007.pdf - MetaLab - Universiti Tenaga Nasional

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

SECTION B: SHORT ANSWERS (5 QUESTIONS, 40 MARKS)<br />

Instruction: Please answer ALL the questions. DO NOT show any working<br />

unless stated by the question.<br />

s<br />

Question 1<br />

(a)<br />

Rewrite the following code using code fragment using switch statement:<br />

if (ch == 'E' || ch =='e')<br />

countE++;<br />

else if (ch == 'A' || ch == 'a')<br />

countA++;<br />

else if (ch == 'I' || ch == 'I')<br />

countI++;<br />

else<br />

printf("Error –Not A,E, or I\n");<br />

[5 marks]<br />

(b)<br />

If originally x=0, y=0, and z=0, what is the value of x, y, and z after<br />

executing the following code<br />

if (x)<br />

if (y)<br />

if(z)<br />

z=3;<br />

else<br />

z=2;<br />

[3 marks]<br />

Question 2<br />

(a) Declare a void function named my_func with ONE (1) parameter of type float<br />

[2 marks]<br />

(b)<br />

Briefly describe the difference between a GLOBAL variable and a LOCAL<br />

variable.<br />

[2 marks]<br />

Semester 2 2006/2007<br />

Page 8 of 11<br />

Principles of Programming

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!