finalpracticesol

# finalpracticesol - University of California Los Angeles...

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

University of California, Los Angeles Computer Science 31, Section 3B Fall 2007 Quarter Final Exam Practice Problems Question 1 (a) BankAccount::BankAccount(int acctNum) :m_accountNum(acctNum), m_balance(25.00) { cout << "Account " << acctNum << " has been created." << endl; } (b) bool BankAccount::deposit(int amount) { if(amount >= 0) { m_balance += amount; return true; } return false; } (c) bool BankAccount::withdraw(int amount) { { m_balance -= amount; return true; } return false; } (d) void Bank::addAccount(int acctNum) { if(m_nAccounts < MAXACCT) { for(int i=0 ; i < m_nAccounts ; i++) if(m_accounts[i]->accountNum() == acctNum) { cout << "Account " << acctNum << " already exists." << endl; return; } m_accounts[m_nAccounts] = new BankAccount(acctNum); m_nAccounts++; } } 1

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

View Full Document
(e) void Bank::destroyAccount(int acctNum) { for(int i=0 ; i < m_nAccounts ; i++) if(m_accounts[i]->accountNum() == acctNum) { delete m_accounts[i]; m_accounts[i] = m_accounts[m_nAccounts-1];
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

finalpracticesol - University of California Los Angeles...

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

View Full Document
Ask a homework question - tutors are online