usebrass3.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // usebrass3.cpp -- polymorphic example
  2. // compile with acctacb.cpp
  3. #include <iostream>
  4. #include <string>
  5. #include "acctabc.h"
  6. const int CLIENTS = 4;
  7. int main()
  8. {
  9. using std::cin;
  10. using std::cout;
  11. using std::endl;
  12. AcctABC * p_clients[CLIENTS];
  13. std::string temp;
  14. long tempnum;
  15. double tempbal;
  16. char kind;
  17. for (int i = 0; i < CLIENTS; i++)
  18. {
  19. cout << "Enter client's name: ";
  20. getline(cin,temp);
  21. cout << "Enter client's account number: ";
  22. cin >> tempnum;
  23. cout << "Enter opening balance: $";
  24. cin >> tempbal;
  25. cout << "Enter 1 for Brass Account or "
  26. << "2 for BrassPlus Account: ";
  27. while (cin >> kind && (kind != '1' && kind != '2'))
  28. cout <<"Enter either 1 or 2: ";
  29. if (kind == '1')
  30. p_clients[i] = new Brass(temp, tempnum, tempbal);
  31. else
  32. {
  33. double tmax, trate;
  34. cout << "Enter the overdraft limit: $";
  35. cin >> tmax;
  36. cout << "Enter the interest rate "
  37. << "as a decimal fraction: ";
  38. cin >> trate;
  39. p_clients[i] = new BrassPlus(temp, tempnum, tempbal,
  40. tmax, trate);
  41. }
  42. while (cin.get() != '\n')
  43. continue;
  44. }
  45. cout << endl;
  46. for (int i = 0; i < CLIENTS; i++)
  47. {
  48. p_clients[i]->ViewAcct();
  49. cout << endl;
  50. }
  51. for (int i = 0; i < CLIENTS; i++)
  52. {
  53. delete p_clients[i]; // free memory
  54. }
  55. cout << "Done.\n";
  56. // cin.get();
  57. return 0;
  58. }