Question: Please add additional //comments to the lines of code below. Circle.cpp #include circle.h #include #include using namespace std; void Circle::input() { ID = 1; type

Please add additional //comments to the lines of code below.

Circle.cpp

#include "circle.h"

#include

#include

using namespace std;

void Circle::input()

{

ID = 1;

type = "Circle";

cout << "Enter radius: ";

cin >> radius;

cout << "Enter Unit Of Measure: ";

cin >> unitOfMeasure;

}

void Circle::print()

{

// circumference of circle

double circumference = 2 * 3.14159 * radius;

cout << type << " with ID = " << ID

<< ", radius = " << radius << " " << unitOfMeasure

<< ", area = " << GetArea() << " " << unitOfMeasure << "^2"

<< ", circumference = " << " " << circumference << unitOfMeasure << endl;

}

double Circle::GetArea()

{

// area of circle

return 3.14159 * radius * radius;

}

Main.cpp

#include

#include "square.h"

#include "circle.h"

#include "triangle.h"

using namespace std;

int main()

{

char type;

// Loop till user want to quit

Shape* sh = nullptr;

while (true)

{

// Prompt user for option

cout << "Enter type of figure(C - Circle, S - Square, T - Triangle or Q - quit: ";

cin >> type;

switch(type)

{

case 'C': sh = new Circle; break;

case 'S': sh = new Square; break;

case 'T': sh = new Triangle; break;

case 'Q': exit(0);

default:

cout << "Invalid ";

break;

}

if(sh)

{

sh->input();

sh->print();

delete sh;

sh = nullptr;

}

cout << endl;

}

return 0;

}

Square.cpp

// include square.h header file

#include "square.h"

// Constructor

Square::Square(double _a)

: a(_a)

{

}

// function to calculate area

double Square::GetArea()

{

return a * a;

}

// function to read sides

void Square::input()

{

ID = 2;

type = "Square";

cout << "Enter side: ";

cin >> a;

cout << "Enter Unit Of Measure: ";

cin >> unitOfMeasure;

}

// print sides and area

void Square::print()

{

cout << type << endl;

cout << "ID: " << ID << endl;

cout << "Side: " << a << " " << unitOfMeasure << endl;

cout << "Area: " << GetArea() << " " << unitOfMeasure << "^2" << endl;

}

Triangle.cpp

#include "triangle.h"

#include

double Triangle::GetArea()

{

double s = (a + b + c)/2;

return sqrt((s*(s-a)*(s-b)*(s-c)));

}

void Triangle::input()

{

ID = 3;

type = "Triangle";

cout << "Enter side a: ";

cin >> a;

cout << "Enter side b: ";

cin >> b;

cout << "Enter side c: ";

cin >> c;

cout << "Enter Unit Of Measure: ";

cin >> unitOfMeasure;

}

void Triangle::print()

{

cout << type << endl;

cout << "ID: " << ID << endl;

cout << "Side a: " << a << " " << unitOfMeasure << ", Side b: "

<< b << " " << unitOfMeasure

<< ", Side c: " << c << " " << unitOfMeasure << endl;

cout << "Area: " << GetArea() << " " << unitOfMeasure << "^2" << endl;

}

Circle.h

#ifndef CIRCLE_H_INCLUDED

#define CIRCLE_H_INCLUDED

#include

#include "shape.h"

using namespace std;

class Circle : public Shape

{

private:

double radius;

double GetArea() override;

public:

Circle() = default;

void input() override;

void print() override;

};

#endif // CIRCLE_H_INCLUDED

Shape.h

#ifndef SHAPE_H_INCLUDED

#define SHAPE_H_INCLUDED

#include

using namespace std;

class Shape

{

protected:

int ID;

string type;

string unitOfMeasure;

Shape() = default;

virtual double GetArea() = 0;

public:

virtual void input() = 0;

virtual void print() = 0;

virtual ~Shape(){}

};

#endif // SHAPE_H_INCLUDED

Square.h

#ifndef SQUARE_H_INCLUDED

#define SQUARE_H_INCLUDED

#include

#include

#include "shape.h"

using namespace std;

class Square : public Shape

{

private:

double a;

//declaration of functions in header file

double GetArea() override;

public:

// constructor with default arguments 0.0

Square(double _a = 0.0);

void print() override;

void input() override;

};

#endif // SQUARE_H_INCLUDED

Triangle.h

#ifndef TRIANGLE_H

#define TRIANGLE_H

#include "shape.h"

class Triangle : public Shape

{

private:

double a, b, c;

double GetArea() override;

public:

Triangle() = default;

void input() override;

void print() override;

};

#endif // TRIANGLE_H

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!