{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
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 specifically 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 first 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
Image of page 1

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

View Full Document Right Arrow Icon
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.
Image of page 2
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. (e) None of (a), (b), (c), are correct.
Image of page 3

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

View Full Document Right Arrow Icon
MC 5 (5 pts) Find the errors in the following code. Select all that apply, if any. #include <iostream> using namespace std; int * myFun(const int & a) { int * c = new int(a); int b = *c; return &b; } int main() { int n = 8; cout << *(myFun(n)) << endl; return 0; } (a) type mismatch (b) memory leak (c) invalid return value (d) NULL pointer dereference (e) violation of const MC 6 (5pts) Which of the following functions are typically implemented in an iterator class? Check all that apply, if any.
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern