Assignment#7: Inheritance & polymorphism: • In the given file Inheritance&polymorphism.cpp you will find: a. The shell of the base class Pet. b. The shell of the derived class Dog. c. The shell of the...

thanks


Assignment#7: Inheritance & polymorphism: • In the given file Inheritance&polymorphism.cpp you will find: a. The shell of the base class Pet. b. The shell of the derived class Dog. c. The shell of the derived class Rock. d. The main function shell. Complete the Inheritance&polymorphism.cpp such as: • The Pet class that stores the pet’s name, age, and weight. a. Implement default constructors that assigns to name “no name”, age 0 and to weight 0. b. Implement the three parameters constructor to initialize: name, age and weight c. Implement All necessary accessor functions, and mutator functions. d. Implement a display that will display the name, age and weight of the pet in different lines. e. Implement the virtual function named getLifespan that returns a string with the value “unknown lifespan.” (You can leave this question until learning polymorphism) • The Dog class that is derived from Pet. a. The Dog class should have a private member variable named breed that stores the breed of the dog. b. Implement the default constructors (calls base class constructor with three parameters) c. Implement the four parameters constructor (calls base class constructor with three parameters). d. Implement a mutator and an accessor functions for the breed variable and appropriate constructors. e. Implement the function display of Pet class to display in addition to name, age and weight, Type: “Dog” and the breed value. f. Implement the getLifespan function to return “Approximately 7 years” if the dog’s weight is over 100 pounds and “Approximately 13 years” if the dog's weight is under 100 pounds or equal.(You can leave this question until learning polymorphism). • The class Rock class that is derived from Pet: a. Implement the default constructors (calls base class default constructor) b. Implement the function display of Pet class to display in addition to name, age and weight the Type: “Rock”. c. Implement the getLifespan function to return “Thousands of years”.(You can leave this question until learning polymorphism). When run, your program should have a similar output to the following: #include #include using namespace std; class Pet{ // name; // age; // weight; public: Pet(); Pet(string n, int a, int w); void setName( string n); void setAge(int a); void setWeight(int w); string getName() ; int getAge() ; int getWeight() ; virtual string getLifespan(); //after learning polymorphism void display(); }; // end class Pet class Dog /* write code: Dog inherits from Pet*/ { // breed; public: Dog(); Dog(string n, int a, int w, string b); void setBreed(string b); string gerBreed(); string getLifespan(); //after learning polymorphism void display(); }; //end of Dog class class Rock /* write code: Rock inherits from Pet*/ { public: Rock(); string getLifespan(); //after learning polymorphism void display(); }; int main() { // inheritance cout<"--------------demonstration of="" the="" concept="" of=""><"\n--------------demonstration of="" the="" concept="" of=""><><":><><><":><><><":><>
Nov 13, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here