Assignment 5 ------------ a) compile-time error, I has a pure virtual method and can therefore not be instantiated. b) okay. c) okay. d) okay. e) okay. f) okay. g) compile-time error, variable l has type I*, value e has type E*, but E is not a subclass of I. h) okay. i) compile-time error, variable g has type D*, value c has type C*, but C is not a subclass of D (it is the other way round). j) okay (h receives the null pointer). k) okay (m receives a pointer to the D object stored in d and f). l) okay. m) okay. n) okay. o) compile-time error, same justification as in g. Assignment 4 ------------ template int read(List& list) { int number = 0; while (true) { T elem; cin >> elem; if (!cin || isend(elem)) return number; list.add(elem); number++; } } template class List { Node *head; Node *tail; int len; ... public:´ List(): head(nullptr), tail(nullptr), len(0) { ... } ... void add(T& elem) { Node* node = new Node(elem, nullptr); if (tail == nullptr) head = node; else tail->next = node; tail = node; len++; } } Assignment 3 ------------ template class ArrayQueue: public BoundedQueue { T* array; int length; int number; int head; // position of front element (where to "get") int tail; // position after the tail element (where to "put") public: ArrayQueue(int len) { array = new T[len]; length = len; number = 0; head = 0; tail = 0; } ~ArrayQueue() { delete[] array; } bool isempty() { return number == 0; } bool isfull() { return number == length; } void put(T& x) { array[tail] = x; tail = (tail+1)%length; // tail++; if (tail == length) tail = 0; number++; } T get() { T elem = array[head]; head = (head+1)%length; // ... number--; return elem; } }; Assignment 2 ------------ 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; } } 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; addSale(shop, *sale, names, turnover); } return names; } Assignment 1 ------------ class Work { int cents; int min; public: Work(int c, int m = 0): cents(c), min(m) { } // Work(Work& w): cents(w.cents), min(c.min) { } void add(int m) { min += m; } void printSalary() { int total = cents*min; cout << (total/100) << ","; int c = total%100; if (c < 10) << "0"; cout << c; } bool subtract(int m) { if (min < m) return false; min -= m; return true; } static void reset(Work &w) { w.min = 0; } void reset() { /*this->*/ min = 0; } int compare(Work &w) { int t1 = cents*min; int t2 = w.cents*w.min; if (t1 == t2) return 0; if (t1 < t2) return -1; return 1; } };