Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. class Money {
  8. private:
  9. long int roubles;
  10. long int copeiki;
  11. public:
  12. Money(long int rub, long int cop) {
  13. roubles = rub;
  14. if (cop > 99) {
  15. roubles += cop / 100;
  16. copeiki = cop % 100;
  17. }
  18. else {
  19. copeiki = cop;
  20. }
  21. }
  22.  
  23. Money(long int cop) {
  24. roubles = 0;
  25. if (cop > 99) {
  26. roubles += cop / 100;
  27. copeiki = cop % 100;
  28. }
  29. else {
  30. copeiki = cop;
  31. }
  32. }
  33.  
  34. Money() {
  35. roubles = 0;
  36. copeiki = 0;
  37. }
  38.  
  39. ~Money() {}
  40.  
  41. void moneyAdd(long int rub, long int cop) {
  42. roubles += rub;
  43. if (copeiki + cop > 99) {
  44. roubles += (copeiki + cop) / 100;
  45. copeiki = (copeiki + cop) % 100;
  46. }
  47. else {
  48. copeiki += cop;
  49. }
  50. if (copeiki < 0) {
  51. copeiki += cop;
  52. }
  53. }
  54.  
  55. void moneyTake(long int rub, long int cop) {
  56. roubles -= rub;
  57. copeiki -= cop;
  58. if (copeiki < -99) {
  59. roubles += copeiki / 100;
  60. copeiki = copeiki % 100;
  61. }
  62. if (copeiki < 0 || roubles < 0) {
  63. cout << "You owe us " << fabs(roubles) << " roubles and " << fabs(copeiki) << " copeek. ";
  64. }
  65. }
  66.  
  67. void getMoney() {
  68. cout << "Your money: " << roubles << " roubles and " << copeiki << " copeek" << endl;
  69. if (copeiki < 0 || roubles < 0) {
  70. cout << "You owe us " << fabs(roubles) << " roubles and " << fabs(copeiki) << " copeek. ";
  71. }
  72. else {
  73. cout << "You owe us 0 roubles and 0 copeek. ";
  74. }
  75. }
  76.  
  77. void display() {
  78. bool isWorking = true;
  79. while (isWorking) {
  80. system("cls");
  81. cout << "What would you like to do?" << endl;
  82. cout << "1. Display info about your money. " << endl;
  83. cout << "2. Add money. " << endl;
  84. cout << "3. Take money. " << endl;
  85. cout << "4. Exit. " << endl;
  86. cout << "______________________________" << endl;
  87. cout << "Your choice: ";
  88. int n = 0;
  89. long int rub, cop;
  90. cin >> n;
  91. switch (n) {
  92. case 1: {
  93. system("cls");
  94. getMoney();
  95. system("PAUSE");
  96. break;
  97. }
  98. case 2: {
  99. system("cls");
  100. cout << "How much money would you like to add?" << endl;
  101. cout << "Roubles: " << endl;
  102. cin >> rub;
  103. cout << "Copeiki: " << endl;
  104. cin >> cop;
  105. if (rub < 0)
  106. rub = fabs(rub);
  107. if (cop < 0)
  108. cop = fabs(cop);
  109. moneyAdd(rub, cop);
  110. system("PAUSE");
  111. break;
  112. }
  113. case 3: {
  114. system("cls");
  115. cout << "How much money would you like to take?" << endl;
  116. cout << "Roubles: " << endl;
  117. cin >> rub;
  118. cout << "Copeiki: " << endl;
  119. cin >> cop;
  120. if (rub < 0)
  121. rub = fabs(rub);
  122. if (cop < 0)
  123. cop = fabs(cop);
  124. moneyTake(rub, cop);
  125. system("PAUSE");
  126. break;
  127. }
  128. case 4: {
  129. system("cls");
  130. cout << "Goodbye! " << endl;
  131. isWorking = false;
  132. system("PAUSE");
  133. break;
  134. }
  135. }
  136. }
  137. }
  138. };
  139.  
  140.  
  141. int main() {
  142. Money mon;
  143. mon.display();
  144. return 0;
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement