#include <iostream>
using namespace std;
class Menu {
protected:
int drink_choice=0; //음료수 선택 변수
int fp=0, tp=0; // 지폐 개수
int fh=0, oh=0, ft=0, ot=0; //동전들의 개수
int five_h_cent=0, one_h_cent=0, five_t_cent=0, one_t_cent=0; // 500원, 100원, 50원 ,10원 개수
int five_th_money = 0, one_th_money = 0;
int total_money = 0; // 자판기가 가지고 있는 총 금액
int input_total_money = 0; // 사용자가 자판기에 넣은 금액
private:
int profit = 0; //총 이익
int choice = 0, choice2 = 0;
int pocari = 700, epro = 800, vitamin = 900, redbull = 1200;// 음료수 목록
int pn = 0, en = 0, vn = 0, rn = 0; //음료수 개수
public:
void menu(); // 메뉴 호출
Menu(); // 메뉴 기본 생성자
void add_cent(int fh, int oh, int ft, int ot); //자판기에 동전 추가하고 호출
int user_input_money(int fp, int tp, int fh, int oh); //사용자가 자판기에 돈 넣기
int drink_select(); //음료수 선택
void drink_price(int drink); //음료수 계산
};
void Menu::drink_price(int drink) {
profit += drink;
}
int Menu::drink_select() {
if (user_input_money(fp,tp,fh,oh)) {
cout << "사용자가 자판기에 넣은 금액은 " << input_total_money << "입니다" << endl;
cout << "이제 음료수를 선택하셔야 합니다" << endl;
cout << "1: 포카리(700원) 2:이프로(800원) 3:비타민(900원) 4:레드불(1200원)" << endl;
cin >> drink_choice;
if (drink_choice == 1) {
cout << "포카리를 선택하셨습니다" << endl;
pn++;
drink_price(pocari);
return pocari;
}
else if (drink_choice == 2) {
cout << "이프로를 선택하셨습니다" << endl;
en++;
drink_price(epro);
return epro;
}
else if (drink_choice == 3) {
cout << "비타민을 선택하셨습니다" << endl;
vn++;
drink_price(vitamin);
return vitamin;
}
else if (drink_choice == 4) {
cout << "레드불을 선택하셨습니다" << endl;
rn++;
drink_price(redbull);
return redbull;
}
}
else {
cout << "거스를 돈이 없거나 자판기에 넣은 금액으로 음료수를 사기에는 턱 없이 부족합니다." << endl;
return 0;
}
}
Menu::Menu() {
}
void Menu::add_cent(int fh, int oh, int ft, int ot) {
five_h_cent += fh;
one_h_cent += oh;
five_t_cent += ft;
one_t_cent += ot;
total_money = five_h_cent * 500 + one_h_cent * 100 + five_t_cent * 50 + one_t_cent * 10;
cout << "자판기가 가지고 있는 총 금액은" << total_money << "입니다" << endl;
}
int Menu::user_input_money(int fp, int tp, int fh, int oh) {
five_th_money = fp;
one_th_money = tp;
five_h_cent = fh;
one_h_cent = oh;
input_total_money = (five_th_money * 5000) + (one_th_money * 1000) + (five_h_cent * 500) + (one_h_cent * 100);
if (total_money > input_total_money && input_total_money >= 700) {
return 1;
}
else {
return 0;
}
}
void Menu::menu() {
do {
cout << "메뉴를 선택하세요:" << endl;
cout << "1.유지보수(동전 보급, 일일매출현황 보고서 출력)" << endl;
cout << "2.운영(음료수 구입)" << endl;
cout << "3. 종료하기" << endl;
cin >> choice;
if (choice == 1) {
cout << "유지보수를 선택하셨습니다" << endl;
cout<<"1: 동전 보급 메뉴 2: 일일 매출 현황 보고서"<<endl;
cin >> choice2;
if (choice2 == 1) {
cout << "동전 보급 메뉴입니다." << endl;
cout << "500원 몇개를 넣을 것인가요?" << endl;
cin >> fh;
cout << "100원 몇개를 넣을 것인가요?" << endl;
cin >> oh;
cout << "50원 몇개를 넣을 것인가요?" << endl;
cin >> ft;
cout << "10원 몇개를 넣을 것인가요?" << endl;
cin >> ot;
add_cent(fh, oh, ft, ot);
}
else if (choice2 == 2) {
cout << "일일 매출 현황 보고서 메뉴입니다." << endl;
cout << "총 매출은 " << profit << "원 입니다" << endl;
cout << "판매개수" << endl;
cout << "-------------------" << endl;
cout << "포카리 : " << pn << "개" << endl;
cout << "이프로 : " << en << "개" << endl;
cout << "비타민 : " << vn << "개" << endl;
cout << "레드불 : " << rn << "개" << endl;
}
}
else if (choice == 2) {
cout << "음료수 구입 메뉴입니다." << endl;
cout << "5000원 짜리 몇장을 넣을 것인가요?" << endl;
cin >> fp;
cout << "1000원 짜리 몇장을 넣을 것인가요?" << endl;
cin >> tp;
cout << "500원 짜리 몇개를 넣을 것인가요?" << endl;
cin >> fh;
cout << "100원 짜리 몇개를 넣을 것인가요?" << endl;
cin >> oh;
user_input_money(fp, tp, fh, oh);
drink_select();
}
} while (choice != 3);
cout << "메뉴종료" << endl;
}
class Change :public Menu {
private:
int change_money = 0; //거스름돈
public:
void change();
};
void Change::change() {
change_money = input_total_money - drink_select();
cout << "거스름 돈은 " << change_money << "원 입니다." << endl;
cout << "500원 짜리 :" << change_money / 500 << "개" << endl;
cout << "100원 짜리 :" << (change_money % 500) / 100 << "개" << endl;
cout << "50원 짜리 :" << (change_money % 100) / 50 << "개" << endl;
cout << "10원 짜리 :" << (change_money % 50) / 10 << "개" << endl;
}
int main() {
Menu m;
Change c;
m.menu();
return 0;
}