forked from R3DHULK/cpp-for-gamers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwild-life-park-simulator.cpp
129 lines (114 loc) · 2.88 KB
/
wild-life-park-simulator.cpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// Animal class
class Animal
{
public:
Animal(string name, string species, int age, bool isMale)
{
this->name = name;
this->species = species;
this->age = age;
this->isMale = isMale;
}
string getName()
{
return name;
}
string getSpecies()
{
return species;
}
int getAge()
{
return age;
}
bool getIsMale()
{
return isMale;
}
private:
string name;
string species;
int age;
bool isMale;
};
// Park class
class Park
{
public:
Park()
{
// Initialize the list of animals
animals.push_back(Animal("Simba", "Lion", 5, true));
animals.push_back(Animal("Nala", "Lion", 4, false));
animals.push_back(Animal("Mufasa", "Lion", 12, true));
animals.push_back(Animal("Timon", "Meerkat", 2, true));
animals.push_back(Animal("Pumbaa", "Warthog", 6, false));
}
void listAnimals()
{
// Display the list of animals in the park
cout << "List of animals:" << endl;
for (int i = 0; i < animals.size(); i++)
{
cout << i + 1 << ". " << animals[i].getName() << " - " << animals[i].getSpecies() << " (" << animals[i].getAge() << " years old, " << (animals[i].getIsMale() ? "male" : "female") << ")" << endl;
}
cout << endl;
}
void addAnimal(string name, string species, int age, bool isMale)
{
// Add a new animal to the park
animals.push_back(Animal(name, species, age, isMale));
cout << "New animal added!" << endl;
listAnimals();
}
private:
vector<Animal> animals;
};
int main()
{
// Create a new park
Park park;
// Main game loop
while (true)
{
// Display options and prompt for choice
cout << "Choose an option:" << endl;
cout << "1. List animals" << endl;
cout << "2. Add animal" << endl;
cout << "3. Exit" << endl;
int choice;
cin >> choice;
// Handle choice
if (choice == 1)
{
park.listAnimals();
}
else if (choice == 2)
{
// Prompt for animal details
string name, species;
int age;
bool isMale;
cout << "Enter the name of the animal: ";
cin >> name;
cout << "Enter the species of the animal: ";
cin >> species;
cout << "Enter the age of the animal: ";
cin >> age;
cout << "Is the animal male? (y/n): ";
char maleChoice;
cin >> maleChoice;
isMale = (maleChoice == 'y' || maleChoice == 'Y');
park.addAnimal(name, species, age, isMale);
}
else if (choice == 3)
{
break;
}
}
return 0;
}