//Henry Hill CSC5 Chapter 4, P. 226, #25
//
/**************************************************************
* CALCULATE AREA OF CIRCLE, TRIANGLE, OR RECTANGLE
* ____________________________________________________________
* This program will ask the user to choose either a circle
* rectangle, or triangle, and will then ask for the components
* necessary to calculate and display the area of either
* requested shape.
* ____________________________________________________________
* INPUT
* radius : Radius of a cirlce
* length : Length of a rectangle
* width : Width of a rectangle
* base : Base of a triangle
* height : Height of a triangle
* shapeChoice : User's menu choice
*
* OUTPUT
* areaCircle : Area of the circle
* areaRectangle : Area of the rectangle
* areaTriangle : Area of the triangle
****************************************************************/
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
const float PI = 3.14159;
const int shapeChoice1 = 1;
const int shapeChoice2 = 2;
const int shapeChoice3 = 3;
const int shapeChoice4 = 4;
float radius; //
float length; //
float width; //
float base; //
float height; //
int shapeChoice; //
float areaCircle; //
float areaRectangle; //
float areaTriangle; //
// Menu bit
cout << "Geometry Calculator\n";
cout << "1. Calculate the Area of a Circle\n";
cout << "2. Calculate the Area of a Rectangle\n";
cout << "3. Calculate the Area of a Triangle\n";
cout << "4. Quit\n";
cin >> shapeChoice;
cout << fixed;
cout << showpoint;
cout << setprecision(2);
if (shapeChoice == shapeChoice1)
{
cout << "\nWhat is the radius? ";
cin >> radius;
areaCircle = PI * pow(radius, 2);
cout << "\nThe area of the circle is " << areaCircle;
}
else if (shapeChoice == shapeChoice2)
{
cout << "\nWhat is the length and width of the rectangle?";
cin >> length;
cin >> width;
areaRectangle = length * width;
cout << "\nThe area of the Rectangle is " << areaRectangle;
}
else if (shapeChoice == shapeChoice3)
{
cout << "\nWhat is the length and width of the triangle?";
cin >> base;
cin >> height;
areaTriangle = base * height * 0.5;
cout << "\nThe area of the triangle is " << areaTriangle;
}
else if (shapeChoice == shapeChoice4)
{
cout << "\nDone";
}
else
cout << "Invalid ";
return 0;
}