Derive the cube class from the base square class. Assume the square class has a
ID: 3624916 • Letter: D
Question
Derive the cube class from the base square class. Assume the square class has a protected member variable representing the side called side and declared as a double with a default value of 1.0. It also has a public function called calcVal that evaluates the area of a square as side * side. In your derived class have the default values for side be 1. For the cube class include a public function calcVal that evaluates the volume of the cube. (Hint: The volume of the cube is side * square ::calcVal.)Explanation / Answer
hi there here is the program u want PLEASE RATE #include using namespace std; class square { protected: double side; double clalcVal() { return side*side; } square(double n=1)//THE DEFUALT VALUE IS ONE IF NOTHING CAME TO IT IT WILL BE 1 { side=n; } }; class cube:public square { public: double clalcVal() { return (side * square::clalcVal());//HERE WILL CALL THE clalcVal OF SQUARE AND MULTIPLY IT WITH THE SIDE VALUE } cube(double N=1) : square( N )//WE MADE THE CONSTRUCTOR HERE TO GO TO THE DEFUALT IN SQUARE CLASS { } }; void main() { cube obj(3); coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.