---------------------------------------------------------------------- QUESTION 1 (10 marks): What does the following program output? #include using namespace std; class A { public: A(int i) : i(i) { cout << "Constructor: " << i << endl; } A(const A &o) : i(o.i) { cout << "Copy constructor: " << i << endl; } A& operator=(const A &o) { cout << "Assignment operator: " << o.i << "->" << i << endl; i = o.i; return *this; } ~A() { cout << "Destructor: " << i << endl; } private: int i; }; A a(10); A test(const A &a, A b, A *c) { return *c; } int main() { A b = a; a = b; test(1, b, &b); } ---------------------------------------------------------------------- QUESTION 2 (10 marks): (a) What operations are required from a Front Insertion Sequence? Give an example of a Front Insertion Sequence from the C++ STL. (b) What type of iterators do Front Insertion Sequences support? (c) What are the operations that can be performed on a Bidirectional Iterator? ---------------------------------------------------------------------- QUESTION 3 (15 marks): You are required to write a program in C++ to perform the following: The program is to keep track of student's marks for a course. The program shall allow the user to enter new students, as well as new assignments. The user must also be able to enter a mark for a specific student and assignment. The user shall also be able to retrieve the marks of a particular students, or all the students that recieved a particular mark. The program must also print out a list of final marks for all the students. The final mark is simply the sum of all the assignment marks. Which containers from the STL would you use? Explain what you would use them for and why you choose those particular containers. ---------------------------------------------------------------------- QUESTION 4 (5 marks): Modify the following linked list of integers class to be a linked list template. struct Node { int value; Node *next; }; class List { public: List(); List(const List&); List& operator=(const List&); ~List(); int length() const; void insert_at_front(int value); bool insert_after_current(int value); void advance_current(); int get_current_value() const; private: Node *head; Node *current; }; ---------------------------------------------------------------------- QUESTION 5 (10 marks): The following code is meant to read integers from cin and output the integers it read in sorted order with duplicates removed. Why doesn't it work? How would you fix it? What containers/algorithms could be used to make the program simpler? #include #include #include #include #include int main() { std::vector v; std::copy(std::istream_iterator(cin), std::istream_iterator(), std::back_inserter(v)); std::unique(v.begin(), v.end()); std::sort(v.begin(), v.end()); std::copy(v.begin(), v.end(), std::ostream_iterator(cout, "\n")); } ---------------------------------------------------------------------- QUESTION 6 (10 marks): Consider a program with the following specification: The program reads from standard input. The first line contains a single integer. The remaining lines are output from the grep command, that is, they have the form: : The program should output each "line of text" (ie. the text after the ':' character) and add it to the file called ".log". At most n lines should be output, where n is the integer read from the first line. For example, the input 3 test.cc: A test program main.cc: The main program test.cc: Revised the test program sample.cc: Some sample code causes the lines: A test program Revised the test program to be added to the file test.cc.log, and the line The main program to be added to the file main.cc.log. Implement this program in C++ or Bourne/bash shell. If you have source code in more than one file, clearly indicate the filename above its contents in your answer. ----------------------------------------------------------------------