{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Practice Exam1-sol

# Practice Exam1-sol - Vanderbilt University Department of...

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

Vanderbilt University Department of Electrical Engineering and Computer Science First Examination CS201 Data Structure and Program Design Spring 2007 Name: VUnet ID: This is a closed book and closed notes exam. No electronic aids are allowed, either. You should have 6 sheets total (the cover sheet, plus numbered pages 1-11). The last sheet is scratch paper; you may detach it while taking the exam, but must turn it in with the exam when you leave. Unless otherwise stated in a problem, assume the best possible design of a particular implementation 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. Problem Points Score Grader 1 10 2 16 3 24 4 10 Total 60

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

View Full Document
CS201 First Exam – Spring 2007 Name: _____________ 1. [Pass by Reference, Reference Variable, and Pointers -- 8 point] Consider the following program. #include <iostream> int Addition(int &a, int &b) { a = a + b; return a; } int main() { int a = 22; int b = 33; int* c = &a; int& d = b; int* e; int i; c = &b; cout << "*c=" << *c << ", d=" << d << endl; d = a; cout << "*c=" << *c << ", d=" << d << endl; cout << "d+*c " << Addition(d, *c) << endl; e = new int[4]; e[0] = a; e[1] = b; e[2] = *c; e[3] = d; for (i = 0; i < 4; i ++) cout << “e[” << i << “]=” << e[i] << “ “ << endl; delete e; } Show the output result of this program. *c=33, d=33 // c is redirected to point to a *c=22, d=22 // As a reference variable, d cannot be reassigned to refer to //another variable. Therefore, b is reassigned the value of a d+*c 44 e[0]=22 // the value of a has in factnever been changed e[1]=44 // value of b and *c should be the same e[2]=44 // the values of b and *c are synchronized with d e[3]=44 // value of d has been changed through call to Addition 2
CS201 First Exam – Spring 2007 Name: _____________ 2. [Array and Operator Overloading – 16 points] Consider the following code for class Polynomial , which would appear in polynomial.h .

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}