fork download
  1. // bank Account header
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class BankAccount
  6. {
  7. public:
  8. BankAccount();
  9. BankAccount(char *name, int AccountNumber, double balance);
  10. BankAccount(BankAccount&copy);
  11.  
  12. void Deposit(double AMT);
  13. double Balance1();
  14. virtual void WithDraw(double AMT);
  15. virtual void ViewAccount();
  16. virtual ~BankAccount();
  17.  
  18.  
  19. private:
  20. char *name;
  21. int AccountNumber;
  22. double Balance;
  23.  
  24. };
  25.  
  26. // bank Account cpp header
  27.  
  28.  
  29. BankAccount::BankAccount()
  30. {
  31. }
  32.  
  33. BankAccount::BankAccount(char *name, int AccountNumber, double balance)
  34. {
  35. int i = 0;
  36. while (name[i] != '\0')
  37. {
  38. this->name[i] = name[i];
  39. }
  40. this->name[i] = '\0';
  41. this->AccountNumber = AccountNumber;
  42. this->Balance = balance;
  43.  
  44. }
  45. BankAccount::BankAccount(BankAccount&copy)
  46. {
  47. int i = 0;
  48. while (name[i] != '\0')
  49. {
  50. this->name[i] = copy.name[i];
  51. }
  52. this->AccountNumber = copy.AccountNumber;
  53. this->Balance = copy.Balance;
  54. }
  55.  
  56. void BankAccount::Deposit(double AMT)
  57. {
  58. if (AMT < 0)
  59. {
  60. cout << "Invalid or negative amount. Payment canceled " << endl;
  61.  
  62. }
  63. else
  64. Balance += AMT;
  65. }
  66.  
  67. void BankAccount::WithDraw(double AMT)
  68. {
  69. if (AMT < 0)
  70. {
  71. cout << "Invalid or negative amount. Payment canceled " << endl;
  72. }
  73. else if (AMT <= Balance)
  74. {
  75. Balance -= AMT;
  76. }
  77. else
  78. {
  79. cout << "There are not enough funds in your account " << endl;
  80. }
  81. }
  82.  
  83. void BankAccount::ViewAccount()
  84. {
  85. cout << "name: " << name << endl;
  86. cout << "balance: " << Balance << endl;
  87. cout << "AccountNumber: " << AccountNumber << endl;
  88. }
  89.  
  90. double BankAccount::Balance1()
  91. {
  92. return Balance;
  93. }
  94.  
  95. BankAccount::~BankAccount()
  96. {
  97. delete[] name;
  98. }
  99.  
  100. using namespace std;
  101.  
  102. class BankAccountPlus:public BankAccount
  103. {
  104. private:
  105. double MaxLoan;
  106. double Rate;
  107. double OwesBank;
  108.  
  109. public:
  110. BankAccountPlus();
  111. BankAccountPlus(char *name, int AccountNumber, double Balance, double MaxLoan, double Rate);
  112. BankAccountPlus(const BankAccount&Balance1, double MaxLoan, double Rate);
  113. BankAccountPlus(BankAccountPlus&copy);
  114.  
  115.  
  116. virtual void ViewAccount();
  117. virtual void WithDraw(double AMT);
  118. virtual ~BankAccountPlus();
  119.  
  120. void StartLoan(double Maxloan1);
  121. void StartRate(double Rate1);
  122. void StartOwes();
  123.  
  124. };
  125.  
  126. BankAccountPlus::BankAccountPlus()
  127. {
  128.  
  129. }
  130.  
  131. BankAccountPlus::BankAccountPlus(char *name, int AccountNumber, double Balance, double MaxLoan, double Rate) :BankAccount(name, AccountNumber, Balance)
  132. {
  133. MaxLoan = MaxLoan;
  134. OwesBank = 0;
  135. Rate = Rate;
  136. }
  137.  
  138. BankAccountPlus::BankAccountPlus(const BankAccount&Balance1, double MaxLoan, double Rate)
  139. {
  140. this->MaxLoan = MaxLoan;
  141. this->Rate = Rate;
  142. this->OwesBank = 0;
  143. }
  144.  
  145. BankAccountPlus::BankAccountPlus(BankAccountPlus&copy)
  146. {
  147. this->MaxLoan = copy.MaxLoan;
  148. this->Rate = copy.Rate;
  149. this->OwesBank = copy.OwesBank;
  150. }
  151.  
  152. void BankAccountPlus::ViewAccount()
  153. {
  154. BankAccount::ViewAccount(); // przywolywanie elementow z klasy bazowej
  155. cout << " Max debit is: " << MaxLoan << " PLN " << endl;
  156. cout << " Liabilities to the bank " << OwesBank << endl;
  157. cout << " Interest rate " << 100 * Rate << endl;
  158. }
  159.  
  160. void BankAccountPlus::WithDraw(double AMT)
  161. {
  162. double balance = Balance1();
  163. if (AMT < balance)
  164. {
  165. BankAccount::WithDraw(AMT);
  166. }
  167. else if (AMT <= balance + MaxLoan - OwesBank)
  168. {
  169. double more = AMT - balance;
  170. OwesBank += more*(1 + Rate);
  171. cout << " Real Loan: " << more << endl;
  172. cout << " interest: " << more*Rate << " zl" << endl;
  173. Deposit(more);
  174. BankAccount::WithDraw(AMT);
  175.  
  176. }
  177. else
  178. {
  179. cout << " Your limit is overrated. Operation canceled " << endl;
  180. }
  181.  
  182.  
  183. }
  184.  
  185. BankAccountPlus::~BankAccountPlus()
  186. {
  187. }
  188.  
  189. // MAIN
  190. #include <iostream>
  191. #include <istream>
  192. const int clients = 4;
  193.  
  194.  
  195. using namespace std;
  196. int main()
  197. {
  198. char Name[50];
  199. int AccountNumber, choice;
  200. double Balance;
  201.  
  202. BankAccount *P_Clients[clients];
  203. for (int i = 0; i < clients; i++)
  204. {
  205. cout << "Enter Basic Informations - including: Name, Account Number and Balance " << endl;
  206. system("cls");
  207. cout << "Name" << endl;
  208. cin >> Name;
  209. cout << "AccountNumber" << endl;
  210. cin >> AccountNumber;
  211. cout << "Balance " << endl;
  212. cin >> Balance;
  213. cout << " Which acccount would you choose ? If you press 1 - Standrad Account If you press 2- LoAccount" << endl;
  214. cin >> choice;
  215. if (choice == 1)
  216. {
  217. P_Clients[i] = new BankAccount(Name, AccountNumber, Balance);
  218. }
  219. else if (choice == 2)
  220. {
  221. double Loan, RatePlus;
  222. cout << " eneter value of your max debit " << endl;
  223. cin >> Loan;
  224. cout << " enter interest rate | decimal format like: xx.zzz " << endl;
  225. cin >> RatePlus;
  226. P_Clients[i] = new BankAccountPlus(Name, AccountNumber, Balance, Loan, RatePlus);
  227. }
  228. cout << endl;
  229.  
  230. }
  231. cout << "Show a member of bank." << endl;
  232. for (int i = 0; i<clients; i++)
  233. {
  234. P_Clients[i]->ViewAccount(); // wskazanie na informacje o danym czlonku ( w zaleznosci od wyboru konta za pomoca -> ) // uzycie metody virtuanej
  235. cout << endl;
  236. }
  237. for (int i = 0; i < clients; i++)
  238. {
  239. delete[] P_Clients[i]; // zwalanianie pamieci
  240. }
  241.  
  242. return 0;
  243. }
  244.  
  245.  
  246.  
Runtime error #stdin #stdout #stderr 0s 16072KB
stdin
Standard input is empty
stdout
Enter Basic Informations - including: Name, Account Number and Balance 
Name
AccountNumber
Balance 
 Which acccount would you choose  ? If you press 1 - Standrad Account If you press 2- LoAccount

Enter Basic Informations - including: Name, Account Number and Balance 
Name
AccountNumber
Balance 
 Which acccount would you choose  ? If you press 1 - Standrad Account If you press 2- LoAccount

Enter Basic Informations - including: Name, Account Number and Balance 
Name
AccountNumber
Balance 
 Which acccount would you choose  ? If you press 1 - Standrad Account If you press 2- LoAccount

Enter Basic Informations - including: Name, Account Number and Balance 
Name
AccountNumber
Balance 
 Which acccount would you choose  ? If you press 1 - Standrad Account If you press 2- LoAccount

Show a member of bank.
stderr
sh: 1: cls: not found
sh: 1: cls: not found
sh: 1: cls: not found
sh: 1: cls: not found