Question: This area calculation program includes data members common to all shapes, such as a shape ID, a shape type, but does not include a unit
This area calculation program includes data members common to all shapes, such as a shape ID, a shape type, but does not include a unit of measure. Unit of measure should be included.
//main.cpp #include
using namespace std;//Telling the compiler to use name space where C++ library is declared
int main( ) { double radius = 0; double length = 0; double width = 0; Square square; Circle circle; Rectangle rectangle;
int menuOption;//declare menu selection variable
do { // Initialize while loop cout << endl << "_______________Calculate Area______________" << endl; cout << "Select an Object" << endl; cout << " 1: Circle" << endl; cout << " 2: Square" << endl; cout << " 3: Rectangle" <
switch(menuOption) {
case 1: { cout<< "Enter the radius : " ; cin>> radius; circle.setRadius(radius); cout<< "Area of the circle is "< } while(menuOption!=0); cout<<" ________________ END PROGRAM ___________________" < //circle.cpp #include "Circle.h" #include using namespace std; Circle::Circle (double r) { radius = r; } double Circle::getRadius() { return radius; } void Circle::setRadius (double r){ radius = r; } double Circle::getArea(){ return radius * radius * 3.14159; } //circle.h #include "Circle.h" #include using namespace std; Circle::Circle (double r) { radius = r; } double Circle::getRadius() { return radius; } void Circle::setRadius (double r){ radius = r; } double Circle::getArea(){ return radius * radius * 3.14159; } //square.cpp #include "Square.h" #include using namespace std; Square::Square(double len) { length = len; } double Square::getLength() { return length; } void Square::setLength(double len){ length = len; } double Square::getArea(){ return length * length; } //square.h #ifndef SQUARE_H #define SQUARE_H #include "shape.h" using namespace std; class Square : public Shape { public: Square (double length =0); double getLength(); void setLength(double length); virtual double getArea (); private: double length; }; #endif // SQUARE_H //rectangle.cpp #include "Rectangle.h" #include using namespace std; Rectangle::Rectangle(double len, double wid) { length = len; width = wid; } double Rectangle::getLength() { return length; } void Rectangle::setLength(double len){ length = len; } double Rectangle::getWidth() { return width; } void Rectangle::setWidth(double wid){ width= wid; } double Rectangle::getArea(){ return length * width; } //rectangle.h #ifndef RECTANGLE_H_INCLUDED #define RECTANGLE_H_INCLUDED #include class Rectangle: public Shape { public: Rectangle (double length =0, double width =0); double getLength(); double getWidth(); void setLength(double length); void setWidth(double width); virtual double getArea (); private: double length; double width; }; #endif // RECTANGLE_H_INCLUDED //shape.cpp #include "shape.h" #include Shape::Shape(){ area = 0; } double Shape::getArea(){ return area; } //shape.h #ifndef SHAPE_H #define SHAPE_H #include class Shape{ // Base Class public: Shape(); double getArea(); private: double area; }; #endif // SHAPE_H_INCLUDED
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
