More actions
imported>Unknown No edit summary |
(Repair batch-0001 pages from live compare) |
||
| Line 10: | Line 10: | ||
private: | private: | ||
int m_money; | int m_money; | ||
char m_beverage | char m_beverage[3][10]; | ||
int m_price | int m_price[3]; | ||
int m_quantity | int m_quantity[3]; | ||
public: | public: | ||
Vending(); | Vending(); | ||
| Line 33: | Line 33: | ||
{ | { | ||
m_money = 0; | m_money = 0; | ||
strcpy(m_beverage | strcpy(m_beverage[0],"사이다"); | ||
strcpy(m_beverage | strcpy(m_beverage[1],"콜라"); | ||
strcpy(m_beverage | strcpy(m_beverage[2],"2%"); | ||
m_price | m_price[0] = 500; | ||
m_price | m_price[1] = 400; | ||
m_price | m_price[2] = 600; | ||
m_quantity | m_quantity[0] = 10; | ||
m_quantity | m_quantity[1] = 10; | ||
m_quantity | m_quantity[2] = 10; | ||
} | } | ||
| Line 80: | Line 80: | ||
int choice; | int choice; | ||
cout << "메뉴\n"; | cout << "메뉴\n"; | ||
cout << "1. " << m_beverage | cout << "1. " << m_beverage[0] << " " << m_price[0] << "원 " << m_quantity[0] << "개\n"; | ||
cout << "2. " << m_beverage | cout << "2. " << m_beverage[1] << " " << m_price[1] << "원 " << m_quantity[1] << "개\n"; | ||
cout << "3. " << m_beverage | cout << "3. " << m_beverage[2] << " " << m_price[2] << "원 " << m_quantity[2] << "개\n"; | ||
cout << "음료수를 고르세요 >> "; | cout << "음료수를 고르세요 >> "; | ||
cin >> choice; | cin >> choice; | ||
if(choice >0 && choice <4 && m_quantity | if(choice >0 && choice <4 && m_quantity[choice-1]>0 && ((m_money-m_price[choice-1])>0)) | ||
{ | { | ||
cout << m_beverage | cout << m_beverage[choice-1] << "을 사셨습니다\n"; | ||
switch(choice) | switch(choice) | ||
{ | { | ||
case 1: | case 1: | ||
m_money -= m_price | m_money -= m_price[0]; | ||
m_quantity | m_quantity[0]--; | ||
break; | break; | ||
case 2: | case 2: | ||
m_money -= m_price | m_money -= m_price[1]; | ||
m_quantity | m_quantity[1]--; | ||
break; | break; | ||
case 3: | case 3: | ||
m_money -= m_price | m_money -= m_price[2]; | ||
m_quantity | m_quantity[2]--; | ||
break; | break; | ||
} | } | ||
| Line 112: | Line 112: | ||
int choice; | int choice; | ||
cout << "메뉴\n"; | cout << "메뉴\n"; | ||
cout << "1. " << m_beverage | cout << "1. " << m_beverage[0] << " " << m_quantity[0] << "개\n"; | ||
cout << "2. " << m_beverage | cout << "2. " << m_beverage[1] << " " << m_quantity[1] << "개\n"; | ||
cout << "3. " << m_beverage | cout << "3. " << m_beverage[2] << " " << m_quantity[2] << "개\n"; | ||
cout << "음료수를 고르세요 >> "; | cout << "음료수를 고르세요 >> "; | ||
cin >> choice; | cin >> choice; | ||
| Line 120: | Line 120: | ||
{ | { | ||
int quantity; | int quantity; | ||
cout << m_beverage | cout << m_beverage[choice-1] << "을 고르셨습니다\n"; | ||
cout << "체울 양을 입력해주세요 >> "; | cout << "체울 양을 입력해주세요 >> "; | ||
cin >> quantity; | cin >> quantity; | ||
| Line 126: | Line 126: | ||
{ | { | ||
case 1: | case 1: | ||
m_quantity | m_quantity[0] += quantity; | ||
break; | break; | ||
case 2: | case 2: | ||
m_quantity | m_quantity[1] += quantity; | ||
break; | break; | ||
case 3: | case 3: | ||
m_quantity | m_quantity[2] += quantity; | ||
break; | break; | ||
} | } | ||
| Line 174: | Line 174: | ||
return 0; | return 0; | ||
} | } | ||
Latest revision as of 23:56, 26 March 2026
DeleteMe) 누구소스인지는 모르겠지만, 다른 소스들처럼 page name 을 바꿔주는것이 좋을듯. --1002
자판기
vending.h
#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
#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
#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;
}