ex1solnsp09

ex1solnsp09 - University of Illinois at Urbana-Champaign...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: University of Illinois at Urbana-Champaign Department of Computer Science First Examination CS 225 Data Structures and Software Principles Spring 2009 7p-9p, Tuesday, Feb 24 Name: NetID: Lab Section (Day/Time): This is a closed book and closed notes exam. No electronic aids are allowed, either. You should have 5 problems total on 18 pages. The last two sheets are scratch paper; you may detach them while taking the exam, but must turn them in with the exam when you leave. Unless otherwise stated in a problem, assume the best possible design of a particular imple-mentation is being used. Unless the problem specically says otherwise, (1) assume the code compiles, and thus any compiler error is an exam typo (though hopefully there are not any typos), and (2) assume you are NOT allowed to write any helper methods to help solve the problem, nor are you allowed to use additional arrays, lists, or other collection data structures unless we have said you can. We will be grading your code by rst reading your comments to see if your plan is good, and then reading the code to make sure it does exactly what the comments promise. In general, complete and accurate comments will be worth approximately 30% of the points on any coding problem. Please put your name at the top of each page. Problem Points Score Grader 1 20 2 20 3 17 4 10 5 33 Total 100 1. [Pointers, Parameters, and Miscellany 20 points]. MC1 (2.5pts) Consider the following statements: int *p; int i; int k; i = 37; k = i; p = &i; After these statements, which of the following will change the value of i to 75? (a) k = 75; (b) *k = 75; (c) p = 75; (d) *p = 75; (e) Two or more of the answers will change i to 75. MC2 (2.5pts) Consider the following statements: int i = 1; int k = 2; int * p1; int * p2; p1 = &i; p2 = &k; p1 = p2; *p1 = 3; *p2 = 4; cout << i << endl; Which of the following is printed by the output statement (assume cout works)? (a) 1 (b) 2 (c) 3 (d) 4 (e) None of these. The code does not compile. MC3 (2.5pts) Consider the following C++ statements: #include <iostream> using namespace std; void increment1(int x) { x = x + 1; } void increment2(int * x) { *(x) = *x + 1; } void increment3(int & x) { x = x + 1; } int main() { int x = 1; increment1(x); increment2(&x); increment3(x); cout << x << endl; return 0; } What is the printed out when this code is compiled and run? (a) 1 (b) 2 (c) 3 (d) 4 (e) This code does not compile. MC4 (2.5pts) Which of the following is a correct way to declare and initialize a dynamic array of length max , each element of which is a List whose parameterized type is a sphere ? (a) List<sphere> * myList = new List<sphere>[max]; (b) sphere ** myList = new sphere *[max]; (c) List<sphere> myList[max]; (d) More than one of (a), (b), (c), are correct....
View Full Document

Page1 / 18

ex1solnsp09 - University of Illinois at Urbana-Champaign...

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