#include <iostream.h> class BankAccount { public : void deposit(float amount); void withdrawl(float amount); float getBalance() const; BankAccount(float amount = 0.0); private: float balance; }; BankAccount::BankAccount(float amount) { cout << "New Bank Account" << endl; balance = amount; } void BankAccount::deposit(float amount) { balance = balance + amount; } void BankAccount::withdrawl(float amount) { balance = balance - amount; } float BankAccount::getBalance() const { return balance; }
class Customer { public: Customer(char* Name, float Amount); float CheckingBalance(); private: char* LastName; BankAccount Checking; }; Customer::Customer(char* Name, float Amount) { cout << "New Customer" << endl; LastName = Name; BankAccount LocalCopy(Amount); Checking = LocalCopy; } float Customer::CheckingBalance() { return Checking.getBalance(); } void main() { Customer Test("Whitney", 1000 ); cout << Test.CheckingBalance(); }Output New Bank Account New Customer New Bank Account 1000
class Customer { public: Customer(char* Name, float Amount); float CheckingBalance(); private: char* LastName; BankAccount* Checking; }; Customer::Customer(char* Name, float Amount) { cout << "New Customer" << endl; LastName = Name; Checking = new BankAccount(Amount); } float Customer::CheckingBalance() { return Checking->getBalance(); } void main() { Customer Test("Whitney", 1000 ); cout << Test.CheckingBalance(); }Output New Customer New Bank Account 1000
class Customer { public: Customer(char* Name, float Amount); float CheckingBalance(); private: char* LastName; BankAccount Checking; }; Customer::Customer(char* Name, float Amount) : Checking(Amount) { cout << "New Customer" << endl; LastName = Name; } float Customer::CheckingBalance() { return Checking.getBalance(); } void main(){ Customer Test("Whitney", 1000 ); cout << Test.CheckingBalance(); }Output New Bank Account New Customer 1000
class Customer { public: Customer(char* Name, BankAccount& CustomersAccount); float CheckingBalance(); private: char* LastName; BankAccount* Checking; }; Customer::Customer(char* Name, BankAccount& CustomersAccount) { cout << "New Customer" << endl; LastName = Name; Checking = &CustomersAccount; } float Customer::CheckingBalance() { return Checking->getBalance(); } void main() { BankAccount TestsAccount( 1000 ); Customer Test( "Whitney", TestsAccount ); cout << Test.CheckingBalance(); }Output New Bank Account New Customer 1000
#include <iostream.h> class Customer; class BankAccount { public : void deposit(float amount); void withdrawl(float amount); float getBalance() const; void setOwner( Customer& Owner); char* name(); BankAccount(float amount = 0.0); private: float balance; Customer* AccountOwner; }; class Customer { public: Customer(char* Name, BankAccount& CustomersAccount); float CheckingBalance(); char* name(); private: char* LastName; BankAccount* Checking; }; void BankAccount::setOwner( Customer& Owner) { AccountOwner = &Owner; } char* BankAccount::name() { return AccountOwner->name(); } char* Customer::name() { return LastName; } Customer::Customer(char* Name, BankAccount& CustomersAccount) { cout << "New Customer" << endl; LastName = Name; Checking = &CustomersAccount; Checking->setOwner( *this ); } float Customer::CheckingBalance() { return Checking->getBalance(); } void main() { BankAccount TestsAccount( 1000 ); Customer Test( "Whitney", TestsAccount ); cout << Test.CheckingBalance() << "\t" << TestsAccount.name() << endl; }Output New Bank Account New Customer 1000 Whitney