ECE244F_2008_Exam_Solutions

ECE244F_2008_Exam_Solutions - University of Toronto Faculty...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Page 1 of 17 University of Toronto Faculty of Applied Science and Engineering ECE 244F PROGRAMMING FUNDAMENTALS Fall 2008 Final Examination Examiner: C. Gibson, A. Goel, and M. Stumm Duration: Two and a Half Hours No aids allowed. No books. No notes. No calculators. No computers. No communicating devices. Do not remove any sheets from this test book. Answer all questions in the space provided. No additional sheets are permitted. There are 15 questions. The weight of each question is the same. Work independently. Write your name and student number in the space below. Do the same on the top of each sheet of this exam book. Last Name: ___________________ First Name: _________________________ Student Number: ______________________ Q1. __________ Q9. __________ Q2. __________ Q10. _________ Q3. __________ Q11. _________ Q4. __________ Q12. _________ Q5. __________ Q13. _________ Q6. __________ Q14. _________ Q7. __________ Q15. _________ Q8. __________ Total
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Name: _______________________________ Student Number: ___________________ Page 2 of 17 1. Warmup a. Consider the following code: class Data { private: int a; public: int get() { return a; } }; int main() { Data data; return 0; } Modify the code above so that data is declared as a global variable. b. Identify what is wrong with the following code and fix the error(s): class C { public: int x; }; void main(void) { int x = 78; C c; c->x = x+22; cout << c->x << endl ; } c. Identify what is wrong with the following code and fix the error(s): const int MAX 10 int list[MAX]; void main(void) { int sum = 0; for (int i = 0; i < MAX+1; i++) { list[i] = i; } for (int i = 0; i < MAX+1; i++) { sum += list[i]; } cout << sum << endl ; } Either: “ C *c = new C ;” Either: “C *c = new C ;” Or: “ c.x ” in both places Off by 1 error. Easiest way to fix this is to get rid of the “ +1 ” in both places × ×
Background image of page 2
Student Number: ___________________ Page 3 of 17 2. GDB and Unix a. Briefly describe (one sentence) what the “Step” command does in either gdb or DDD when debugging a running program: b. Assume your current working directory is your home directory. What Unix command(s) would you need to execute to create a new directory “Lab4” under the existing “ece244” directory. cd ece244 mkdir Lab4 or mkdir ece244/Lab4 c. What command do you need to execute in order to make the contents of this directory not readable by anyone else but yourself? chmod go-r d. You are testing a program that reads from the standard input until end of file is reached. When you have completed providing input, do you enter Control-C or Control-D? Control-D e. What command do you issue in order to remove a file? rm
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 17

ECE244F_2008_Exam_Solutions - University of Toronto Faculty...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online