U E D R , A S I H C RSS

Super Market/재니

02 Genie

~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
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:09
Processing time 0.0095 sec