1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#include <iostream>
#include <cmath> // added cmath
using namespace std;
/* this program will present the user with a menu and allow the user
to calculate different type of geometric shape */
const double PI = 3.1416;
double AREC (double length, double width); // fixed (), changed to doubles
double ACIRCLE (double radius); // added variable types, removed *, remover =, removed pi, removed one of the radius
double ATRIANGLE (double height, double base);// added variable types, removed *, removed /2
int main()
{
int option;
double length, width, radius, height, base;
do
{
cout << "\n1- Compute the area of a Rectangle : "
<< "\n2- Compute the area of a Circle: "
<< "\n3- Compute the area of a Triangle : "
<< "\n4- Exit Program " << endl;
cout << "\n\tPlease select an option : ";
cin >> option;
if (option == 1)
{
cout << "\nPlease enter length of the Rectangle : ";
cin >> length;
cout << "\nPlease enter the width of the Rectangle : ";
cin >> width;
cout << "The area of the Rectangle is : " << AREC(length, width);
}
else if (option == 2)
{
cout << "\nPlease enter the radius of the Circle: ";// added ;
cin >> radius;
cout << "\n The area of the Cirlce is: "
<< ACIRCLE(radius);
}
else if (option == 3)
{
cout << " In order to calculate the Area of the triangle;"
<< " we must input the base of the triangle, followed by the height of the triangle"
<< "\nPlease enter the base of the triangle";
cin >> base;
cout << "Now, please enter the Height of the triangle: ";
cin >> height;
cout << " The area of the Triangle is: " << ATRIANGLE(height, base);
}
else if (option == 4)
{
cout << "Terminating Program" << endl;
}
else
{
cout << "Invalid Option entered" << endl;
}
} while (option != 4);
return 0;
}
//added functions
double AREC(double length, double width)
{
double area;
area = length * width;
return area;
}
double ACIRCLE(double radius)
{
double area;
area = PI * pow(radius, 2);
return area;
}
double ATRIANGLE(double height, double base)
{
double area;
area = (height * base) / 2;
return area;
}
|