Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question In a popular business simulation video game, Zoo Tycoon, players create

ID: 3587985 • Letter: Q

Question

Question In a popular business simulation video game, Zoo Tycoon, players create a Zoo. This includes creating exhibits to display their favorite animals. The figure below shows an example of how different animals are put into different exhibits. In the game players can put animals in the same exhibit if the animals share similar resources for survival. For example, a zebra and gazelle can be put into the same exhibit since they both live in a savannah biome. In this lab you are required to create a class called Animal with the private fields called name and sound. The Animal class should ave the following definition: class Animalf private: string name;

Explanation / Answer

Here I provide answer of your q1 & q2.

save these files compile and run. Q3 you can try yourself as per the answer of Q1 & Q2

/**********************/

/*
* main.cpp
*
* Created on: 07-Oct-2017
*      Author:
*/
#include <iostream>
#include "Animal.h"
#include "Exhibit.h"
using namespace std;

int main()
{
   Animal* monkey = new Animal("Frank","Squeak");
   Animal* tiger = new Animal("Simba","Chuff");
   Animal* Dog = new Animal("Petals","Noof");
   cout<<*monkey<<endl;
   cout<<*tiger<<endl;
   cout<<*Dog<<endl;// upto this is your 1st question along with Animal.h & Animal.cpp
   Exhibit cage(10);
   cage.add(*monkey);
   cage.add(*tiger);
   cage.add(Animal("Batty","Screech"));
   cage.add(Animal("Hippopotamusesy","grewl"));
   cage.add(Animal("Turkey","Goobble"));
   cout<<cage<<endl;
   cout<<cage<<endl;
   return 0;
}

/**********************/

/*
* Animal.h
*
* Created on: 07-Oct-2017
*      Author:
*/
#include <string>

using namespace std;
#ifndef ANIMAL_H_
#define ANIMAL_H_

class Animal {
private:
   string name;
   string sound;
public:
   Animal(const string n="",const string s="");
   string getName() const;
   string makeSound() const;
   friend ostream& operator<< (ostream& os,const Animal& a);
};

#endif /* ANIMAL_H_ */

/****************************/

/*
* Animal.cpp
*
* Created on: 07-Oct-2017
*      Author:
*/

#include "Animal.h"

Animal::Animal(const string n,const string s) {
   // TODO Auto-generated constructor stub
   name=n;
   sound=s;
}

string Animal::getName() const{
   return name;
}

string Animal::makeSound() const{
   return sound;
}

ostream& operator<<(ostream& os,const Animal& a){
   string s=a.name+" says "+a.sound;
   os << s;
   return os;
}

/********************************/

/*
* Exhibit.h
*
* Created on: 07-Oct-2017
*      Author:
*/
#include <string>
#include "Animal.h"
using namespace std;
#ifndef EXHIBIT_H_
#define EXHIBIT_H_

class Exhibit {
public:
   Exhibit(int maxEnt = 10);
   ~Exhibit();
   void add(const Animal& a);
   Animal& operator[](size_t i) {return entries[i];}
   friend ostream& operator<<(ostream& out,const Exhibit& obj);
private:
   int MaxNumberOfAnimals;
   int CurrentNumberOfAnimals;
   Animal* entries;
};

#endif /* EXHIBIT_H_ */

/****************************/

/*
* Exhibit.cpp
*
* Created on: 07-Oct-2017
*      Author:
*/

#include "Exhibit.h"
#include <stdlib.h>
Exhibit::Exhibit(int maxEnt) {
   // TODO Auto-generated constructor stub
   MaxNumberOfAnimals=maxEnt;
   CurrentNumberOfAnimals=0;
   entries= NULL;
}

Exhibit::~Exhibit() {
   // TODO Auto-generated destructor stub
}
void Exhibit::add(const Animal& a){

   if(CurrentNumberOfAnimals<MaxNumberOfAnimals)
   {
       entries=(Animal*)&a;
       CurrentNumberOfAnimals++;
       entries++;
   }
}
ostream& operator<<(ostream& os,const Exhibit& a){
   string s="{";
   for(int i=0;i<a.CurrentNumberOfAnimals;i++)
   {
       s=s+a.entries[i].getName();
   }
   s=s+"}";

   os << s;
   return os;
}

/****************************/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote