Question: Shape Inheritance (member functions) - from Shape Base Classes Complete the exercise project ShapeInheritance. Finish the project by adding the modules described in the ShapeInheritance-Square

 Shape Inheritance (member functions) - from Shape Base Classes Complete theexercise project ShapeInheritance. Finish the project by adding the modules described in

Shape Inheritance (member functions) - from Shape Base Classes Complete the exercise project ShapeInheritance. Finish the project by adding the modules described in the ShapeInheritance-Square Exercise. Exercise the new Square class in the Shapelnheritance.cpp module: Change the project folder name to Assign06-ShapeInheritance Define const PI in Circle.h const double PI 3.1416 Add public member function prototypes to both Rect.h and Circle.h header files. Make them const functions that return calculated values of type double. double getArea( double getPerimeter const; Add these member functions to both Circle.h and Rect.h header files. Do not add to Square.h class definition. const; Implement these two methods as const functions in both the Circle.cpp and the Rect.cpp source files Rect double getArea() Rect double getPerimeter() Circle double getArea() Circle double getPerimeter() const const const const return width height return 2 (width + height) return .radius2 return . 2 . radius The Square class inherits getArea() and getPerimeter) functions from the Rect class. The getPerimeter() and getArea() operations that Square inherits from Rect use both length and height values from Rect for these calculations. The class constructor for Square shows inheritance from Rect and invokes the Rect constructor, setting both length and height to the current value of the Square side. Square::Square(int newX, int newY, int length) Rect (newx, newY, length, length) Square side length used to set both Rect width and height setSide(length); When the current side value of a Square object is changed by Square.setSide(n), further coding is required to make a corresponding change in Rect base class data member values. Otherwise, underlying Rect values used to calculate area and perimeter for a Square object will be wrong and lead to an incorrect result. void Square::setSide(int newLength) side = newLength; // change width in Rect base class I/ change height in Rect base class Rect::setWidth(newLength); Rect::setHeight(newLength); Modify the display) routine for each of the derived Shape classes (Rect, Circle, and Square) and configure output lines to fit all information across the output window. Show calculated area and perimeter values for each of these shapes For consistent formatting, these double values will require an extra statement at the start of all three of the object display routines (Rect, Circle, and Square) cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!