/*
ed george 2008
Please Enter Version and Update Date */
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main(){
string version;
version = "1.2.0";
string update;
update = "02/03/08";
char ch = 0;
int choice(0);
int schoice(0);
const double PI = 3.14159;
cout << "---------------------------"<<endl;
cout<<"Welcome to Ed George's Math Class Program Version
"<<version<<endl; //Version = Build, Major, Minor
cout << "---------------------------"<<endl;
cout<<"Enter A for Sphere Tool"<<endl;
cout<<"Enter B for Gradient Tool"<<endl;
cout<<"Enter C for Shape Tool"<<endl;
cout<<"Enter D for Info About this Program"<<endl;
cout<<"Enter E to Quit"<<endl;
cin >> ch;
ch = toupper (ch);
switch (ch)
{
case 'A':
do
{
cout<<"--Sphere Tool--"<<endl;
cout<<"0: Exit"<<endl;
cout<<"1: Find Surface Area and Volume"<<endl;
cout<<"2: Find Radius Using Surface Area"<<endl;
cout << "---------------------------"<<endl;
cin>>choice;
if (choice == 1)
{
double r(0);
double sa(0);
double v(0);
do
{
cout<<"Enter radius: ";
cin>>r;
} while (r < 0);
sa = 4 * PI * (r*r);
v = (4.0 * PI * (r*r*r) ) / 3.0;
cout<<"Surface area: "<<sa<<endl;
cout<<"Volume: "<<v<<endl;
}
else if (choice == 2)
{
double r(0);
double sa(0);
do
{
cout<<"Enter surface area: ";
cin>>sa;
} while (sa < 0);
r = sqrt( sa / (4*PI) );
cout<<"Radius: "<<r<<endl;
}
else if (choice == 0)
{
cout<<"Good bye!"<<endl;
}
else
{
cout<<"Invalid input!"<<endl;
}
} while (choice != 0);
break;
case 'B':
cout << "---------------------------"<<endl;
cout << "Welcome to Ed George's C++ Gradient Finder tool - Version
1.1.5"<<endl;
cout << "Use this tool to find the gradient of a line"<<endl;
cout << "---------------------------"<<endl;
cout << "x1 and x2 are the two different x co-ordinates in a pair of
co-ordinates"<<endl;
cout << "e.g. (3,4) & (5,6)"<<endl;
cout << "x1 would be 3 and x2 would be 5"<<endl;
cout << "Its the same with y1 and y2."<<endl;
cout << "Using the same example: y1 would be 4 and y2 would be 6."<<endl;
int a;
do
{
double x1, x2, y1, y2, slope, mid1, mid2, dist, A, B;
cout << "---------------------------"<<endl;
cout<< "Please enter a value for x1: ";
cin >> x1;
cout << "Please enter a value for x2: ";
cin >> x2;
cout << "Please enter a value for y1: ";
cin >> y1;
cout << "Please enter a value for y2: ";
cin >> y2;
cout << "---------------------------"<<endl;
//Calculating the results for gradient(slope):
slope = (y2 - y1)/(x2 - x1);
//Mid point formula broken into 2 sections for x and y:
mid1 = (x1 + x2)/2;
mid2 = (y1 + y2)/2;
//Distance Formulae
A = pow(x1 - x2, 2);
B = pow(y1 - y2, 2);
dist = sqrt(A + B);
cout << "Results:"<<endl;
cout << "\nThe slope of the line is = " << slope <<endl;
cout << "\nThe midpoint of the line is (" << mid1 <<
"," << mid2 << ")"<<endl;
cout << "\nThe distance of the line segment is = " << dist
<<endl;
cout << "---------------------------"<<endl;
cout << "If you would like to Continue using this Program, Enter
1"<<endl;
cout << "For Help please press 2"<<endl;
cout << "To EXIT Please Go To Help (2) and then Enter \"3\"
when prompted: ";
cin >> a;
} while ( a == 1 );
do
{
cout << "---------------------------"<<endl;
cout << "Welcome to the help section."<<endl;
cout << "---------------------------"<<endl;
cout << "To use this program properly you must know two co-ordinates that a
line passes"<<endl;
cout << "To find the gradient."<<endl;
cout <<"e.g. y=x^2 (squared)"<<endl;
cout << "(2,4) and (3,9) are both on the line"<<endl;
cout << "Therefore: "<<endl;
cout << "x1 = 2"<<endl;
cout << "x2 = 3"<<endl;
cout << "y1 = 4"<<endl;
cout << "y2 = 9"<<endl;
cout << "---------"<<endl;
cout << "Please note that if any value is (example) 6.02e23"<<endl;
cout << "It simply means 6.02 x 10^23"<<endl;
cout << "If the value is (example) 1.6e-19"<<endl;
cout << "It simply means 1.6 x 10^-19"<<endl;
cout << "---------"<<endl;
cout << "If you would like to Continue using help, Enter 2"<<endl;
cout << "To return to the main program enter 1"<<endl;
cout << "Otherwise, to exit press 3 and then enter."<<endl;
cin >> a;
} while ( a == 2 );
do{
break;
} while (a == 3);
break;
case 'C':
do
{
cout<<"--Shape Tool--"<<endl;
cout<<"0: Exit"<<endl;
cout<<"1: Trapezium"<<endl;
cout<<"2: Parallelogram"<<endl;
cout << "---------------------------"<<endl;
cin>>schoice;
if (schoice == 1)
{
double tbase(0);
double ttop(0);
double vh(0);
double ta(0);
do
{
cout<<"Enter Base Lenght: ";
cin>>tbase;
} while (tbase < 0);
do
{
cout<<"Enter Top Lenght: ";
cin>>ttop;
} while (ttop < 0);
do
{
cout<<"Enter Vertical Hight: "<<endl;
cin>>vh;
} while (vh < 0);
ta = (0.5 * (ttop + tbase)) * vh;
cout<<"\n";
cout<<"The Area Is: "<<ta<<endl;
cout << "---------------------------"<<endl;
cout<<"To Start Over Enter 1"<<endl;
cout<<"To Move Onto Parallelograms Enter 2"<<endl;
cout<<"To Exit Enter 0"<<endl;
cout << "---------------------------"<<endl;
cin>>schoice;
}
else if (schoice == 2)
{
double pbase(0);
double pvh(0);
double pa(0);
do
{
cout<<"Enter Base Lenght: ";
cin>>pbase;
} while (pbase < 0);
do
{
cout<<"Enter Vertical Hight: ";
cin>>pvh;
} while (pvh < 0);
pa = pbase * pvh;
cout<<"The Area Is: "<<pa<<endl;
cout << "---------------------------"<<endl;
cout<<"To Start Over Enter 2"<<endl;
cout<<"To Move to Trapeziums Enter 1"<<endl;
cout<<"To Exit Enter 0"<<endl;
cout << "---------------------------"<<endl;
cin>>schoice;
}
else if (schoice == 0)
{
cout<<"Good bye!"<<endl;
}
else
{
cout<<"Invalid input!"<<endl;
}
} while (schoice != 0);
break;
case 'D':
cout<<"The Current Version is "<<version<<endl;
cout<<"The Last Update Was on the "<<update<<endl;
cout<<"Created In Full By Funkyjunky 2008"<<endl;
cout<<"---------------------------"<<endl;
cout<<"Menu"<<endl;
cout<<"---------------------------"<<endl;
cout<<"Enter A for Sphere Tool"<<endl;
cout<<"Enter B for Gradient Tool"<<endl;
cout<<"Enter C for Shape Tool"<<endl;
cout<<"Enter E to Quit"<<endl;
cout<<"---------------------------"<<endl;
cin >> ch;
break;
case 'E': break;
default: // Program should handle the case where the user enters an invalid
character
cout << "Sorry, '" << ch << "' does not correspond to a
function. Please try again."<<endl;
cout<<"Enter A for Sphere Tool"<<endl;
cout<<"Enter B for Gradient Tool"<<endl;
cout<<"Enter C for Shape Tool"<<endl;
cout<<"Enter D for Info About this Program";
cout<<"Enter E to Quit"<<endl;
cin >> ch;
}
return 0;
}