클 ¶
할 하 ¶
- 판 할 ..... 판 ...
- 할...
- 해할 ?
태(품,,) 하 ...
했 품 해 한 확 하 하..... /
품 크해 !!^^
할 한 품 하, 품 해!^^
- 흠.. 할 한 ? 해 할 ..
투한 형 (10,50,100,500,1000) 확해 할 ,
환 하 화 할 하?^^
!! 한 해 할 !^^
¶
~cpp
#include <iostream>
#include <cstring>
using namespace std;
int selection, num;
class Man{
public:
void select(){
selection = 0;
while (selection < 1 || selection > num){
cout << ">> ";
cin >> selection;
if (selection < 1 || selection > num)
cout << " 하. n";
}
};
};
class CoinCounter{
public:
int remainders, coin;
void resetCoins(){
remainders = 0;
};
void showRemainders(){
cout << "REMAINDERS : " << remainders << endl;
};
void insertCoins(){
cout << " .n 1. 10 n 2. 50 n 3. 100 n 4. 500 n 5. 1000 n>> ";
cin >> coin;
if (coin == 1) coin = 10;
else if (coin == 2) coin = 50;
else if (coin == 3) coin = 100;
else if (coin == 4) coin = 500;
else if (coin == 5) coin = 1000;
else coin = 0;
remainders += coin;
cout << coin <<" . n " << remainders << ".n";
};
void pay(int used){
cout << used << " 하.n";
remainders -= used;
};
};
class VendingMachine{
public:
void showMenu(){
num = 4;
cout << "MAIN MENU n 1. INSERT COIN n 2. BUY n 3. RETURN THE REMAINDERS n 4. EXIT n";
};
};
class Drink{
public:
struct drinks{
char name[10];
int price;
int quantity;
};
drinks detail[3];
Drink(){
strcpy(detail[0].name, "");
strcpy(detail[1].name, "");
strcpy(detail[2].name, "2% ");
detail[0].price = 500;
detail[1].price = 400;
detail[2].price = 600;
for (int i = 0 ; i < 3 ; i++)
detail[i].quantity = 10;
};
void showDetails(){
num = 3;
cout << " 품t t n";
for (int i = 0 ; i < 3; i++)
cout << i+1 << ". " << detail[i].name << "t"
<< detail[i].price << "t"
<< detail[i].quantity << endl;
};
int buy(int remainders){
if (remainders >= detail[selection - 1].price && detail[selection - 1].quantity != 0){
cout << detail[selection - 1].name << " 택하.n";
detail[selection - 1].quantity--;
return detail[selection - 1].price;
}
else if (detail[selection - 1].price > remainders)
cout << " 합.n";
else if (detail[selection - 1].quantity == 0)
cout << ". 품 .n";
return 0;
};
};
int main(){
Man man;
CoinCounter coin_counter;
VendingMachine vending_machine;
Drink drink;
int usedmoney;
coin_counter.resetCoins();
while(selection != 4)
{
vending_machine.showMenu();
coin_counter.showRemainders();
man.select();
if (selection == 1)
coin_counter.insertCoins();
else if (selection == 2){
drink.showDetails();
man.select();
usedmoney = drink.buy(coin_counter.remainders);
coin_counter.pay(usedmoney);
}
else if (selection == 3){
cout << " 환합.n";
coin_counter.resetCoins();
}
else if (selection == 4)
break;
else cout << " 하.n";
system("pause");
system("cls");
};
return 0;
}
.. ¶
- 클 히 해 형 .
클 툴 하.. 해할 ...^^
- 했 해 ...^^
해 ..^^
- 한 했 해 ..^^
( 할 하 ...^^∂)
see also FifteenSecondsRule
----
CppStudy_2002_2 VendingMachine










