You are on page 1of 8
Ines Caureate International Universities FINAL Examination Paper (COVER PAGE) Session : January 2010 Programme : B.Sc, (Hons) Network and Mobile Computing (BNMCD “Bachelor of Engineering (Hons) in Civil Engineerin, ring (Hons) in Civil Engineering (BCEGI) ___ “Bachelor of Engineering (Hons) in Mechanical Engineering (BMEGI) Course : Date of Examination: 12 April 2010 ime > _08:00- 10:00 Reading Time Duration : 2 Hours Special Instructions This paper consists of SIX (6) questions. Answer any FOUR (4) questions in the answer booklet provided. All questions carry equal marks. Materials permitted Nil Materials provided Nil : Examiner(s) ; Kavitha Sivashanmugam and Chong Fong Kim Moderator : Po Jiang Ling d This paper consists of 7 printed pages, including the cover page. CSC 2203 (F) / Page | of 6 INTI UNIVERSITY COLLEGE B.SC(HONS) NETWORK AND MOBILE COMPUTING PROGRAMME (BNMC1) BACHELOR OF ENGINEERING (HONS) IN CIVIL ENGINEERING PROGRAMME (BCEGI) BACHELOR OF ENGINEERING (HONS) IN MECHANICAL ENGINEERING PROGRAMM (BMEGI) CSC2203: INTRODUCTION TO PROGRAMMING FINAL EXAMINATION: JANUARY 2010 SESSION ‘This paper consists of SIX (6) questions. Answer any FOUR (4) questions in the answer booklet provided. Ail questions carry equal marks. Question 1 (e) What are the outputs produced by the following code fragment? int a=3, b=0, €=0; a=bt/a; c= bt / b+ printf(“%Sd%5d%Sd\n”, a, b, 65 asttb+ cts a=—b+e-5 printf(“%5d%5d%Sd\n”, a, b, ¢); float e = 10.0; et= by printf(“%.21%7d\n”, ¢, b)s (8 marks) (6) Let num be an array of 20 integers. Write a C program that first fills the array with up to 20 input values and then finds and displays the value ofthe largest and smallest number. Calculate and display the difference between the largest and smallest number. (15 marks) (©) Show the values of x after the execution of the following statements i) x= 124 349445/3-1 i) x= 10 %10+10* 1010/10 (2 marks) CSC 2203 (F)/ Page 2 of 6 Question 2 (a) Consider the following C program fragments: i) for (=0, j=0; i<= 20; i++) { if (%2) continue; if (= 15) break; jah } printf(“The value of j is d\n”, j); “What does the continue and break statements do in this program fragment? (4 marks) i) “Trace the output for the following C program fragment: for (num=0; num < 103 num++) printf(“%od ”, num); If the programmer is actually intend to print the numbers from 1 to 10. How would you correct the above program fragment? G marks) (b) A form contains the following information: Employee Information ‘Name: Jones Months: 80 Wage: RM14.01 i) Declare a data structure to record the above information. [Note: the name of structure is rec] (S marks) ii) Declare an array of 100 structures for the above data structure. [Note: the name of the array structure is employee_rec] (2 marks) iil) Write a fragment of C code to show how you will assign information into the three fields. [Note: Assume that there is only one record.] (6 marks) CSC 2203 (F)/ Page 3 of 6 (©) What will be output if you will compile and execute the following ¢ code? i) void main() { int x-28, 5, 23 int *a; a= &x; zeta; sarytl2; printi("x is %d y is %d zis %d\n”, x, y, 2); Sattar arty printf(*x is %d y is Yod z is %dln”, x,y,z); printt(*a is %ed\n”, *a); } void main() ( int const * j=6; print(%d, +4()s } (2.5 marks) (2.5 marks) CSC 2203 (F)/ Page 4 of 6 Question 3 (a) Identify whether there is any syntax error(s) in every line of the following program. If there is an error in a line of statement, state the reason and correct it by rewrite the particular statement. a /* Ata state college, the local students pay only $30 per credit, whereas the other students wvill pay $50 per credit, Write @ program in which the user inputs the student's status (1 for local and 2 for international student) and the number of credits. */ Line 1 #include Line2 void main Lines { Line 4 integer status, credit, cost; Line 5 print®(Please enter your status (1 for local 2. International): “); Line 6 scanft“%d”, status); Line 7 printf(“Please enter credit(s) no.: “); Line 8 seanf(“%"”, credit); Line 9 switch (credit); Line 10 { Line 11 case “1"; Line 12 cost = credit * 30; Line 13 printf(“You are a local student. You have take %d credits with $\n”, credit, cost); Line 14 break; Line 15 case ‘2" : Line 16 cost = credit * 50; Line 17 printf(You are an international student. You have take %d credits with $%d\n, credit, cost”); Line 18 break; Line 19 Default: printf(“Invalid entry number \n"); break; Line 20 } Line21} (15 marks) (6) Write a program that will prompt the user to enter 10 integer numbers. Your program should display the sum and average of all even numbers. [Note: You are required to use while loop] (10 marks) cere rerererranenEEINTETS TT ET CSC 2203 (F)/ Page 5 of 6 Question 4 (@) Writea program using siructure that asks the user to type the Price without tax of one kilogram Wronions, the number of kilograms 2° sey buy and the tax in percent units ‘The program ort write the tal price including xeS- (8 marks) (o) Write a program tht requests an exam score and assigns 2 etter grade with the scale 90-100 (As), 80-89 (A), 70-79 (B+), 60-69 (B), 50-59 (Cr) *teag. (C), 0-39 (D). Use Switch statement. (12 marks) (o)_ Write a program by using & njested Joops that will print the folowing output: [Note: You are required to use a for 1ooP] XYZ YZ LZ 6 marks) Question 5 (a) Write a program that reads an integer between 0 and 1000 and adds all che digits in the integer. For example, if an integer is 185, the sum of its entire digit 16 14. (10 marks) (o) Write @ program thet ‘wll caloutate the gross pay of an employe by calculating the working ars with pay rate. Example if the jvorking hours is 40 and the pay rate is $20, then the gross pay is 40 * $20 = $800. ‘Smnain the working hours and pay rate from users input. 6 marks) (© Given three arrays Al “A2,83 seach can store 10 iMteEer \Weite a program that will prompt the ory to enter the data into Al and Mo Compare each element of array ‘A to its corresponding jement in array A2 Assign "1,0,41 to the corresponding clement in A3 based on the following conditions «1 ifelement in AT is greater than element in A2. * p ifelement in AT is equal to the ‘element in A2. 2-1 if element in A1 is less than the element in A2. (9 marks) CSC 2203 (F)/ Page 6 of 6 Question 6 fa) (b) © Check the following variable names are valid (or) invalid, explain why. i, temper ii, fand-no iii, 9hallo iv, coursecode vy. main vi. percent_raise vii, cost of (7 marks) Kiesha’s Restaurant is offering a discount sale for the Valentine's Day celebration. ‘The discount policy is as following: Events Sales more than RM500__| Sales less than RM5S00 Valentine Lunch | Discount 20% Discount 15% Valentine Hi-tea__| Discount 10% Discount 5% [Valentine Dinner | Discount 30% Discount 25% Others No discount Write a program to implement the discount policy using a selection structure to select and the discount rate for the items: Valentine Lunch, Valentine Hi- tea, Valentine Dinner and Others. (10 marks) Write a program that calculates the size of a box. The main function should prompt the user to enter the width, height, and length of the box. This information should be passed to a function called calculate Volume. The function calculateVolume should pass the result back to the main function to be displayed to the user, (8 marks) - The End - (€52203(FYANIOIKAVITH 240310

You might also like