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 97 98 99 100 101 102 103 104 105 106 107 108
|
//Audy L Sain
//Week 8 Assignment 1
//Geometry Calculator
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
//Functions
void showMenu();
int main()
{
int choice; //Menu choices
float pi = 3.14159;
float radius, c, Length, Width, p, base, hight, y, thight, b1, b2,
s, sr, srr;
const int Circle_Area = 1,
Rectangle_Area = 2,
Triangle_Area = 3,
Trapezoid_Area = 4,
Sphere_Area = 5,
Exit = 6;
do
{
showMenu();
cin >> choice;
while (choice < Circle_Area || choice > Exit)
{
cout << "Please enter a valid menu choice: ";
cin >> choice;
}
if (choice != Exit)
{
switch (choice)
{
case Circle_Area:
cout << "What is the radius of the circle :";
cin >> radius;
c = pi * pow(radius, 2);
cout << "\nThe Area of the Circle is :" << c << endl;
break;
case Rectangle_Area:
cout << "What is the Rectangle length :";
cin >> Length;
cout << "\nWhat is the Rectangle width :";
cin >> Width;
p = Length * Width;
cout << "\nThe Area of the Rectangle is :" << p << endl;
break;
case Triangle_Area:
cout << "What is the length of the Triangle base :";
cin >> base;
cout << "\nWhat is the hight of the Triangle :";
cin >> hight;
y = base * hight * 0.5;
cout << "\nThe Area of the Triangle is :" << y << endl;
break;
case Trapezoid_Area:
cout << "What is the hight of the Trapezoid :";
cin >> thight;
cout << "\nWhat is the first base length :";
cin >> b1;
cout << "\nWhat is the secound base length :";
cin >> b2;
s = hight / 2 * (b1 + b2);
cout << "\nThe Area of the Trapezoid is :" << s << endl;
break;
case Sphere_Area:
cout << "What is the radius of the Sphere :";
cin >> sr;
srr = 4 * pi * pow(sr, 2);
cout << "\nThe area of the sphere is :" << srr << endl;
break;
}
}
}
while (choice != Exit);
return (0);
}
//Menu Function
void showMenu()
{
cout << "Please choose a selection" << endl << endl
<< "1. Calculate the Area of a Circle" << endl
<< "2. Calculate the Area of a Rectangle" << endl
<< "3. Calculate the Area of a Triangle" << endl
<< "4. Calculate the Area of a Trapezoid" << endl
<< "5. Calculate the Area of a Sphere" << endl
<< "6. Exit" << endl << endl;
}
|