Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use C++ please: Instructions: Download given code on Canvas. Create a new project and out all files into their supposed folders. Read and understand the

Use C++ please:

Instructions: Download given code on Canvas. Create a new project and out all files into their supposed folders. Read and understand the given code. The classes and dependencies are shown in the included class diagram. There is a base class called Animal. A horse is an animal. Horse is derived from Animal. This relationship is inheritance. A bird is an animal. Bird is derived from Animal. This relationship is also inheritance. A Zoo has an animal (or several). In other words, the classes Horse and Bird are members of the Zoo class. This relationship is composition. Part One: Inheritance Please complete the following TODO tasks to implement the Animal base class, the Horse derived class, and the Bird derived class. It might look like a lot, but many of the functions are just getters and setters. Animal.cpp

Animal::Animal() { // TODO: Use the setData function to set the member variable name // to "no-name", the member variable age to 0, and the member variable // weight to 0. }

Animal::Animal(string n, int a, int w) { // TODO: Use the setData function to set the member variables // according their corresponding parameters. }

void Animal::setData(string n, int a, int w) { // TODO: Use the setName, setAge, and setWeight functions to set // the member variables according to their corresponding parameters. }

void Animal::setName(string n) { // TODO: Set the member variable name according to the parameter. }

void Animal::setAge(int a) { // TODO: Provided that the parameter value is >= 0, set the member // variable age according to the parameter. Otherwise, set the // member variable age to 0. }

void Animal::setWeight(int w) { // TODO: Provided that the parameter value is >= 0, set the member // variable weight according to the parameter. Otherwise, set the // member variable weight to 0. }

string Animal::getName() const { // TODO: Return the member variable name. }

int Animal::getAge() const { // TODO: Return the member variable age. }

int Animal::getWeight() const { // TODO: Return the member variable weight. }

void Animal::printRecord() const { // TODO: Output the name, age, and weight. }

bool Animal::isOlder(const Animal &first, const Animal &second) { // TODO: Return true if first object passed in the parameter // has a greater age than the second object passed in the parameter. // Otherwise, false is returned. }

Horse.cpp

Horse::Horse() { // TODO: Use the setColor function to set this derived class member // variable color to "no-color". The base class content will be // initialized according to the base class's default constructor. }

Horse::Horse (string n, int a, int w, string b) // TODO: Before the opening brace, use the syntax from the example slides // to construct the base class using the base class parameterized // constructor. Pass the base class content (name, age and weight) // up to the base class. { // After the opening brace, call the setColor function to set the one // derived class member variable color according to the corresponding // parameter. }

void Horse::setData(string n, int a, int w, string b) { // TODO: The base class and derived classes both have setData functions. // The derived class setData function overrides the base class one. However, // we can invoke the base class version of the function here if we scope to it. // Since the member variables name, age, and weight are stored // in the base class, use the base class's setData function to set those // values according to the corresponding parameters.

// Then use the setColor function to set the remaining derived class variable. }

void Horse::setColor(string b) { // TODO: Set the member variable name according to the parameter. }

string Horse::getColor() const { // TODO: Return the member variable color. }

void Horse::printRecord() const { // TODO: The base class and derived classes both have printRecord functions. // The derived class printRecord function overrides the base class one. However, // we can invoke the base class version of the function here if we scope to it. // Since the member variables name, age, and weight are stored // in the base class, use the base class's printRecord function output those // base class values.

// Then output the derived class member variable directly. }

Bird.cpp

Bird::Bird() { // TODO: Use the setWingspan function to set this derived class member // variable wingSpan to 0.0. The base class content will be // initialized according to the base class's default constructor. }

Bird:: Bird (string n, int a, int w, double ws) // TODO: Before the opening brace, use the syntax from the example slides // to construct the base class using the base class parameterized // constructor. Pass the base class content (name, age and weight) // up to the base class. { // After the opening brace, call the setWingspan function to set the one // derived class member variable wingSpan according to the corresponding // parameter. }

void Bird::setData(string n, int a, int w, double ws) { // TODO: The base class and derived classes both have setData functions. // The derived class setData function overrides the base class one. However, // we can invoke the base class version of the function here if we scope to it. // Since the member variables name, age, and weight are stored // in the base class, use the base class's setData function to set those // values according to the corresponding parameters.

// Then use the setWingspan function to set the remaining derived class variable.

image text in transcribed

}

void Bird::setWingspan(double ws) { // TODO: Provided that the parameter value is >= 0, set the member // variable wingSpan according to the parameter. Otherwise, set the // member variable wingSpan to 0.0. }

double Bird::getWingspan() const { // TODO: Return the member variable wingSpan. }

void Bird::printRecord() const { // TODO: The base class and derived classes both have printRecord functions. // The derived class printRecord function overrides the base class one. However, // we can invoke the base class version of the function here if we scope to it. // Since the member variables name, age, and weight are stored // in the base class, use the base class's printRecord function output those // base class values.

// Then output the derived class member variable directly. }

Part Two: Composition Please complete the following TODO tasks to implement the Zoo class, which is composed of an object of the Horse class and an object of the Bird class.

Zoo.cpp

Zoo::Zoo(const House &h, const Bird &b) { // TODO: Implement this parameterized constructor to set the member // objects horse and bird according to the objects passed in the // parameter. }

void Zoo::printZooData() const { // Output the information about the two animals at this zoo. // Output the information about the horse. Then output the // information about the bird.

// Using the isOlder function, also output information about // which of the two animals is heavier. }

Testing, Commenting, and Submission:

Write a client to test your own code. Sample output below.

Each function to be implemented is worth 4 points (100 points total).

For submission, upload your modified Animal.cpp file, your modified Horse.cpp file, your modified Bird.cpp file, your modified Zoo.cpp file, and test client.

Please test your code thoroughly. After submitting your files, please download and view them to ensure youve uploaded what you intended. Thank you.

Class Diagram: Derive Compose Part One: Inheritance Please complete the following TODO tasks to implement the Animal base class, the Horse derived class, and the Bird derived class. It might look like a lot, but many of the functions are just getters and setters. Animal.cpp Animal:: Animal() // TODO: Use the setData function to set the member variable name // to "no-name", the member variable age to e, and the member variable

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

Step: 3

blur-text-image

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

Beginning VB.NET Databases

Authors: Thearon Willis

1st Edition

1594864217, 978-1594864216

More Books

Students also viewed these Databases questions