~cpp
#include <iostream>
#include <cstring>
using namespace std;
class Customer {
private:
int input;
public:
int mainMenuInput(){
cout << ">> ";
cin >> input;
if (input < 1 || input > 5){
cout << "못 .\n";
input = 0;
}
return input;
}
};
class SuperMarket{
private:
int money, cash, wantProduct, wantNum;
struct goods{
char name[10];
int price;
int num;
};
goods product[3];
public:
SuperMarket() {
money = 0;
strcpy(product[0].name, "디"); product[0].price = 1000;
strcpy(product[1].name, "디"); product[1].price = 1200;
strcpy(product[2].name, "마"); product[2].price = 5000;
for (int i = 0 ; i < 3 ; i++)
product[i].num = 0;
}
void mainMenuView() {
cout << "메메뉴 n1. 돈 n2. 물 n3. 물 목 보 \n"
<< "4. 물 n5. \n";
}
void moneyView(){
cout << "남 돈 : " << money << endl;
}
void cashMoney(){
cout << "마를 ? ";
cin >> cash;
money += cash;
}
void buyGoods(){
cout << " 메뉴n";
for (int i = 0 ; i < 3 ; i++)
cout << i << ". " << product[i].name << " " << product[i].price << "\n";
cout << " 물 르 >> ";
cin >> wantProduct;
cout << " 물 량 >> ";
cin >> wantNum;
if (money >= product[wantProduct].price * wantNum){
money -= product[wantProduct].price * wantNum;
product[wantProduct].num += wantNum;
cout << product[wantProduct].name << " " << wantNum << " .\n";
}
else
cout << " 부.\n";
}
void showBoughtGoods(){
cout << " 물\n";
for (int i = 0 ; i < 3 ; i++)
if (product[i].num > 0)
cout << i << ". " << product[i].name << " " << product[i].num << "\n";
}
void cancelToBuyProduct(){
cout << " 물 번를 >> ";
cin >> wantProduct;
cout << " 물 량 >> ";
cin >> wantNum;
if (product[wantProduct].num >= wantNum){
money += product[wantProduct].price * wantNum;
product[wantProduct].num -= wantNum;
cout << product[wantProduct].name << " " << wantNum << " .\n";
}
else
cout << " 량 량보 많.\n";
}
};
int main(){
Customer customer;
SuperMarket supermarket;
int input;
while(input != 5)
{
supermarket.mainMenuView();
supermarket.moneyView();
input = customer.mainMenuInput();
if (input == 1)
supermarket.cashMoney();
else if (input == 2)
supermarket.buyGoods();
else if (input == 3)
supermarket.showBoughtGoods();
else if (input == 4){
supermarket.showBoughtGoods();
supermarket.cancelToBuyProduct();
}
else if (input == 5)
break;
cout << endl;
system("pause");
system("cls");
}
return 0;
}