Question 5: a) compilation error, I has a pure virtual method, cannot be instantiated b) okay. c) okay. d) okay. e) okay. f) okay. g) compilation error, type E of e is not a subclass of type I of variable l h) okay. i) compilation error, type C of c is not a subclass of type D of variable g (but the other way round) j) okay. h becomes NULL. k) okay. h becomes d (a D* pointer) l) okay. m) okay. n) okay. o) compilation error, same reason as in g). --------------------------------------------------- Question 4: template int read(List &list) { int n = 0; while (true) { T x; cin >> x; if (!cin) return -1; if (isend(x)) return n; list.push_back(x); n++; } } template class List { Node* head; Node* tail; int len; List(): head(NULL), tail(NULL), len(0) { ... } void push_back(T& x) { Node *node = new Node(x, NULL); if (tail == NULL) head = node; else tail->next = node; tail = node; len++; } } ----- Question 3: template class ArrayQueue: public BoundedQueue { T* a; int l; int n; int h; int t; public: ArrayQueue(int s): a(new T[s]), l(s), n(0), h(0), t(0) { } ~ArrayQueue() { delete[] a; } bool isempty() { return n == 0; } bool isfull() { return n == l; } void put(T& x) { a[t] = x; // t = t+1; if (t == l) t = 0; t = (t+1)%l; n++; } T get() { T x = a[h]; h = (h+1)%l; n--: return x; } } ------------------------------------------------------------- Question 2: set getSales(Shop& shop, set& days, int& turnover) { set names; turnover = 0; list sales = shop.sales(); for (list::iterator it = sales.begin(); it != sales.end; it++) { Sale* sale = *it; int day = sale->getDay(); if (days.count(day) == 0) continue; addSales(shop, *sale, names, turnover); } return names; } void addSales(Shop& shop, Sale& sale, set& names, int& turnover) { map articles = shop.articles(); list ids = sale.articleIds(); for (list::iterator it = ids.begin(); it != ids.end(); it++) { string id = *it; Article* article = articles.find(id); string name = article->getName(); int price = article->getPrice(); names.insert(name); turnover += price; } } --------------- Question 1: class Work { int m; // minutes int r; // cent/minute public: Work(int m0, int r0): m(m0), r(r0) { } Work(Work& w): m(w.m), r(w.r) { } // automatically generated void printSalary() { int s = m*r; cout << (s/100) << "," << (s%100) << endl; } void add(int m) { this->m += m; } bool subtract(int m) { if (this->m < m) return false; this->m -= m; return true; } static void reset(Work& w) { w.m = 0; } void reset() { m = 0; } int compare(Work& w) { int s1 = m*r; int s2 = w.m*w.r; if (s1 == s2) return 0; if (s1 > s2) return 1; return -1; } };