Advertisement
daniel_c05

Classes and Constructors.h

Feb 18th, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.06 KB | None | 0 0
  1. #ifndef Banking_Base
  2. #define Banking_Base
  3. #include <string>
  4. using namespace std;
  5.  
  6. class BankAccount {
  7. //Let's create some properties for our Class
  8.     //These guys are private by default
  9. string cardType, cardOwner, rewardsType, cardNumber;
  10. double creditLimit, availableCredit, currentBalance;
  11.  
  12. public:
  13. //Let's create some methods for our Class
  14.     //These guys are public, and will allow us to modify the private properties
  15.     //in their same class.
  16.     //These are just prototypes, not the actual code that will be executed upon a call.
  17. void setCardType (string);
  18. void setCardOwner(string);
  19. void setRewardsType(string);
  20. void setCardNumber(string);
  21. void setCreditLimit(double);
  22. bool confirmAction(double);     //Unused Method, see line 74
  23. void newAuthorization(double);
  24. void printProperty();
  25. void printProperty(char);
  26.  
  27. //Let's bring in the constructors, and overload them!
  28. BankAccount (string);
  29. BankAccount (string, string, string);
  30. };  //End of Class
  31.  
  32. //Time for Methods again.
  33.  
  34. BankAccount::BankAccount(string c)
  35. {
  36. cardNumber = c;
  37. currentBalance = 0;
  38. }
  39.  
  40. BankAccount::BankAccount(string a, string b,  string c)
  41. {
  42. cardOwner = a;
  43. cardType = b;
  44. cardNumber = c;
  45. currentBalance = 0;
  46. }
  47.  
  48. void BankAccount::setCardType(string a)
  49. {
  50. cardType = a;
  51. }
  52.  
  53. void BankAccount::setCardOwner(string a)
  54. {
  55. cardOwner = a;
  56. }
  57.  
  58. void BankAccount::setRewardsType(string a)
  59. {
  60. rewardsType = a;
  61. }
  62.  
  63. void BankAccount::setCardNumber(string a)
  64. {
  65. cardNumber = a;
  66. }
  67.  
  68. void BankAccount::setCreditLimit(double a) {
  69.     creditLimit = a;
  70.     availableCredit = creditLimit;
  71. }
  72.  
  73. //Unused method, I have to work on it a bit more.
  74. bool BankAccount::confirmAction(double a) {
  75.     cout << "Your current available balance is: " << availableCredit
  76.          << "\nAre you sure you would like to continue with the purchase?(Y = Yes, N = No)"
  77.          << "\nThe total amount to be deducted is: " << a <<endl;
  78.     char confirm = cin.get();
  79.  
  80.     if(confirm == 'Y')  {
  81.         return confirm;
  82.     }
  83.     else if(confirm == 'N') {
  84.         return false;
  85.     }
  86. }
  87.  
  88. void BankAccount::newAuthorization(double a) {
  89.     cout << "Your current available balance is: " << availableCredit
  90.          << "\nAre you sure you would like to continue with the purchase?(Y = Yes, N = No)"
  91.          << "\nThe total amount to be deducted is: " << a <<endl;
  92.  
  93.     string confirm;
  94.     cin >> confirm;
  95.  
  96.     if (confirm == "Y") {
  97.         availableCredit -= a;
  98.         currentBalance += a;
  99.         cout << "The transaction was processed succesfully" << endl;
  100.         cout << "Your new balance is " << availableCredit << endl;
  101.     }
  102.     else {
  103.         cout << "No Transaction was processed today!" << endl;
  104.     }
  105. }
  106.  
  107. void BankAccount::printProperty()
  108. {
  109. cout << "This method allows you to explore the properties of an object belonging to the 'BankAccount' class.\n"
  110.      << "What property would you like to access?"
  111.      << "\nEnter 't' for type, 'o' for owner, 'r' for rewards type, 'c' for card number, 'a' for available credit, 'l' for credit limit, 'b' for current balance."
  112.      << endl;
  113.  
  114. char propertyToPrint;
  115. cin >> propertyToPrint;
  116.  
  117. switch(propertyToPrint) {
  118. case 't':
  119.     cout << cardType << '\n' << endl;
  120.     break;
  121. case 'o':
  122.     cout << cardOwner << '\n' << endl;
  123.     break;
  124. case 'r':
  125.     cout << rewardsType << '\n' << endl;
  126.     break;
  127. case 'c':
  128.     cout << cardNumber << '\n' << endl;
  129.     break;
  130. case 'a':
  131.     cout << availableCredit << '\n' << endl;
  132.     break;
  133. case 'l':
  134.     cout << creditLimit << '\n' << endl;
  135.     break;
  136. case 'b':
  137.     cout << currentBalance << '\n' << endl;
  138.     break;
  139. default:
  140.     cout << "Make sure you enter one of the valid characters!" << endl;
  141. }
  142. }
  143.  
  144. void BankAccount::printProperty(char propertyToPrint)
  145. {
  146. switch(propertyToPrint) {
  147. case 't':
  148.     cout << cardType << '\n' << endl;
  149.     break;
  150. case 'o':
  151.     cout << cardOwner << '\n' << endl;
  152.     break;
  153. case 'r':
  154.     cout << rewardsType << '\n' << endl;
  155.     break;
  156. case 'c':
  157.     cout << cardNumber << '\n' << endl;
  158.     break;
  159. case 'a':
  160.     cout << availableCredit << '\n' << endl;
  161.     break;
  162. case 'l':
  163.     cout << creditLimit << '\n' << endl;
  164.     break;
  165. case 'b':
  166.     cout << currentBalance << '\n' << endl;
  167.     break;
  168. default:
  169.     cout << "Make sure you enter one of the valid characters!" << endl;
  170. }
  171. }
  172.  
  173. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement