fork download
  1. // acctabc.h -- bank account classes
  2. #ifndef ACCTABC_H_
  3. #define ACCTABC_H_
  4.  
  5. // Abstract Base Class
  6. class AcctABC
  7. {
  8. private:
  9. enum {MAX = 35};
  10. char fullName[MAX];
  11. long acctNum;
  12. double balance;
  13. protected:
  14. const char * FullName() const {return fullName;}
  15. long AcctNum() const {return acctNum;}
  16. std::ios_base::fmtflags SetFormat() const;
  17. public:
  18. AcctABC(const char *s = "Nullbody", long an = -1,
  19. double bal = 0.0);
  20. void Deposit(double amt) ;
  21. virtual void Withdraw(double amt) = 0; // pure virtual function
  22. double Balance() const {return balance;};
  23. virtual void ViewAcct() const = 0; // pure virtual function
  24. virtual ~AcctABC() {}
  25. };
  26.  
  27. // Brass Account Class
  28. class Brass :public AcctABC
  29. {
  30. public:
  31. Brass(const char *s = "Nullbody", long an = -1,
  32. double bal = 0.0) : AcctABC(s, an, bal) { }
  33. virtual void Withdraw(double amt);
  34. virtual void ViewAcct() const;
  35. virtual ~Brass() {}
  36. };
  37.  
  38. //Brass Plus Account Class
  39. class BrassPlus : public AcctABC
  40. {
  41. private:
  42. double maxLoan;
  43. double rate;
  44. double owesBank;
  45. public:
  46. BrassPlus(const char *s = "Nullbody", long an = -1,
  47. double bal = 0.0, double ml = 500,
  48. double r = 0.10);
  49. BrassPlus(const Brass & ba, double ml = 500, double r = 0.1);
  50. virtual void ViewAcct()const;
  51. virtual void Withdraw(double amt);
  52. void ResetMax(double m) { maxLoan = m; }
  53. void ResetRate(double r) { rate = r; };
  54. void ResetOwes() { owesBank = 0; }
  55. };
  56.  
  57. #endif
  58.  
  59. // acctabc.cpp -- bank account class methods
  60. #include <iostream>
  61. #include <cstring>
  62. using std::cout;
  63. using std::ios_base;
  64. using std::endl;
  65.  
  66. #include "acctabc.h"
  67.  
  68. // Abstract Base Class
  69. AcctABC::AcctABC(const char *s, long an, double bal)
  70. {
  71. std::strncpy(fullName, s, MAX - 1);
  72. fullName[MAX - 1] = '\0';
  73. acctNum = an;
  74. balance = bal;
  75. }
  76.  
  77. void AcctABC::Deposit(double amt)
  78. {
  79. if (amt < 0)
  80. cout << "Negative deposit not allowed; "
  81. << "deposit is cancelled.\n";
  82. else
  83. balance += amt;
  84. }
  85.  
  86. void AcctABC::Withdraw(double amt)
  87. {
  88. balance -= amt;
  89. }
  90.  
  91. // protected method
  92. ios_base::fmtflags AcctABC::SetFormat() const
  93. {
  94. // set up ###.## format
  95. ios_base::fmtflags initialState =
  96. cout.setf(ios_base::fixed, ios_base::floatfield);
  97. cout.setf(ios_base::showpoint);
  98. cout.precision(2);
  99. return initialState;
  100. }
  101.  
  102. // Brass methods
  103. void Brass::Withdraw(double amt)
  104. {
  105. if (amt < 0)
  106. cout << "Withdrawal amount must be positive; "
  107. << "withdrawal canceled.\n";
  108. else if (amt <= Balance())
  109. AcctABC::Withdraw(amt);
  110. else
  111. cout << "Withdrawal amount of $" << amt
  112. << " exceeds your balance.\n"
  113. << "Withdrawal canceled.\n";
  114. }
  115.  
  116. void Brass::ViewAcct() const
  117. {
  118.  
  119. ios_base::fmtflags initialState = SetFormat();
  120. cout << "Brass Client: " << FullName() << endl;
  121. cout << "Account Number: " << AcctNum() << endl;
  122. cout << "Balance: $" << Balance() << endl;
  123. cout.setf(initialState);
  124. }
  125.  
  126. // BrassPlus Methods
  127. BrassPlus::BrassPlus(const char *s, long an, double bal,
  128. double ml, double r) : AcctABC(s, an, bal)
  129. {
  130. maxLoan = ml;
  131. owesBank = 0.0;
  132. rate = r;
  133. }
  134.  
  135. BrassPlus::BrassPlus(const Brass & ba, double ml, double r)
  136. : AcctABC(ba) // uses implicit copy constructor
  137. {
  138. maxLoan = ml;
  139. owesBank = 0.0;
  140. rate = r;
  141. }
  142.  
  143. void BrassPlus::ViewAcct() const
  144. {
  145. ios_base::fmtflags initialState = SetFormat();
  146.  
  147. cout << "BrassPlus Client: " << FullName() << endl;
  148. cout << "Account Number: " << AcctNum() << endl;
  149. cout << "Balance: $" << Balance() << endl;
  150. cout << "Maximum loan: $" << maxLoan << endl;
  151. cout << "Owed to bank: $" << owesBank << endl;
  152. cout << "Loan Rate: " << 100 * rate << "%\n";
  153. cout.setf(initialState);
  154. }
  155.  
  156. void BrassPlus::Withdraw(double amt)
  157. {
  158. ios_base::fmtflags initialState = SetFormat();
  159.  
  160. double bal = Balance();
  161. if (amt <= bal)
  162. AcctABC::Withdraw(amt);
  163. else if ( amt <= bal + maxLoan - owesBank)
  164. {
  165. double advance = amt - bal;
  166. owesBank += advance * (1.0 + rate);
  167. cout << "Bank advance: $" << advance << endl;
  168. cout << "Finance charge: $" << advance * rate << endl;
  169. Deposit(advance);
  170. AcctABC::Withdraw(amt);
  171. }
  172. else
  173. cout << "Credit limit exceeded. Transaction cancelled.\n";
  174. cout.setf(initialState);
  175. }
  176.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:66:21: error: acctabc.h: No such file or directory
prog.cpp:16: error: ‘std::ios_base’ has not been declared
prog.cpp:16: error: ISO C++ forbids declaration of ‘fmtflags’ with no type
prog.cpp:16: error: expected ‘;’ before ‘SetFormat’
prog.cpp:92: error: no ‘std::_Ios_Fmtflags AcctABC::SetFormat() const’ member function declared in class ‘AcctABC’
prog.cpp: In member function ‘virtual void Brass::ViewAcct() const’:
prog.cpp:119: error: ‘SetFormat’ was not declared in this scope
prog.cpp: In member function ‘virtual void BrassPlus::ViewAcct() const’:
prog.cpp:145: error: ‘SetFormat’ was not declared in this scope
prog.cpp: In member function ‘virtual void BrassPlus::Withdraw(double)’:
prog.cpp:158: error: ‘SetFormat’ was not declared in this scope
stdout
Standard output is empty