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 //Need this header file to support the C++ I/O system #include "circle.cpp"// including the header and implementation files #include "square.cpp" #include "rectangle.cpp" #include "shape.cpp"

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" <> menuOption;

switch(menuOption) {

case 1: { cout<< "Enter the radius : " ; cin>> radius; circle.setRadius(radius); cout<< "Area of the circle is "<> length; square.setLength(length); cout<<"Area of the square is "<> length; rectangle.setLength(length); cout<< "Enter width of one side of the rectangle : "<> width; rectangle.setWidth(width); cout<<"Area of the rectangle 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 #include "shape.h"

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

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!