로그램 ¶
래 나기 ¶
담기 ¶
- 먼 기 보..... 기는 먼 메뉴를 람게 보 될꺼...
- 그리고 람 메뉴를 보고 각 메뉴 맞 명령 내릴 것고...
- 료가 뭐가 까?
먼 (목,가격,량) 기고 람게 보 겠...
그리고 람 문 때 문 가격 는 것 구..... / 기
또 문 남는 될꺼!!^^
두가 만 때는 문 내 겠고, 때 량 겠!^^
- .. 그리고 기 볼까? 녀 먼 기 보 것고..
람 맞는(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; }
만들고나.. ¶
- 래를 무 많 만들 괜 복다는 동 다.
래 법 대로 모르는라 기 고.. 결론 공부 것 많다는 것...^^
- 까는 만 대 구는 말두는 게 것 같다...^^
배는 게 많록 드가 복 나는 못 볼 모르는 각 드는군..^^
- 로그램 를 글로 만 로 보고 기..^^
(그럼 공부 나 더 늘나는가...^^)
래 가 많 복 닌듯(모 VendingMachine 경 Requirement 변경 따라 래갯가 10개 되기 ; 래 가 다기보다 료된 가 나 명료느냐가 복를 결리라 각). 단, 담때 각 래 명료 경 는것 겠다. CoinCounter 경 VendingMachine 멤로 듯. CRC 때 래들 각각 따로 는 것 같만, 론 그 래들 로를 고 기 든. 또는 당 기능 구기 다른 래들과 동기 고 (Collaboration. 구 다른 래 메드들 구다던 ). 담 고 난 다 모 나리를 만든뒤 딩나갔다면 떠까 는 각 본다. 경는 UnitTest 를 는게 겠. UnitTest & 대 ScheduledWalk/ 반부랑 UnitTest .--1002
see also FifteenSecondsRule
----
CppStudy_2002_2 VendingMachine