#include <iostream>
#include <string>
#include <vector>
using namespace std;
class AccountOwner;
class Account {
private:
string id;
double balance;
vector <AccountOwner*> owner;
public:
string getId(){
return this->id;
}
void setId(string anId) {
this->id = anId;
}
double getBalance() {
return this->balance;
}
void setBalance(double aBalance) {
this->balance = aBalance;
}
Account(string anId, double aBalance) {
this->setId(anId);
this->setBalance(aBalance);
this->owner.clear();
}
void attachOwner(AccountOwner *anOwner) {
this->owner.push_back(anOwner);
}
void print() {
cout << "Id: " << this->getId() << endl;
cout << "Balance: " << this->getBalance() << endl;
}
void display();
};
class AccountOwner {
private:
string name;
vector <Account*> account;
public:
string getName() {
return this->name;
}
void setName(string aName) {
this->name = aName;
}
AccountOwner(string aName) {
this->setName(aName);
this->account.clear();
}
void attachAccount(Account *anAccount) {
this->account.push_back(anAccount);
}
void print() {
cout << "Name: " << this->getName() << endl;
}
void display() {
print();
cout << "Linked with Account: " << endl;
int count = 0;
for (auto temp : this->account) {
++count;
cout << "Account" << count << ": " << endl;
temp->print();
}
if (count == 0)
cout << "Empty!";
cout << endl;
}
};
void Account:: display() {
print();
cout << "Linked with AccountOwner: " << endl;
int count = 0;
for (auto temp : this->owner) {
++count;
cout << "AccountOwner" << count << ": " << endl;
temp->print();
}
if (count == 0)
cout << "Empty!";
cout << endl;
}
class Bank {
private:
vector <Account*> account;
vector <AccountOwner*> owner;
public:
Account* getAccount(int i) {
return this->account[i];
}
AccountOwner* getOwner(int i) {
return this->owner[i];
}
Bank() {
this->account.clear();
this->owner.clear();
}
void createAccount(string anId, double aBalance) {
Account *anAccount = new Account(anId, aBalance);
this->account.push_back(anAccount);
}
void createOwner(string aName) {
AccountOwner *anOwner = new AccountOwner(aName);
this->owner.push_back(anOwner);
}
void link(Account *anAccount, AccountOwner *anOwner) {
anOwner->attachAccount(anAccount);
anAccount->attachOwner(anOwner);
}
void displayAccount() {
cout << "List of Account: " << endl <<endl;
int count = 0;
for (auto temp : this->account) {
++count;
cout << "Account" << count << ": " << endl;
temp->display();
}
if (count == 0)
cout << "Empty!";
cout << endl;
}
void displayOwner() {
cout << "List of AccountOwner: " << endl << endl;
int count = 0;
for (auto temp : this->owner) {
++count;
cout << "AccountOwner" << count << ": " << endl;
temp->display();
}
if (count == 0)
cout << "Empty!";
cout << endl;
}
};
int main() {
Bank bank;
bank.createAccount("001", 1000);
bank.createAccount("002", 500);
bank.createAccount("003", 50);
bank.createOwner("Tran Thanh Dat");
bank.createOwner("Dau Quang Anh");
bank.link(bank.getAccount(0), bank.getOwner(0));
bank.link(bank.getAccount(1), bank.getOwner(0));
bank.link(bank.getAccount(2), bank.getOwner(0));
bank.link(bank.getAccount(2), bank.getOwner(1));
bank.displayAccount();
bank.displayOwner();
return 0;
}