Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- class Animals{
- public:
- //Overloaded Constructor:
- Animals(string);
- string getName();
- private:
- //Member Variables:
- string newName;
- };
- Animals::Animals(string name){
- newName = name;
- }
- string Animals::getName(){
- return newName;
- }
- class Zoo{
- public:
- //Overloaded Constructor:
- Zoo(int spaces);
- void AddAnimal(Animals);
- void displayZoo();
- private:
- //Member Variables:
- vector<Animals> newZoo;
- };
- Zoo::Zoo(int spaces){
- newZoo.reserve(spaces);
- }
- void Zoo::AddAnimal(Animals newAni){
- newZoo.push_back(newAni);
- }
- void Zoo::displayZoo(){
- int aniCount = 0;
- for(vector<Animals>::iterator iter = newZoo.begin(); iter != newZoo.end(); ++iter){
- aniCount++;
- cout << "Animal #" << aniCount << ": " << iter->getName() << "\n";
- }
- }
- int main(){
- int zSize;
- cout << "Enter Number of Animals: ";
- cin >> zSize;
- Zoo myZoo(zSize);
- for(int i = 0; i < zSize; i++){
- string uInput;
- cout << "Enter Animal " << i + 1 << ": ";
- cin >> uInput;
- Animals myAni(uInput);
- myZoo.AddAnimal(myAni);
- }
- myZoo.displayZoo();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement