14 Give a definition for a class SmartBut that is a derived class of the base cl
ID: 3912782 • Letter: 1
Question
14 Give a definition for a class SmartBut that is a derived class of the base class Smart given in the following. Do not bother with # include directives or namespace details. class Smart public: Smart void printAnswer() const protected: int ai int b; This class should have an additional data field, crazy, of type bool; one additional member function that takes no arguments and returns a value of type bool; and suitable constructors. The new function is named iscrazy. You do not need to give any implementations, just the class definition.Explanation / Answer
Answer: Definition of class SmartBut is given below:
// We have inherited publicly because it is commonly used and it is also not mentioned in question.
// If you want to inherit privately or in protected manner just change the public to private or protected.
class SmartBut : public Smart
{ public:
SmartBut(); // Constructor is declared as public with no return type and same name as class's // name.
// Below is the isCrazy() function returning the bool value crazy. It is also declared as public because it // is not mentioned where to declare it and it is common to declare functions as public.
bool isCrazy()
{
return crazy;
}
protected:
bool crazy; // This is the crazy variable declared as protected. You may change it to public or // protected.
}; // End class definition with a semi colon.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.