//Nicolas Ruano CS1A Chapter 4, Pp. 223, #21
//
/******************************************************************************
*
* AREA OF VARIOUS SHAPES CALCULATOR
* ____________________________________________________________________________
* This program calculates the area of a circle, rectangle, and triangle.
*
*
* FORMULA IS BASED ON THIS CALCULATION:
* Area of a cirlce = pi * radius^2
* Area of rectangle = Base X Height
* Area of a triangle = Base * Height * .5
*
*
*
* ____________________________________________________________________________
* INPUT
* radiusCircle : The radius of the circle
* lengthRectangle : The length of the rectangle
* widthRectangle : The width of the rectangle
* baseTriangle : The base of the triangle
* heightTriangle : The height of the triangle
*
* OUTPUT
* areaOfCircle
* AreaOfRectangle
* AreaOfTriangle
**************************************************************/
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
int choice; //INPUT - THE CHOICES TO BE MADE 1-4
float radiusCircle; //INPUT - THE RADIUS OF THE CIRCLE
float lengthRectangle; //INPUT - THE LENGTH OF THE RECTANGLE
float widthRectangle; //INPUT - THE WIDTH OF THE RECTANGLE
float baseTriangle; //INPUT - THE BASE OF THE TRIANGLE
float heightTriangle; //INPUT - THE HEIGHT OF THE TRIANGLE
float areaOfCircle; //OUTPUT - THE AREA OF THE CIRCLE TO BE COMPUTED
float areaOfRectangle; //OUTPUT - THE AREA OF THE RECTANGEL TO BE COMPUTED
float areaOfTriangle; //OUTPUT - THE AREA OF THE TRIANGLE TO BE COMPUTED
//
// Initialize the variables
cout << "Geometry Calculator" << endl;
cout << "1. Calculate the Area of a Circle" << endl;
cout << "2. Calcualte the Area of a Rectangle" << endl;
cout << "3. Calcualte the area of a Triangle" << endl;
cout << "4. Quit" << endl;
cin >> choice;
cout << fixed << setprecision(2) << endl;
if (choice >= 0 and choice <=4) {
switch (choice) {
case 1:
cout << "Please enter the radius of the circle " << endl;
cin >> radiusCircle;
if (radiusCircle > 0) {
areaOfCircle = 3.14159 * (pow(radiusCircle, 2));
cout << "The area of the circle is " << areaOfCircle;
}
else {
cout << "Cannot have negative radius " << endl;
}
break;
case 2:
cout << "Please enter the length of the rectangle " << endl;
cin >> lengthRectangle;
if (lengthRectangle < 0 ) {
cout << "Cannot have a negative length " << endl;
break;
}
cout << "Please enter the width of the rectangle " << endl;
cin >> widthRectangle;
if (widthRectangle < 0 ) {
cout << "Cannot have a negative width " << endl;
break;
}
else {
areaOfRectangle = lengthRectangle * widthRectangle;
cout << "The area of the of the rectangle is " << areaOfRectangle;
}
break;
case 3:
cout << "Please enter the base of the triangle " << endl;
cin >> baseTriangle;
if (baseTriangle < 0) {
cout << "Cannot have a negative base " << endl;
break;
}
cout << "Please enter the height of the triangle " << endl;
cin >> heightTriangle;
if (heightTriangle < 0) {
cout << "Cannot have a negative height" << endl;
break;
}
else {
areaOfTriangle = baseTriangle * heightTriangle * .5;
cout << "The area of the triangle is " << areaOfTriangle << endl;
}
break;
case 4:
cout << "Goodbye" << endl;
break;
}
}
else {
cout << "INVALID MENU OPTION " << endl;
}
return 0;
}