[Solved]Question 1 Implement Following Three Classes Class Animal Attributes Age Integer Private A Q37083670
Question 1
Implement the following three classes:
Class Animal:
Attributes:
Age, an integer (private) The age of the animal
Weight, a float (protected) The weight of the animal
Behaviors: (public)
Animal() default constructor sets age=0, and weight=0.0
setAge() Takes an integer parameter, returns nothing
setWeight() Takes a float parameter, returns nothing
getAge() Takes no parameters, returns the Animal’s age
getWeight() Takes no parameters, returns the Animal’s weight
End Class Animal
Class Cat: (It is a derived class fromAnimal)
Attributes:
An object of type Cat has all the attributes of an
object of type Animal
Additionally, Cats have attributes that Animals do not:
Legs, an integer (private)
Behaviors:
An object of type Cat has all the behaviors of an object of
type Animal
Additionally, Cats have behaviors that Animals do not:
Cat() default constructor sets Legs=4
setLegs() Takes an integer parameter, returns nothing
getLegs() Takes no parameters, returns the cat’s number oflegs
getWeight2() Takes no parameters, returns the cat’s weight
End Cat class
Class Snake: (It is a derived class fromAnimal)
Attributes:
An object of type Snake has all the attributes of an
object of type Animal
Additionally, Snakes have attributes that Animals do not:
IsPoisonous, a boolean (private) yes or no
Behaviors:
An object of type Snake has all the behaviors of an objectof
type Animal
Additionally, Snakes have behaviors that Animals do not:
Snake() default constructor sets IsPoisonous=false
setIsPoisonous() Takes a boolean parameter, returns nothing
getIsPoisonous() Takes no parameters, returns the Snake’sIsPoisonous status
getAge2() Takes no parameters, returns the Snake’s age
End Snake Class
It would be a horrible waste of valuable programming time toredefine all of the functions in Cat or Snake when many of them arealready defined. This assignment is to reinforce the application ofinheritance.
For the testing, write the following test code in your main( ):
Animal x;
cout << “Initial value for x: “ << endl;
cout << “Age = “ << x.getAge() << “ Weight= “<< x.getWeight() << endl;
x.setAge(10);
x.setWeight(20);
cout << “Modified value for x: “ << endl;
cout << “Age = “ << x.getAge() << “ Weight= “<< x.getWeight() << endl;
Cat y;
cout << “Initial value for y: “ << endl;
cout << “Age = “ << y.getAge() << “ Weight= “<< y.getWeight() << endl;
y.setAge(12);
y.setWeight(17);
cout << “Modified value for y: “ << endl;
cout << “Age = “ << y.getAge() << “ Weight= “<< y.getWeight() << “ Weight2=” << y.getWeight2()<< endl;
Snake z;
cout << “Initial value for z: “ << endl;
cout << “Age = “ << z.getAge() << “ Weight= “<< z.getWeight() << endl;
z.setAge(14);
z.setWeight(23);
cout << “Modified value for z: “ << endl;
cout << “Age = “ << z.getAge() << “ Weight= “<< z.getWeight() << “ Age2=” << z.getAge2()<< endl;
Display the results in tabular format (one is already done foryou) as follows:
Value used for test, and what function(s)
Reason for Test
Expected Result
Actual Result
setAge( 15 )
To ensure that the age is setting the value properly, and thatgetAge( ) is returning
After setAge(15) is called, getAge() should return15.
After using cout<< on the member function getAge(), 15 wasprinted.
Expert Answer
Answer to Question 1 Implement the following three classes: Class Animal: Attributes: Age, an integer (private) The age of the ani… . . .
OR

