








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









class Account { public: ... void deductFee(double fee); ... }; class Checking : public Account { public: ... void deductFee(); ... }; CPSC 223 -‐-‐ Fall 2010 4
CPSC 223 -‐-‐ Fall 2010 7
CPSC 223 -‐-‐ Fall 2010 8 Account Checking Account::getBalance() balance = 500. Checking::getMonthlyFees() Checking::getBalance() monthyFees = 10. Checking object Account object (part of the checking account object)
What is printed?
CPSC 223 -‐-‐ Fall 2010 15 Checking c(500, 5); cout << c.getBalance(); Account a = c; cout << a.getBalance(); Account* aptr = &c; cout << aptr->getBalance(); // base class class Account { public: Account(double bal = 0); virtual double getBalance(); private: double balance; }; // derived class class Checking : public Account { public: Checking(double b = 0, double f = 5); double getMonthlyFees(); double getBalance(); private: double monthlyFees; }; // 495 // 500 // 495 What is printed?
Using a linked list void List::retrieve(int index, ListItemType& item) { ... check if valid index ... Node* curr = head; for(int i = 1; i < index; i++) curr = curr->next; item = curr->item; } Using an array void List::retrieve(int index, ListItemType& item) { ... check if valid index ... item = items[index-1]; } Which do you think is more efficient? CPSC 223, 2009 19 We compare algorithms based on:
void List::retrieve(int index, ListItemType& item) { ... check if valid index ... Node* curr = head; for(int i = 1; i < index; i++) curr = curr->next; item = curr->item; }
void List::retrieve(int index, ListItemType& item) { ... check if valid index ... item = items[index-1]; }