¶
~cpp
#include <iostream>
using namespace std;
#include <string>
//기
class VendingMachine
{
private:
int _money;
int _temp_money;
int _select_money, _select_drink, _insert_amount;
struct drink
{
char * name;
int price, amount;
};
drink s_drink[5];
int _max_num;
public:
VendingMachine();
int showMenu();
void get_money();
void buy();
void takeBack_money();
void insertDrink();
};
int VendingMachine::showMenu()
{
int choice;
cout << "\n기 \n";
cout << "1. \n";
cout << "2. \n";
cout << "3. 거 \n";
cout << "4. \n";
cout << "0.\n";
cout << " : ";
cin >> choice;
return choice;
}
//기 기
VendingMachine::VendingMachine()
{
_money = _temp_money = 0;
_max_num = 5;
char * drink_name[] = {"coke", "juice", "tea" , "cofee", "milk"};
int price[] = {400, 600, 500, 450, 350};
for(int i = 0 ; i < _max_num ; i++)
{
s_drink[i].name = drink_name[i];
s_drink[i].price = price[i];
s_drink[i].amount = 10;
}
}
// 기
void VendingMachine::get_money()
{
cout << " . 10, 50, 100, 500, 1000 : ";
cin >> _temp_money;
if(_temp_money == 10 || _temp_money == 50 || _temp_money == 100 || _temp_money == 500 || _temp_money == 1000)
_money = _money + _temp_money;
else
cout << "10, 50, 100, 500, 1000 . \n";
cout << _money << " \n";
}
//
void VendingMachine::buy()
{
cout << "\t\t격\t\n";
cout << "------------------------------------\n";
for(int i = 0 ; i < _max_num ; i++)
cout << i + 1 << "." << s_drink[i].name << "\t\t" << s_drink[i].price << "\t" << s_drink[i].amount << "\n";
cout << "\n " << _money << " \n";
cout << " : ";
cin >> _select_drink;
if((_money - s_drink[_select_drink - 1].price) >= 0 && s_drink[_select_drink - 1].amount >= 1)
{
s_drink[_select_drink - 1].amount--;
_money = _money - s_drink[_select_drink - 1].price;
}
else
cout << " 거 \n";
cout << _money << " \n";
}
// 거
void VendingMachine::takeBack_money()
{
cout << "거" << _money << " \n";
_money = 0;
}
//
void VendingMachine::insertDrink()
{
for(int i = 0 ; i < _max_num ; i++)
cout << i + 1 << "." << s_drink[i].name << "\t" << s_drink[i].amount << "\n";
cout << "길 : ";
cin >> _select_drink;
cout << "길 : ";
cin >> _insert_amount;
s_drink[_select_drink - 1].amount += _insert_amount;
cout << " \n";
for(i = 0 ; i < _max_num ; i++)
cout << i + 1 << "." << s_drink[i].name << "\t" << s_drink[i].amount << "\n";
}
int main()
{
VendingMachine VendingMachine;
int choice = VendingMachine.showMenu();
while(choice != 0)
{
if( choice >= 0 || choice <= 4)
{
switch(choice)
{
case 1:
VendingMachine.get_money();
break;
case 2:
VendingMachine.buy();
break;
case 3:
VendingMachine.takeBack_money();
break;
case 4:
VendingMachine.insertDrink();
break;
case 0:
cout << "기 !!\n\n";
break;
}
}
else
cout << " . : ";
choice = VendingMachine.showMenu();
}
return 0;
}
경 간 기 ,
- 기 . - public 'how' 'what' 겁. ' ' , 고 게 ' ' 겠.
- - , , 고 . Copy & Paste 과 / 겠.
- 기 , . --1002
- 고 --










