Question
#include #include #include using namespace std; class Animal { private: string name; string sound; public: Animal(const string n=,const string s=); string getName() const; string makeSound()
#include
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); };
Animal::Animal(const string n,const string s) { 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; }
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; };
Exhibit::Exhibit(int maxEnt) { MaxNumberOfAnimals=maxEnt; CurrentNumberOfAnimals=0; entries=new Animal[maxEnt]; }
Exhibit::~Exhibit() {
} void Exhibit::add(const Animal& a){
if(CurrentNumberOfAnimals os << s; return os; } int main() { Animal* monkey = new Animal("Max","Eeeeep"); Animal* tiger = new Animal("Jack","Roar"); Animal* Dog = new Animal("Petals","Woof"); cout<<*monkey< //cage.removeLast(); cout< //cage.removeLast(); cout < how would i edit this code to produce this output using void removeLast() function in the Exhibit class (I have provided what needs to be in the code in the comments): Frank says Squeak Simba says Chuff Petels says Woof { Frank Simba Batty Hippopotamusesy Turkey } { Frank Simba Batty Hippopotamusesy } { Frank Simba Batty }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started