answer in c++ You are given a segment of code in the previous question. The foll
ID: 3721325 • Letter: A
Question
answer in c++
You are given a segment of code in the previous question. The following questions are based on the same code, where the Cat class is as follows class Cat public Pet f public: string cBreed int iAge; Cat(string name, int phone, string email, string breed, int age) ··· //write the constructor Answer the following questions: (1) Define an overloading operator Cat>, which can compare two Cat objects to determine which cat is older. (2) Can the overloading operator Cat> be applied to two Pet objects? Explain your answer. [2 point] [3 points]Explanation / Answer
a) class Pet{
public : String petName;
}
class Cat:public Pet{
public: string cBreed;
int iAge;
Cat(string name,int phone,string email,string breed,int age)
{
}
Cat(string catname1,string catname2,int cat1age,int cat2age)
{
if(cat1age>cat2age)
cout<< catname1<<"is older."
else
cout<< catname2<<"is older."
}
int main()
{
Cat cat1;
cat1.iAge=5;
Cat cat2;
cat2.iAge=6;
cat1("Cat1","Cat2",cat1.iAge,cat2.iAge);
return 0;
}
b) No it cannot be applied to Pet objects .
Here Pet is a base class and it can access only its own constructors.
And Cat is an inherited class which implements the methods of Base class plus its own newly created methods and constructors .
But base class does not have access to newly created methods in inherited class.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.