Explore BrainMass
Share

C++ Square and Cube classes

This content was STOLEN from BrainMass.com - View the original, and get the solution, here!

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.)

© BrainMass Inc. brainmass.com September 25, 2018, 11:06 am ad1c9bdddf - https://brainmass.com/computer-science/cpp/c-square-and-cube-classes-569148

Solution Preview

Attached solution 569148.cpp creates a base class Square, and derives class Cube from it as per the given specifications. It also ...

Solution Summary

Solution creates a base class 'Square' with protected member 'side'. It then derives class 'Cube' from it that makes use of 'side' from parent class, and also overrides 'calcVal' method of the parent class.

$2.19