fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Menu {
  5. protected:
  6. int drink_choice=0; //음료수 선택 변수
  7. int fp=0, tp=0; // 지폐 개수
  8. int fh=0, oh=0, ft=0, ot=0; //동전들의 개수
  9. int five_h_cent=0, one_h_cent=0, five_t_cent=0, one_t_cent=0; // 500원, 100원, 50원 ,10원 개수
  10. int five_th_money = 0, one_th_money = 0;
  11. int total_money = 0; // 자판기가 가지고 있는 총 금액
  12. int input_total_money = 0; // 사용자가 자판기에 넣은 금액
  13.  
  14. private:
  15. int profit = 0; //총 이익
  16. int choice = 0, choice2 = 0;
  17. int pocari = 700, epro = 800, vitamin = 900, redbull = 1200;// 음료수 목록
  18. int pn = 0, en = 0, vn = 0, rn = 0; //음료수 개수
  19.  
  20. public:
  21. void menu(); // 메뉴 호출
  22. Menu(); // 메뉴 기본 생성자
  23. void add_cent(int fh, int oh, int ft, int ot); //자판기에 동전 추가하고 호출
  24. int user_input_money(int fp, int tp, int fh, int oh); //사용자가 자판기에 돈 넣기
  25. int drink_select(); //음료수 선택
  26. void drink_price(int drink); //음료수 계산
  27. };
  28.  
  29.  
  30. void Menu::drink_price(int drink) {
  31. profit += drink;
  32. }
  33.  
  34.  
  35. int Menu::drink_select() {
  36. if (user_input_money(fp,tp,fh,oh)) {
  37. cout << "사용자가 자판기에 넣은 금액은 " << input_total_money << "입니다" << endl;
  38.  
  39. cout << "이제 음료수를 선택하셔야 합니다" << endl;
  40.  
  41.  
  42. cout << "1: 포카리(700원) 2:이프로(800원) 3:비타민(900원) 4:레드불(1200원)" << endl;
  43. cin >> drink_choice;
  44. if (drink_choice == 1) {
  45. cout << "포카리를 선택하셨습니다" << endl;
  46. pn++;
  47. drink_price(pocari);
  48. return pocari;
  49. }
  50. else if (drink_choice == 2) {
  51. cout << "이프로를 선택하셨습니다" << endl;
  52. en++;
  53. drink_price(epro);
  54. return epro;
  55. }
  56. else if (drink_choice == 3) {
  57. cout << "비타민을 선택하셨습니다" << endl;
  58. vn++;
  59. drink_price(vitamin);
  60. return vitamin;
  61.  
  62. }
  63.  
  64. else if (drink_choice == 4) {
  65. cout << "레드불을 선택하셨습니다" << endl;
  66. rn++;
  67. drink_price(redbull);
  68. return redbull;
  69. }
  70. }
  71. else {
  72. cout << "거스를 돈이 없거나 자판기에 넣은 금액으로 음료수를 사기에는 턱 없이 부족합니다." << endl;
  73. return 0;
  74. }
  75. }
  76.  
  77. Menu::Menu() {
  78.  
  79. }
  80.  
  81. void Menu::add_cent(int fh, int oh, int ft, int ot) {
  82. five_h_cent += fh;
  83. one_h_cent += oh;
  84. five_t_cent += ft;
  85. one_t_cent += ot;
  86. total_money = five_h_cent * 500 + one_h_cent * 100 + five_t_cent * 50 + one_t_cent * 10;
  87. cout << "자판기가 가지고 있는 총 금액은" << total_money << "입니다" << endl;
  88. }
  89.  
  90. int Menu::user_input_money(int fp, int tp, int fh, int oh) {
  91. five_th_money = fp;
  92. one_th_money = tp;
  93. five_h_cent = fh;
  94. one_h_cent = oh;
  95. input_total_money = (five_th_money * 5000) + (one_th_money * 1000) + (five_h_cent * 500) + (one_h_cent * 100);
  96. if (total_money > input_total_money && input_total_money >= 700) {
  97. return 1;
  98. }
  99. else {
  100. return 0;
  101. }
  102. }
  103.  
  104. void Menu::menu() {
  105. do {
  106. cout << "메뉴를 선택하세요:" << endl;
  107. cout << "1.유지보수(동전 보급, 일일매출현황 보고서 출력)" << endl;
  108. cout << "2.운영(음료수 구입)" << endl;
  109. cout << "3. 종료하기" << endl;
  110. cin >> choice;
  111. if (choice == 1) {
  112.  
  113. cout << "유지보수를 선택하셨습니다" << endl;
  114. cout<<"1: 동전 보급 메뉴 2: 일일 매출 현황 보고서"<<endl;
  115. cin >> choice2;
  116. if (choice2 == 1) {
  117. cout << "동전 보급 메뉴입니다." << endl;
  118. cout << "500원 몇개를 넣을 것인가요?" << endl;
  119. cin >> fh;
  120. cout << "100원 몇개를 넣을 것인가요?" << endl;
  121. cin >> oh;
  122. cout << "50원 몇개를 넣을 것인가요?" << endl;
  123. cin >> ft;
  124. cout << "10원 몇개를 넣을 것인가요?" << endl;
  125. cin >> ot;
  126. add_cent(fh, oh, ft, ot);
  127. }
  128. else if (choice2 == 2) {
  129. cout << "일일 매출 현황 보고서 메뉴입니다." << endl;
  130. cout << "총 매출은 " << profit << "원 입니다" << endl;
  131. cout << "판매개수" << endl;
  132. cout << "-------------------" << endl;
  133. cout << "포카리 : " << pn << "개" << endl;
  134. cout << "이프로 : " << en << "개" << endl;
  135. cout << "비타민 : " << vn << "개" << endl;
  136. cout << "레드불 : " << rn << "개" << endl;
  137.  
  138. }
  139. }
  140.  
  141. else if (choice == 2) {
  142. cout << "음료수 구입 메뉴입니다." << endl;
  143. cout << "5000원 짜리 몇장을 넣을 것인가요?" << endl;
  144. cin >> fp;
  145. cout << "1000원 짜리 몇장을 넣을 것인가요?" << endl;
  146. cin >> tp;
  147. cout << "500원 짜리 몇개를 넣을 것인가요?" << endl;
  148. cin >> fh;
  149. cout << "100원 짜리 몇개를 넣을 것인가요?" << endl;
  150. cin >> oh;
  151. user_input_money(fp, tp, fh, oh);
  152. drink_select();
  153.  
  154.  
  155. }
  156. } while (choice != 3);
  157. cout << "메뉴종료" << endl;
  158.  
  159.  
  160. }
  161.  
  162.  
  163.  
  164. class Change :public Menu {
  165. private:
  166. int change_money = 0; //거스름돈
  167.  
  168. public:
  169. void change();
  170.  
  171.  
  172. };
  173.  
  174. void Change::change() {
  175. change_money = input_total_money - drink_select();
  176. cout << "거스름 돈은 " << change_money << "원 입니다." << endl;
  177. cout << "500원 짜리 :" << change_money / 500 << "개" << endl;
  178. cout << "100원 짜리 :" << (change_money % 500) / 100 << "개" << endl;
  179. cout << "50원 짜리 :" << (change_money % 100) / 50 << "개" << endl;
  180. cout << "10원 짜리 :" << (change_money % 50) / 10 << "개" << endl;
  181.  
  182.  
  183. }
  184.  
  185.  
  186.  
  187. int main() {
  188. Menu m;
  189. Change c;
  190. m.menu();
  191. return 0;
  192. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:10: fatal error: iostream: No such file or directory
 #include <iostream>
          ^~~~~~~~~~
compilation terminated.
stdout
Standard output is empty