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
|
#include <iostream>
#include <math.h>
#define PI 3.141592653589793238463
using namespace std;
double a, B, A, s, P, r, cena, ina;
void report(int n, double B)
{
cout << "\n\nCalculating...\n\n\n";
cout << "Number of Sides: " << n <<"\nApothem: " << a << "\nSide Length: " << s
<< "\nPerimeter: " << P << "\nRadius: " << r << "\nArea: " << A << "\n\nInterior Angle Measure: " << ina
<< "\nCentral Angle Measure: " << cena << "\n\n\n";
}
void apothem(int n, double B)
{
cout << "\n\nWhat is the length of the apothem?\n\n";
cin >> a;
s = (tan(B*PI/180)*a)*2;
P = s*n;
A = (P*a)/2;
r = a/cos(B*PI/180);
report(n, B);
}
void side(int n, double B)
{
cout << "\n\nWhat is the length of one side?\n\n";
cin >> s;
a = (s/2)/tan(B*PI/180);
P = s*n;
A = (P*a)/2;
r = a/cos(B*PI/180);
report(n, B);
}
void radius(int n, double B)
{
cout << "\n\nWhat is the length of the radius?\n\n";
cin >> r;
s = (r*sin(B*PI/180))*2;
P = s*n;
a = (s/2)/tan(B*PI/180);
A = (P*a)/2;
report(n, B);
}
void perimeter(int n, double B)
{
cout << "\n\nWhat is the perimeter?\n\n";
cin >> P;
r = ((P/n)/2)/sin(B*PI/180);
s = (r*sin(B*PI/180))*2;
a = (s/2)/tan(B*PI/180);
A = (P*a)/2;
report(n, B);
}
int main()
{
int selection, n;
bool redo;
cout << "How many sides does the polygon have?\n\n"; //Right now it assumes you know the number of sides. I'll change this later.
cin >> n;
B = (360/n)/2;
cena = 360/n;
ina = ((n-2)*180)/n;
cout << "\n\n";
cout << "What else do you know?\n\n1.Length of the Apothem\n"
"2.Length of a Side\n3.Length of the Radius\n4.Perimeter of the Polygon\n\nEnter 1-4\n\n";
cin >> selection;
if (selection==1) //sends you to the corresponding function
apothem(n, B);
if (selection==2)
side(n, B);
if (selection==3)
radius(n, B);
if (selection==4)
perimeter(n, B);
cout << "Would you like to try another?\n\n1.Yes\n2.No\n\n";
cin >> redo;
if (redo==true)
{
cout << "\n\n\n";
main();
}
return 0;
}
|