¶
~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
- 대 보 -- 동