/* University College London course in C++ 3C59 | all rights reserved 1999 | | Example: BankAccount in C++ | | BankAccount type as used in examples in the lectures | | This file shows you how to write the declaration of a | simple class, which includes: | | - the member variables of the class | - the methods of the class | | This version also has all the method definitions inline | | | Author: P.Clarke */ #ifndef _bankacc_inline_h #define _bankacc_inline_h 1 #include #include #include class BankAccount { private: std::string holderName ; float currentBalance ; float overdraftLimit ; bool jointAccount ; int yearsHeld ; public: //........................... // Initialise a new account void initialise( std::string name, float initial, float odlim ) { // Set the holders name holderName = name ; // Set balance and overdraft currentBalance = initial ; overdraftLimit = odlim ; // Default to not a joint account jointAccount = false ; // Its just been opened, so.. yearsHeld = 0 ; } //........................... // Returns the total funds available to be used float availableFunds( ) { return( currentBalance + overdraftLimit ) ; } //........................... // To make a deposit in the account void deposit( float amount ) { // We ought to check that it is a positive deposit if( amount < 0.0 ) return ; // Go ahead and deposit - we always take money currentBalance += amount ; return ; } //........................... // To make a withdrawl from the account if possible bool withdrawl( float amount ) { // Check whether the withdrawl can be made if( amount > availableFunds( ) ) { // There are insufficient funds in the account return false ; } else { // Its ok to make the withdrawl currentBalance -= amount ; return true ; } } //........................... // To print out the account name and balance void printStatus( ) { std::cout << "Account name: " << holderName << std::endl << " balance: " << currentBalance << std::endl ; return ; } } ; #endif