������ ������ ¶
~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; }
������고������ ¶
������������ ������게���...ㅡㅡ;;
* ��������� ������ ���기 ���게 ���������... ���������기 ��� ��������� ���고... ���기 ������������...-,-;;; --������
----
CppStudy_2002_2
----
CppStudy_2002_2