Question: Programming Language: C++ With the Abstract Class Shape, Make the Implementation by heritage of the derived classes Circle, Rectangle and Square. Also add them in
Programming Language: C++
With the Abstract Class Shape, Make the Implementation by heritage of the derived classes Circle, Rectangle and Square. Also add them in main.cpp.
Circle and Rectangle must inherit from Shape, and Square must inherit from Rectangle.
----------------------------------------- Shape Functions: getArea(): double getPerimeter(): double ---------------------------------------
Circle's data members: -radius: double Circle Functions: Circle() Circle(aRadius: double) setRadius(r: double):void
-------------------------------------------
Rectangle's data members: -width, height: double
Rectangle Functions: Rectangle() Rectangle(w: double, h: double) setWidth(w: double): void
setHeight(h: double): void
-----------------------------------------
Square Functions: Square() Square(s: double) setSide(s: double): void
-----------------------------------
Codes for Shape.h:
#ifndef SHAPE_H #define SHAPE_H
Codes for shape: class Shape { public: double getArea() const = 0; double getPerimeter() const = 0; };
#endif // SHAPE_H -----------------------------------------
Codes for Shape.cpp
#include "Shape.h"
double Shape::getArea() const { return area; }
double Shape::getPerimeter() const { return perimeter; } ----------------------------------------------------
Codes for Rectangle.h
#include "Shape.h"
#ifndef RECTANGLE_H #define RECTANGLE_H
class Rectangle : public Shape { protected: double width; double height; public: void setWidth(double w); void setHeight(double h); };
#endif // RECTANGLE_H -------------------------------------------------
Codes for Rectangle.cpp
#include "Rectangle.h"
void Rectangle::setWidth(double w) { }
void Rectangle::setHeight(double h) { } --------------------------------------------------------------
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
