1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #include <iostream> #include <string> #include <cstdlib> #include <ctime> using namespace std; class Player { string name; public: void setName(string name) { this->name = name; } string getName() { return name; } }; class GamblingGame { Player *p; public: GamblingGame() { p = new Player[2]; srand((unsigned)time(0)); } ~GamblingGame() { delete[]p; } void playgame(); }; void GamblingGame::playgame() { cout << "***** 갬블링 게임을 시작합니다. *****" << endl; string name; int index = 0; int number[3]; cout << "첫번째 선수 이름>>"; cin >> name; p[0].setName(name); cout << "두번째 선수 이름>>"; cin >> name; p[1].setName(name); cin.ignore(); // 버퍼 비우기 while (1) { if (index == 2) index = 0; cout << p[index].getName() << ":<Enter>"; getline(cin, name); cout << "\t\t"; for (int i = 0; i < 3; i++) { number[i] = rand() % 3; cout << number[i] << "\t"; } if (number[0] == number[1] && number[1] == number[2]) { cout << p[index].getName() << "님 승리!!" << endl; break; } else { cout << "아쉽군요!" << endl; index++; } } } int main() { GamblingGame user; user.playgame(); } | cs |
'Programming > 명품 C++ Programming' 카테고리의 다른 글
| 명품 C++ Programming 5장 OpenChallenge (0) | 2018.05.09 |
|---|---|
| 명품 C++ Programming 실습문제 4장 11번 응용 (0) | 2018.05.08 |
| 명품 C++ Programming 실습문제 4장 10번 (0) | 2018.05.06 |
| 명품 C++ Programming 실습문제 4장 9번 (0) | 2018.05.06 |
| 명품 C++ Programming 실습문제 4장 8번 (0) | 2018.05.06 |