// Mariah Contreras CSC5 Chapter 4, P.226, #23
//
/* ************************************************************
*
* COMPUTE GEOMETRIC AREAS
* ____________________________________________________________
* This program will display a menu of geometry
* calculations. Then based upon the users selction will
* compute the area of a specificed shape and display it.
*
* Computation is based on the formula :
* Area of a Circle = PI * (Radius * Radius)
* Area of a Rectangle = Lenght * Width
* Area of a Triangle = Base * Height * 0.5
* ____________________________________________________________
* INPUT
* choice : choice on menu
* radius : Radius of Circle
* length : Length of Rectangle
* width : Width of Rectangle
* base : Base of Triangle
* height : Height of Triangle
*
* OUTPUT
* area : Area of choosen shape
*
**************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
float const PI = 3.14159; // CONSTANT - PI
int const areaCircle = 1, // CONSTANT - Menu Choice 1
areaRectangle = 2, // CONSTANT - Menu Choice 2
areaTriangle = 3, // CONSTANT - Menu Choice 3
quit = 4; // CONSTANT - Menu Choice 4
int choice; // INPUT - Menu Choice
float radius, // INPUT - Radius of circle
length, // INPUT - Length of Rectangle
width, // INPUT - Width of Rectangle
base, // INPUT - Base of Triangle
height, // INPUT - Height of Triangle
area; // OUTPUT - Area of Choosen Shape
//
// Display Menu and Prompt User for Choice
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";
cout << "Enter your choice (1-4):";
// Get Menu Choice and Respond
cin >> choice;
switch (choice)
{
//
// Area of Circle
case areaCircle:
cout << "\nEnter the Radius of the circle";
cin >> radius;
if (radius > 0)
{
area = PI * (radius * radius);
cout << "\nThe Area of the Circle: " << area;
}
else
{
cout << "\nYou Entered an Invalid Number.Please ";
cout << "\nreset the Program and enter a valid number.";
}
break;
//
// Area of Rectangle
case areaRectangle:
cout << "\nEnter the length of the rectangle:";
cin >> length;
cout << "\nEnter the width of the rectangle";
cin >> width;
if (length > 0 && width > 0)
{
area = length * width;
cout << "\nThe Area of the Rectangle: " << area;
}
else
{
cout << "\nYou entered an invalid number.Please ";
cout << "\nreset the program and use valid numbers.";
}
break;
//
// Area of Triangle
case areaTriangle:
cout << "\nEnter the base of the triangle:";
cin >> base;
cout << "\nEnter the height of the triangle";
cin >> height;
if (base > 0 && height > 0)
{
area = base * height * 0.5;
cout << "\nThe Area of the Triangle: " << area;
}
else
{
cout << "\nYou entered an invalid number.Please ";
cout << "\nReset the program and use valid numbers.";
}
break;
//
// Quit Program
case quit:
cout << "\nYou've ended the program";
break;
default: cout << "\nMenu input invalid. Please enter a number from 1-4.\n";
}
return 0;
}