Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "CreditCard.h"
  3. #include <iostream>
  4. #include <fstream>
  5. #include <ctime>
  6. #include <sstream>
  7.  
  8. using namespace std;
  9.  
  10. CreditCard::CreditCard()
  11. {
  12. string fName;
  13. ifstream fin;
  14. ostringstream n;
  15.  
  16. srand((unsigned)time(0));
  17. Ano = (rand() % 100000) + 1;
  18. n << Ano << flush;
  19. fName = "CC" + n.str() + ".txt";
  20. fin.open(fName.c_str());
  21. while (fin.is_open())
  22. {
  23. fin.close();
  24. Ano = (rand() % 100000 + 1);
  25. n << Ano << flush;
  26. fName = "CC" + n.str() + ".txt";
  27. fin.open(fName.c_str());
  28. }
  29. fin.close();
  30. vCLimit = 1000;
  31. vBalDue = 0;
  32. CCName = fName;
  33. CCLName = "CCL" + n.str() + ".txt";
  34. writestatus();
  35. writelog("Account " + n.str() + "opened. ");
  36. }
  37. CreditCard::CreditCard(int a)
  38. {
  39. string fName;
  40. ifstream fin;
  41. ostringstream n;
  42. vErr = false;
  43.  
  44. n << a << flush;
  45. fName = "CC" + n.str() + ".txt";
  46. fin.open(fName.c_str());
  47. if (fin.is_open())
  48. {
  49. Ano = a;
  50. fin >> vCLimit;
  51. fin >> vBalDue;
  52. fin.close();
  53. CCName = fName;
  54. CCLName = "CCL" + n.str() + ".txt";
  55. writelog("Account " + n.str() + " reopened. ");
  56. }
  57. else
  58. {
  59. Ano = 0;
  60. vCLimit = 0;
  61. vBalDue = 0;
  62. vErr = true;
  63. vEMsg = "Account " + n.str() + "could not be opened. ";
  64. }
  65. }
  66. void CreditCard::applyCharge(int charge)
  67. {
  68. vBalDue = vBalDue + charge;
  69. vCLimit = vCLimit - charge;
  70. }
  71. void CreditCard::applyPayment(int payment)
  72. {
  73. vBalDue = vBalDue - payment;
  74. vCLimit = vCLimit + payment;
  75. }
  76. int CreditCard::getAcctNo()
  77. {
  78. return Ano;
  79. }
  80. double CreditCard::getCreditLimit()
  81. {
  82. return vCLimit;
  83. }
  84. double CreditCard::getBalanceDue()
  85. {
  86. return vBalDue;
  87. }
  88. void CreditCard::writestatus()
  89. {
  90. vErr = false;
  91. vEMsg = "";
  92. ofstream fout;
  93. fout.open(CCName.c_str());
  94. if (fout.is_open())
  95. {
  96. fout << vCLimit << endl;
  97. fout << vBalDue << endl;
  98. fout.close();
  99. }
  100. else
  101. {
  102. vErr - true;
  103. vEMsg = "Unable to write status file. ";
  104. }
  105. }
  106. void CreditCard::writelog(string m)
  107. {
  108. vErr = false;
  109. vEMsg = "";
  110. time_t rawtime;
  111. time(&rawtime);
  112.  
  113. ofstream fout;
  114. fout.open(CCLName.c_str(), ios_base::app);
  115. if (fout.is_open())
  116. {
  117. fout << m << " on " << ctime(&rawtime) << endl;
  118. fout.close();
  119. }
  120. else
  121. {
  122. vErr = true;
  123. vEMsg = "Unable to write log entry: " + m;
  124. }
  125. }
  126. CreditCard::~CreditCard()
  127. {
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement