Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the main files done just need help with the following: Animal.h #pragma once #include #include #include using namespace std; class Animal { string

I have the main files done just need help with the following:

image text in transcribed

image text in transcribed

Animal.h

#pragma once #include #include #include

using namespace std;

class Animal { string name; int age;

public:

Animal() { cout

void display(const vector & list) {

}

string getName() { return name; }

void setName(string name) { this->name = name; }

int getAge() { return age; }

void setAge(int age) { this->age = age; }

~Animal() { cout

void feed() { cout

};

Dog.h

#ifndef LA4_Dog_h #define LA4_Dog_h

#include #include "Animal.h"

using namespace std;

class Dog : public Animal{ public: Dog(){ cout

#endif

display.h

#include "Animal.h" void display (const vector &list){ for (int i = 0; i getName() Suppose we wish to store several different animals in an array. We do not know ahead of time what animals they will be. C++ will allow us to create a vector of pointers to Animal, and store in that vector, any object of type Animal or a descendant of Animal. So, if we have a generic animal we can store it as a generic animal but if we have a dog we can store it as a dog. Reuse the Animal.h and Dog.h files from previous exercises and get the display.h file. Then write a C++ program that reads in an integer N. This is followed by N lines, where each line contains a character, a string and an integer, separated by space. The character will either have the value A or D, indicating whether the animal described on this line is a generic animal or a dog. The string indicates the animal's name and the integer, its age. For each line of input, instantiate the appropriate object and push it to the vector of pointers to Animal that you have created. Once you have pushed all the animals to the vector, call the display function, found in display.h, with your vector passed as an argument. For example, if input (marked as bold) is entered, you should see following Output: 2 A Snoopy 4 Creating Generic Animal D Bruno 5 Creating Generic Animal Creating Dog Snoopy Bruno

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago