fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7.  
  8.  
  9.  
  10. class AccountOwner;
  11.  
  12. class Account {
  13. private:
  14. string id;
  15. double balance;
  16. vector <AccountOwner*> owner;
  17. public:
  18. string getId(){
  19. return this->id;
  20. }
  21. void setId(string anId) {
  22. this->id = anId;
  23. }
  24.  
  25. double getBalance() {
  26. return this->balance;
  27. }
  28. void setBalance(double aBalance) {
  29. this->balance = aBalance;
  30. }
  31.  
  32. Account(string anId, double aBalance) {
  33. this->setId(anId);
  34. this->setBalance(aBalance);
  35. this->owner.clear();
  36. }
  37.  
  38. void attachOwner(AccountOwner *anOwner) {
  39. this->owner.push_back(anOwner);
  40. }
  41.  
  42. void print() {
  43. cout << "Id: " << this->getId() << endl;
  44. cout << "Balance: " << this->getBalance() << endl;
  45. }
  46.  
  47. void display();
  48. };
  49.  
  50. class AccountOwner {
  51. private:
  52. string name;
  53. vector <Account*> account;
  54. public:
  55. string getName() {
  56. return this->name;
  57. }
  58. void setName(string aName) {
  59. this->name = aName;
  60. }
  61.  
  62. AccountOwner(string aName) {
  63. this->setName(aName);
  64. this->account.clear();
  65. }
  66.  
  67. void attachAccount(Account *anAccount) {
  68. this->account.push_back(anAccount);
  69. }
  70.  
  71. void print() {
  72. cout << "Name: " << this->getName() << endl;
  73. }
  74.  
  75. void display() {
  76. print();
  77.  
  78. cout << "Linked with Account: " << endl;
  79. int count = 0;
  80. for (auto temp : this->account) {
  81. ++count;
  82. cout << "Account" << count << ": " << endl;
  83. temp->print();
  84. }
  85. if (count == 0)
  86. cout << "Empty!";
  87.  
  88. cout << endl;
  89. }
  90. };
  91.  
  92. void Account:: display() {
  93. print();
  94.  
  95. cout << "Linked with AccountOwner: " << endl;
  96. int count = 0;
  97. for (auto temp : this->owner) {
  98. ++count;
  99. cout << "AccountOwner" << count << ": " << endl;
  100. temp->print();
  101. }
  102. if (count == 0)
  103. cout << "Empty!";
  104.  
  105. cout << endl;
  106. }
  107.  
  108. class Bank {
  109. private:
  110. vector <Account*> account;
  111. vector <AccountOwner*> owner;
  112. public:
  113. Account* getAccount(int i) {
  114. return this->account[i];
  115. }
  116.  
  117. AccountOwner* getOwner(int i) {
  118. return this->owner[i];
  119. }
  120.  
  121. Bank() {
  122. this->account.clear();
  123. this->owner.clear();
  124. }
  125.  
  126. void createAccount(string anId, double aBalance) {
  127. Account *anAccount = new Account(anId, aBalance);
  128. this->account.push_back(anAccount);
  129. }
  130.  
  131. void createOwner(string aName) {
  132. AccountOwner *anOwner = new AccountOwner(aName);
  133. this->owner.push_back(anOwner);
  134. }
  135.  
  136. void link(Account *anAccount, AccountOwner *anOwner) {
  137. anOwner->attachAccount(anAccount);
  138. anAccount->attachOwner(anOwner);
  139. }
  140.  
  141. void displayAccount() {
  142. cout << "List of Account: " << endl <<endl;
  143. int count = 0;
  144. for (auto temp : this->account) {
  145. ++count;
  146. cout << "Account" << count << ": " << endl;
  147. temp->display();
  148. }
  149. if (count == 0)
  150. cout << "Empty!";
  151.  
  152. cout << endl;
  153. }
  154.  
  155. void displayOwner() {
  156. cout << "List of AccountOwner: " << endl << endl;
  157. int count = 0;
  158. for (auto temp : this->owner) {
  159. ++count;
  160. cout << "AccountOwner" << count << ": " << endl;
  161. temp->display();
  162. }
  163. if (count == 0)
  164. cout << "Empty!";
  165.  
  166. cout << endl;
  167. }
  168. };
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175. int main() {
  176. Bank bank;
  177. bank.createAccount("001", 1000);
  178. bank.createAccount("002", 500);
  179. bank.createAccount("003", 50);
  180.  
  181. bank.createOwner("Tran Thanh Dat");
  182. bank.createOwner("Dau Quang Anh");
  183.  
  184. bank.link(bank.getAccount(0), bank.getOwner(0));
  185. bank.link(bank.getAccount(1), bank.getOwner(0));
  186.  
  187. bank.link(bank.getAccount(2), bank.getOwner(0));
  188. bank.link(bank.getAccount(2), bank.getOwner(1));
  189.  
  190. bank.displayAccount();
  191. bank.displayOwner();
  192.  
  193. return 0;
  194. }
Success #stdin #stdout 0s 5296KB
stdin
Standard input is empty
stdout
List of Account: 

Account1: 
Id: 001
Balance: 1000
Linked with AccountOwner: 
AccountOwner1: 
Name: Tran Thanh Dat

Account2: 
Id: 002
Balance: 500
Linked with AccountOwner: 
AccountOwner1: 
Name: Tran Thanh Dat

Account3: 
Id: 003
Balance: 50
Linked with AccountOwner: 
AccountOwner1: 
Name: Tran Thanh Dat
AccountOwner2: 
Name: Dau Quang Anh


List of AccountOwner: 

AccountOwner1: 
Name: Tran Thanh Dat
Linked with Account: 
Account1: 
Id: 001
Balance: 1000
Account2: 
Id: 002
Balance: 500
Account3: 
Id: 003
Balance: 50

AccountOwner2: 
Name: Dau Quang Anh
Linked with Account: 
Account1: 
Id: 003
Balance: 50