#include <iostream>
#include <vector>
#include <list>
using namespace std;
class AccountOwner;
class Account;
//**********************************************************************************
class AccountOwner
{
private:
string name;
vector <Account *> accounts;
public:
//Getters & Setters
string getName();
void setName(string aName);
//Constructors
AccountOwner(string name);
//Add Account
void addAccount(Account *acc);
//Display
void display();
//Get Account
//Account * getAccount();
};
//Getters & Setters
//Get Name
string AccountOwner::getName()
{
return this->name;
}
//Set Name
void AccountOwner::setName(string aName)
{
this->name = aName;
}
//Constructors
AccountOwner::AccountOwner(string name)
{
this->setName(name);
//this->accounts = NULL;
}
//Add Account
void AccountOwner::addAccount(Account * acc)
{
this->accounts.push_back(acc);
//this->accounts->addOwner(this);
}
//**********************************************************************************
class Account
{
private:
string id;
int balance;
vector <AccountOwner *> owners;
public:
// Getters & Setters
string getId();
void setId(string anId);
int getBalance();
void setBalance(int aBalance);
//Constructors
Account(string id, int balance);
void addOwner(AccountOwner * own);
//Display
void display();
};
//Getters & Setters
//Get ID
string Account::getId()
{
return this->id;
}
//Set ID
void Account::setId(string anId)
{
this->id = anId;
}
//Get Balance
int Account::getBalance()
{
return this->balance;
}
//Set Balance
void Account::setBalance(int aBalance)
{
this->balance = aBalance;
}
//Constructors
Account::Account(string id, int balance)
{
this->setId(id);
this->setBalance(balance);
//this->owners = NULL;
}
//Add Owner
void Account::addOwner(AccountOwner *own)
{
this->owners.push_back(own);
own->addAccount(this);
}
//**********************************************************************************
//Display
void AccountOwner::display()
{
cout << "Owner Name: " << this->getName() << endl;
cout << "List of Accounts: " << endl;
if (!this->accounts.empty())
{
for (auto acc : this->accounts)
{
cout << "ID: " << acc->getId() << endl;
cout << "Balance: " << acc->getBalance() << endl;
}
}
else
cout << "EMPTY" << endl;
}
//Display
void Account::display()
{
cout << "Account ID: " << this->getId() << endl;
cout << "Balance: " << this->getBalance() << endl;
cout << "List of Owner:" << endl;
if (!this->owners.empty())
{
for (auto own : this->owners)
cout << own->getName() << endl;
}
else cout << "EMPTY" << endl;
}
//**********************************************************************************
int main()
{
Account a("001", 100000);
Account b("002", 200000);
Account c("003", 500000);
AccountOwner owner1("John");
AccountOwner owner2("An");
a.addOwner(&owner1);
b.addOwner(&owner1);
c.addOwner(&owner1);
c.addOwner(&owner2);
a.display();
cout << "\n";
b.display();
cout << "\n";
c.display();
cout << "\n";
owner1.display();
cout << "\n";
owner2.display();
return 0;
}