finalpractice

finalpractice - University of California Los Angeles...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
University of California, Los Angeles Computer Science 31, Section 3B Fall 2007 Quarter Final Exam Practice Problems Question 1 Let us define a class named BankAccount as follows: class BankAccount { public: // constructor BankAccount(int acctNum); // accessors int accountNum() const; // implemented double balance() const; // implemented // mutators bool deposit(double amount); bool withdraw(double amount); private: int m_accountNum; // account number double m_balance; // balance }; Assume the accessors accountNum() and balance() are already implemented. (a) Write the full definition of the constructor of BankAccount , using the initialization list. The new customer is promised to get $25.00 of bonus balance when he/she opens an account, and gets a welcome message that goes “ Account <account number> has been created. ” (with <account number> replaced by the actual account number). (b) Write the full definition of deposit . A deposit is valid if the amount is not negative. An invalid deposit should result in the return value of false ; otherwise, it returns true . (c) Write the full definition of withdraw . A withdraw is valid if the amount is not negative and if the resulting balance is nonnegative. An invalid withdraw should result in the return value of false ; otherwise, it returns true . 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Now let us define the class Bank as follows. class Bank { public: Bank(string name); // implemented bool accountExists(int acctNum); // implemented, true iff there’s an account // already created with the account number acctNum void addAccount(int acctNum); void destroyAccount(int acctNum); BankAccount* findAccount(int acctNum); // implemented, finds and returns // the pointer to the account // returns NULL if no such account private: BankAccount* m_accounts[MAXACCT];
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/17/2009 for the course CSE CS31 taught by Professor Smallberg during the Spring '09 term at UCLA.

Page1 / 6

finalpractice - University of California Los Angeles...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online