finalA - 1 CSCE 2014 Final Exam Fall 2009 Student Name:...

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

View Full Document Right Arrow Icon
1 CSCE 2014 – Final Exam Fall 2009 Student Name : Student UAID : Instructions : This is closed book exam. Students are allowed one 8.5x11 page of notes, but no calculators or other electronic devices. The exam has 14 pages of questions worth a total of 140 points, so schedule your time accordingly.
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 ---- Classes ---- Consider the following C++ program. // class declaration class thing { public: ~thing(); thing(); thing(int num); int num(); private: int number; }; // class implementation thing::~thing() { number = 0; } thing::thing() { number = 42; } thing::thing(int num) { number = num; } int thing::num() { return number; } void main() { thing red(73); thing green[15]; thing blue; int num = 0; } (10 points) Which of the following are valid C++ statements that could be compiled and executed in the main function above? (circle valid or invalid). [valid / invalid] thing yellow( red.num() ); [valid / invalid] thing purple(red); [valid / invalid] cout << blue; [valid / invalid] num = blue.num(); [valid / invalid] cout << red.number; [valid / invalid] num = red.number(); [valid / invalid] cout << green[4].num(); [valid / invalid] cin >> green.number[7]; [valid / invalid] num = white.num(); [valid / invalid] thing *white = new thing(green);
Background image of page 2
3 ---- Recursion ---- Consider the following C++ program. void magic(int number) { if (number < 0) { magic(abs(number)); cout << '-'; } else if (number < 10) cout << number; else { cout << number % 10; magic(number/10); } } void main() { magic(-1023); } (4 points) How many calls to function magic will occur when this program is executed? A) 3 B) 5 C) 1023 D) 4 E) None of the above. (4 points) What will this program output when is executed? A) -8976 B) -1023 C) 3201- D) 6798- E) An infinite number of ‘-‘ characters.
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 ---- Linked Lists ---- Consider the following C++ program. class node { public: int data; node * next; }; int main() { node * a; node * b; node * c; c = new node; c->data = 35; b = new node; b->data = c->data % 15; a = new node; a->data = b->data + c->data; cout << a->data << " " << b->data << " " << c->data << endl; return 0; } (4 points) What output would this program generate? (4 points) Each node of a doubly-linked list contains one more pointer than a singly-linked list. This extra pointer is used to: A) Point to itself. B) Point to the first node in the list. C) Point to the last node in the list. D) Point to the previous node in the linked list. E) None of the above.
Background image of page 4
5 Consider the following C++ class definition for a linked list node. // class declaration class node { public: node(); node(int value); node(int value, node *ptr); int data; node *next; }; // class implementation node::node() { data=0; next=NULL; } node::node(int value) { data=value; next=NULL; } node::node(int value, node *ptr) { data=value; next=ptr; } (4  points) Which of the following sequences of C++ statements will generate a linked list containing the values 123, 234, 333, and 468 in this order? A)
Background image of page 5

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

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

Page1 / 16

finalA - 1 CSCE 2014 Final Exam Fall 2009 Student Name:...

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

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