U E D R , A S I H C RSS

Vending Machine/세연

~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
  • 가 대다 --




Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:21
Processing time 0.0181 sec