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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int displayMenu();
double calcAreaCircle( double radius );
double calcAreaRect( double length, double width );
double calcAreaTriangle( double base, double height );
const double Pi = 3.14159;
int main ()
{
int choice;
double radius, width, length, base, height;
double menu;
menu=displayMenu();
double circArea;
circArea = calcAreaCircle (radius);
double rectArea;
rectArea = calcAreaRect (length, width);
double triArea;
triArea = calcAreaTriangle (base, height);
switch(choice)
{
case 1:
{
cout << "Please enter the Radius:" << endl;
cin >> radius;
}
break;
case 2:
{
cout << "Please enter the Length:" << endl;
cin >> length;
cout << endl;
cout << "Please enter the width:" << endl;
cin >> width;
cout << endl;
}
break;
case 3:
{
cout << "Please enter the Base:" << endl;
cin >> base;
cout << endl;
cout << "Please enter the Height:" << endl;
cin >> height;
cout << endl;
}
break;
case 4:
cout<< "Bye! "<<endl;
system ("pause");
break;
}
}
int displayMenu()
{
int choice;
cout << "Geometry Calculator"<<endl;
cout << "1. Calculate the Area of a Circle"<<endl;
cout << "2. Calculate the Area of a Rectangle"<<endl;
cout << "3. Calculate the Area of a Triangle"<<endl;
cout << "4. Quit";
cout << endl;
cin >> choice;
while (choice < 1 || choice > 4)
{
cout << "Invalid selection. Enter 1, 2, 3, or 4: ";
cin >> choice;
}
}
return choice (int);
}
double calcAreaCircle(double radius)
{
double circArea = Pi*radius*radius;
if (radius > 0)
{
cout << "The area of the circle " << radius << " is: " << area << endl;
system ("pause");
return 0;
}
else
{
cout << "You did not enter a valid number" << endl;
cout << "The program will now restart" << endl;
system ("pause");
return circArea;
}
}
double calcAreaRect (double width, double length)
{
double rectArea = length * width
if (length > 0, width > 0)
{
cout << "The Area for the Rectangle is: " << area << endl;
system ("pause");
return rectArea;
}
else
{
cout << "You did not enter valid numbers." << endl;
cout << "The program will now restart." << endl;
system ("pause");
return rectArea;
}
}
double calcAreaTriangle (double base, double height )
{
double triArea = base * height
if (base > 0, height > 0)
{
triArea = .5 * base * height;
}
else
{
cout << "You did not enter a valid number." << endl;
cout << "Please retry your entry." << endl;
system ("pause");
return triArea;
}
}
|