fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <list>
  4. using namespace std;
  5.  
  6.  
  7. class AccountOwner;
  8. class Account;
  9.  
  10. //**********************************************************************************
  11. class AccountOwner
  12. {
  13. private:
  14. string name;
  15. vector <Account *> accounts;
  16. public:
  17. //Getters & Setters
  18. string getName();
  19. void setName(string aName);
  20.  
  21. //Constructors
  22. AccountOwner(string name);
  23.  
  24. //Add Account
  25. void addAccount(Account *acc);
  26.  
  27. //Display
  28. void display();
  29.  
  30. //Get Account
  31. //Account * getAccount();
  32.  
  33. };
  34.  
  35. //Getters & Setters
  36. //Get Name
  37. string AccountOwner::getName()
  38. {
  39. return this->name;
  40. }
  41.  
  42. //Set Name
  43. void AccountOwner::setName(string aName)
  44. {
  45. this->name = aName;
  46. }
  47.  
  48. //Constructors
  49. AccountOwner::AccountOwner(string name)
  50. {
  51. this->setName(name);
  52. //this->accounts = NULL;
  53. }
  54.  
  55. //Add Account
  56. void AccountOwner::addAccount(Account * acc)
  57. {
  58. this->accounts.push_back(acc);
  59. //this->accounts->addOwner(this);
  60. }
  61.  
  62.  
  63. //**********************************************************************************
  64. class Account
  65. {
  66. private:
  67. string id;
  68. int balance;
  69. vector <AccountOwner *> owners;
  70. public:
  71. // Getters & Setters
  72. string getId();
  73. void setId(string anId);
  74.  
  75. int getBalance();
  76. void setBalance(int aBalance);
  77.  
  78. //Constructors
  79. Account(string id, int balance);
  80.  
  81. void addOwner(AccountOwner * own);
  82.  
  83. //Display
  84. void display();
  85.  
  86. };
  87.  
  88. //Getters & Setters
  89. //Get ID
  90. string Account::getId()
  91. {
  92. return this->id;
  93. }
  94.  
  95. //Set ID
  96. void Account::setId(string anId)
  97. {
  98. this->id = anId;
  99. }
  100.  
  101. //Get Balance
  102. int Account::getBalance()
  103. {
  104. return this->balance;
  105. }
  106.  
  107. //Set Balance
  108. void Account::setBalance(int aBalance)
  109. {
  110. this->balance = aBalance;
  111. }
  112.  
  113. //Constructors
  114. Account::Account(string id, int balance)
  115. {
  116. this->setId(id);
  117. this->setBalance(balance);
  118. //this->owners = NULL;
  119. }
  120.  
  121. //Add Owner
  122. void Account::addOwner(AccountOwner *own)
  123. {
  124. this->owners.push_back(own);
  125. own->addAccount(this);
  126. }
  127.  
  128.  
  129. //**********************************************************************************
  130.  
  131. //Display
  132. void AccountOwner::display()
  133. {
  134. cout << "Owner Name: " << this->getName() << endl;
  135. cout << "List of Accounts: " << endl;
  136. if (!this->accounts.empty())
  137. {
  138. for (auto acc : this->accounts)
  139. {
  140. cout << "ID: " << acc->getId() << endl;
  141. cout << "Balance: " << acc->getBalance() << endl;
  142. }
  143. }
  144. else
  145. cout << "EMPTY" << endl;
  146. }
  147.  
  148. //Display
  149. void Account::display()
  150. {
  151. cout << "Account ID: " << this->getId() << endl;
  152. cout << "Balance: " << this->getBalance() << endl;
  153. cout << "List of Owner:" << endl;
  154. if (!this->owners.empty())
  155. {
  156. for (auto own : this->owners)
  157. cout << own->getName() << endl;
  158. }
  159. else cout << "EMPTY" << endl;
  160. }
  161.  
  162.  
  163.  
  164. //**********************************************************************************
  165. int main()
  166. {
  167. Account a("001", 100000);
  168. Account b("002", 200000);
  169. Account c("003", 500000);
  170. AccountOwner owner1("John");
  171. AccountOwner owner2("An");
  172.  
  173. a.addOwner(&owner1);
  174. b.addOwner(&owner1);
  175. c.addOwner(&owner1);
  176. c.addOwner(&owner2);
  177.  
  178. a.display();
  179. cout << "\n";
  180. b.display();
  181. cout << "\n";
  182. c.display();
  183. cout << "\n";
  184. owner1.display();
  185. cout << "\n";
  186. owner2.display();
  187.  
  188. return 0;
  189. }
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
Account ID: 001
Balance: 100000
List of Owner:
John

Account ID: 002
Balance: 200000
List of Owner:
John

Account ID: 003
Balance: 500000
List of Owner:
John
An

Owner Name: John
List of Accounts: 
ID: 001
Balance: 100000
ID: 002
Balance: 200000
ID: 003
Balance: 500000

Owner Name: An
List of Accounts: 
ID: 003
Balance: 500000