Download as pdf
Download as pdf
You are on page 1of 15
UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING FINAL EXAMINATION, APRIL 25, 2007 APS 106 - FUNDAMENTALS OF COMPUTER PROGRAMMING Examiners: F, Baron, M. Bussmann, L. Shu, V. Sinnathurai Student Name (print): - _ Student Name (signature): Student Number: DO ALL WORK IN THIS BOOKLET, AND DO NOT SEPARATE THE PAGES IMPORTANT NOTE: If your C code program contains errors, part marks will be awarded for a cortect algorithm. However, a statement of your algorithm is not required for full marks. Marks will be awarded for correctness of your algorithm, C syntax, adherence to recommended C coding practice, code efficiency, and the clarity of your program. Open book (Type X) Al calculators atlowed; no computers allowed ‘Time allotted: 2 hours and 30 minutes (3 minutes per mark) Question Maximum Mark Actual Mark 1 7 2 5 3 8 4 6 7 5 6 6 8 Total 50 : Page 1 of 15 Question 1. Write your answers in the boxes. For the nine parts of Question 1, you may assume that the appropriate libraries have been included, and that a system (“pause”) isn’t necessary, (a) [1 mark] What is the output of the following? int A= Hf /kHts j= teK/its k= HHasitts printf(*Sd %d %d\n", i, 3, KY (b) [2marks] What's the output? int 10, j= 4, KE) = (14, 21), m= 18, *ptr = &mj for (i = 0; i < sizeof(k) / sizeof(k{0]); it) { af (1(KLIS) = 2)) printf(*hello world "); printf(*%din", *pte = j++); ) else { printf ("goodbye world *); printf(*Rd\n", *ptr = j#=2)5 } printf(*j = %d, m= %d \nyj, m)j Page 2 of 15 (0 [2marks} A structure, Date, is defined globally, and an array of tl and initialized. What is the output generated by the two printf statments? type, study, is declared struct Data { char group; int trials; float avg; % int main ( ) { struct Data studyf] = {{*A',10,2.34}, {*BY,8,3.14),{'6",11,1.99})5 printf (*%c\n", study{1] group); printf(*%0.2f\n", study(2) avg); return 0; (d) [2 marks] What's the output? int fre (int i, int *}) { “pe return *j3 } int main () { int i, j for (i=0; i<4; it+) i= fre (i, 85); printf (*\n\n %d ¥d\n\nr, i, 5)5 return 0; Page3 of 15 (c) [1mark] A student, Joe Stranger, wrote the following program to write his name to a log file “mylog. txt". int main ( ) 4 FILE * out_file; fprintf(out_file, ‘Joe Stranger*); felose(out_file); return 0; y What is the missing statement? (Q [1mark] An array of integers af} begins at address OOO0ABCD. If an integer is stored in four bytes, what is the address of a1 4)? Page 4 of 15 (g) (2marks] What is the output? char string[11} = "helloworld*; int i; for (10; i