-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHobbit.cpp
More file actions
78 lines (70 loc) · 1.65 KB
/
Hobbit.cpp
File metadata and controls
78 lines (70 loc) · 1.65 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/***********************************************************************
* Program:
* Hobbit
* Author:
* Bryce Maughan
* Summary:
* Demonstrate OOP in C++
************************************************************************/
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
/**********************************************************************
* This is a class
*
***********************************************************************/
class Hobbit{
public:
int strength = 10;
int eatAgain = 4;
void walk();
void sleep();
void eat();
void display();
};
void Hobbit::walk(){
if (eatAgain <= 0){
cout << "Need to Eat!\n";
} else {
strength -= 1;
eatAgain -= 1;
}
}
void Hobbit::sleep(){
if (eatAgain <= 0){
cout << "Need to Eat!\n";
} else {
strength += 1;
eatAgain -= 1;
}
}
void Hobbit::eat(){
strength += 2;
eatAgain = 4;
}
void Hobbit::display(){
cout << "Hobbit Strength: " << strength << " Eat Again: " << eatAgain << endl;
}
/**********************************************************************
* MAIN
*
***********************************************************************/
int main(){
Hobbit frodo;
char choice = '.';
while(choice != 'q'){
frodo.display();
cout << "(w)alk (s)leep (e)at (q)uit >\n";
cin >> choice;
if(choice == 'w'){
frodo.walk();
} else if(choice == 's'){
frodo.sleep();
} else if(choice == 'e'){
frodo.eat();
}
cout << "\n";
}
return 0;
}