This preview shows pages 1–4. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Page 1 of 9 Question 1 (7 + 8 = 15 marks) This question assumes the class outlined below. Note that only those aspects of the class that are relevant to the question have been shown. Other aspects have been omitted. A full class definition would include a constructor, a destructor, and so on. class X { private: class LNode { int data; LNode *next, *prior; LNode (int data, LNode *next, LNode *prior) { this > data = data; this > next = next; this > prior = prior; } }; LNode *head, *tail; int count; public: // Duplicates the last value in the list. If a list contains {1, 2, 2, 6, 8}, this method // will leave it containing {1, 2, 2, 6, 8, 8}. Throws a range_error exception if // the list is empty. void duplicateLastNode (); // Deletes all list nodes containing a value greater than limit. // If there are no such nodes the method has no effect. void deleteAllGreaterThan (int limit); }; The class involves a doubly linked list. This list is sorted in ascending order and may contain duplicate values. In the space provided in your answer booklet, implement methods duplicateLastNode and deleteAllGreaterThan. Page 2 of 9 Question 2 (7 marks) In the space provided in your answer booklet, write a recursive function that reverses the order of elements start through end of an array (as illustrated below). start end BEFORE 0 3 5 4 2 1 start end AFTER 0 2 4 5 3 1 A function header has been supplied: // Reverses the order of array elements start through end void reverseElements (int array, int start, int end); Make you own decision as to how your function should behave if start is greater than end. Any reasonable choice is acceptable. Hint: there is one very reasonable choice that will make your life much easier. Page 3 of 9 Question 3 (7 + 8 = 15 marks) This question assumes the class outlined below. Note that only those aspects of the class that are relevant to the question have been shown. Other aspects have been omitted. class StudentDB { private: class TNode { public: int number; // student number double GPA; TNode *left, *right; }; TNode *head; int count; // total number of students public: // returns the GPA for student for the specified student. // throws an invalid_argument exception if the student does not exist. double getGPA (int studentNumber) const; // returns the average of all student GPAs. // throws a range_error exception if the tree is empty. double averageGPA (double GPA) const; }; The class involves a tree. This tree is sorted by student number in the usual manner (i.e. the lowest student number is at the very left of the tree). In the space provided in your answer booklet, implement methods getGPA and averageGPA....
View
Full
Document
This note was uploaded on 02/24/2010 for the course SYSC 2002 taught by Professor Unknown during the Fall '07 term at Carleton.
 Fall '07
 Unknown

Click to edit the document details