Task 3 Lab 10.cpp
Task 3 Lab 10.cpp
#include <vector>
using namespace std;
class Bank;
class Account;
class Customer {
int id;
string name;
friend class Account;
public:
Customer( const int id = 0, const string name = "" ) : id(id), name(name) {}
void display()
{
cout << "\t\t\t\tName: " << this->name << ", ID: " << this->id << endl;
}
class Account {
int account_number;
static int account_number_giver;
double balance;
Customer owner;
void check_balance() { cout << "\t\t\tBalance: " << this->balance << endl; }
void display_details()
{
cout << "\t\t\tAccount number: " << this->account_number << '\n';
this->check_balance();
cout << "\t\t\tOwner details:\n";
this->owner.display();
}
friend void operator+ ( Account &account_1, Account &account_2 );
};
class Bank {
vector<Account> accounts;
public:
void open_account( const Customer &customer )
{
double initial_deposit_amount;
cout << "\tEnter the initial deposit amount before opening account of the
customer: ";
cin >> initial_deposit_amount;
Account temp( initial_deposit_amount );
temp.owner.set_name( customer.get_name() );
temp.owner.set_id( customer.get_id() );
this->accounts.push_back( temp );
}
void display_accounts()
{
cout << "\n\tDisplaying details of accounts:\n";
for ( int i = 0; i < this->accounts.size(); i++ )
{
cout << "\t\tFor account no." << i+1 << ":\n";
this->accounts[i].display_details();
}
}
};
int main ()
{
cout << "Creating and giving values to customer object(s):\n";
Customer customer_1(1, "Mahira Khan"), customer_2(2, "Central Cee"),
customer_3(3, "Mohammad Ali");
cout << "\nUsing + operator to add funds from one account to another account:\
n";
account_1 + account_2; // transferring 20000 into account_2
account_2 + account_3; // depositing 4000 into account_3
account_3 + account_1; // depositing 5000 into account_1