Write a program to create a (class) hierarchy of felines.The parent class is a feline that is represented as an abstract class named feline that has the properties (private members):• A name,...

1 answer below »



Write a program to create a (class) hierarchy of felines.



The parent class is a feline that is represented as an abstract class named feline that has the properties (private members):



• A name, represented by a string.



• An age, represented by an integer.



This feline has the interface:



• A constructor to set name to empty and age to 0.



• A constructor(sName, nAge) to set name to sName and age to nAge.



• A destructor to print “bye bye feline”.



• A member function name to return name.



• A member function age to return age.



• An assignment operator



• A copy constructor



• A pure virtual member function climb to compute and return a feline's climbing ability.



• A pure virtual member function print to print the information related to the feline.



A cat is a child class of a feline that is represented as a class named cat that has the properties:



• An owner, represented by a string.



This cat has the interface:



• A constructor to set owner to empty.



• A constructor(sName, nAge, sOwner), that uses the feline's constructor to set name to sName and age to nAge, and to set owner to sOwner.



• A destructor to print “bye bye cat”.



• A member function owner to return owner.



• A member function climb to compute and return a cat's climbing ability, where climbing ability is 1.75 times age plus the square root of age.



• A member function print to print name, age, owner, and climbing ability of the cat.



A tiger is a child of a feline that is represented as a class named tiger that has the properties:



• An enemy, represented by a string.



This tiger has the interface:



• A constructor to set enemy to empty.



• A constructor(sName, nAge, sEnemy), that uses the feline's constructor to set name



• to sName and age to nAge, and to set enemy to sEnemy.



• A destructor to print “bye bye tiger”.



• A member function enemy to return enemy.



• A member function climb to compute and return a tiger's climbing ability, where climbing ability is 3 times age minus 1.5.



• A member function print to print name, age, enemy, and climbing ability of the tiger.



Use a client program with the following instructions:



1. Declare a cat instance c, whose name, age, and owner are "Sylvester", 3, and "Elmer Fudd", respectively.



2. Declare a tiger instance t, whose name, age, and enemy are "Laney", 9, and "Jackal", respectively.



3. Print information of instance c.



4. Print information of instance t.



Section 2 [10 marks]



Use the classes defined in Section 1 so that the insertion operator < is="" able="" to="" print="" information="" of="" a="" feline.="" write="" a="" client="" program="" with="" the="" following="">



1. Declare a cat instance c, whose name, age, and owner are "Sylvester", 3, and "Elmer Fudd", respectively.



2. Declare a tiger instance t, whose name, age, and enemy are "Laney", 9, and "Jackal", respectively.



3. Print information of instance c using the overloaded insertion operator <>



4. Print information of instance t using the overloaded insertion operator <>



Section 3 [30 marks]



Write a client program that:



1. Asks for a number of cats from the console.



2. Dynamically allocates a sequence of cats and tigers by the number received from the console such that 2 cats for every tiger is created. For example, if 4 is given for the number of cats, then two tigers will be included, which results in 6 felines altogether.



3. Uses an automatic approach to set the data fields of the felines. For example, “C1”, 1, and “O1” (name, age, and owner) for data fields of the first cat and “C2”, 2, and “O2” for data fields of the second cat. Similarly, “T1”, 1, and “E1” (name, age, and enemy) for data fields of the first tiger and so on.



4. Places the cats at the two consecutive indices (0, 1, 3, 4, ...) and tigers at the indices following indices of cats (2, 5, 7, …).



5. Prints the information of all felines (cats and tigers).



Note: in addition to the specifications above, you may also need to add other data fields and (member) functions.
Answered 3 days AfterDec 05, 2022

Answer To: Write a program to create a (class) hierarchy of felines.The parent class is a feline that is...

Pratyush answered on Dec 05 2022
4 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here