DeleteMe) 누구소스ì�¸ì§€ëŠ” ëª¨ë¥´ê² ì§€ë§Œ, 다른 소스들처럼 page name ì�„ 바꿔주는것ì�´ 좋ì�„듯. --1002
ìž�íŒ�기 ¶
vending.h ¶
~cpp
#ifndef _VENDING_H_
#define _VENDING_H_
class Vending
{
private:
int m_money;
char m_beverage[3][10];
int m_price[3];
int m_quantity[3];
public:
Vending();
void insertCoin();
void extortCoin();
void mainMenu();
void buyBeverage();
void update();
};
#endif
vending.cpp ¶
~cpp
#include <iostream>
#include <cstring>
using namespace std;
#include "vending.h"
Vending::Vending()
{
m_money = 0;
strcpy(m_beverage[0],"사�다");
strcpy(m_beverage[1],"콜�");
strcpy(m_beverage[2],"2%");
m_price[0] = 500;
m_price[1] = 400;
m_price[2] = 600;
m_quantity[0] = 10;
m_quantity[1] = 10;
m_quantity[2] = 10;
}
void Vending::insertCoin()
{
int money;
cout << "�� 넣으세요\n";
cout << "10,50,100,500,1000�만 가능\n";
cout << ">> ";
cin >> money;
if(money==10 || money==50 || money==100 || money==500 || money ==1000)
{
m_money += money;
}
else
cout << "ì œëŒ€ë¡œ ë�œ ë�™ì „ì�´ë‚˜ ì§€í��를 넣어 주세요!\n";
}
void Vending::extortCoin()
{
m_money = 0;
}
void Vending::mainMenu()
{
cout << "메�메뉴\n";
cout << "1. � 넣기\n";
cout << "2. 사기\n";
cout << "3. � 빼기\n";
cout << "4. 종료\n";
cout << "5. �료수 체우기\n";
cout << "남� �: " << m_money << "\n";
cout << ">> ";
}
void Vending::buyBeverage()
{
int choice;
cout << "메뉴\n";
cout << "1. " << m_beverage[0] << " " << m_price[0] << "� " << m_quantity[0] << "개\n";
cout << "2. " << m_beverage[1] << " " << m_price[1] << "� " << m_quantity[1] << "개\n";
cout << "3. " << m_beverage[2] << " " << m_price[2] << "� " << m_quantity[2] << "개\n";
cout << "ì�Œë£Œìˆ˜ë¥¼ ê³ ë¥´ì„¸ìš” >> ";
cin >> choice;
if(choice >0 && choice <4 && m_quantity[choice-1]>0 && ((m_money-m_price[choice-1])>0))
{
cout << m_beverage[choice-1] << "� 사셨습니다\n";
switch(choice)
{
case 1:
m_money -= m_price[0];
m_quantity[0]--;
break;
case 2:
m_money -= m_price[1];
m_quantity[1]--;
break;
case 3:
m_money -= m_price[2];
m_quantity[2]--;
break;
}
}
else
cout << "다시 ì„ íƒ� 해주세요\n";
}
void Vending::update()
{
int choice;
cout << "메뉴\n";
cout << "1. " << m_beverage[0] << " " << m_quantity[0] << "개\n";
cout << "2. " << m_beverage[1] << " " << m_quantity[1] << "개\n";
cout << "3. " << m_beverage[2] << " " << m_quantity[2] << "개\n";
cout << "ì�Œë£Œìˆ˜ë¥¼ ê³ ë¥´ì„¸ìš” >> ";
cin >> choice;
if(choice >0 && choice <4)
{
int quantity;
cout << m_beverage[choice-1] << "ì�„ ê³ ë¥´ì…¨ìŠµë‹ˆë‹¤\n";
cout << "체울 ì–‘ì�„ ìž…ë ¥í•´ì£¼ì„¸ìš” >> ";
cin >> quantity;
switch(choice)
{
case 1:
m_quantity[0] += quantity;
break;
case 2:
m_quantity[1] += quantity;
break;
case 3:
m_quantity[2] += quantity;
break;
}
}
else
cout << "다시 ì„ íƒ� 해주세요\n";
}
useVending.cpp ¶
~cpp
#include <iostream>
#include "vending.h"
using namespace std;
int main()
{
int choice;
Vending vending;
vending.mainMenu();
cin >> choice;
while(choice != 4)
{
switch(choice)
{
case 1:
vending.insertCoin();
break;
case 2:
vending.buyBeverage();
break;
case 3:
vending.extortCoin();
break;
case 5:
vending.update();
break;
}
vending.mainMenu();
cin >> choice;
};
return 0;
}










