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
|
#include <iostream>
#include <cmath>
using namespace std;
void Minmax(int x ,int y ,int z ,int &resultL ,int &resultH);
void Modulus(int a,int b,int "ient,int &remainder);
int main( )
{
int getMenuItem, x, y, z, resultL, resultH, a, b, quotient, remainder;
double getCentimeters, getBMI, error, getLineLength;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(3);
cout << " Please make a selection from the following menu" <<endl;
cout << " 1. Inches to centimeters "<<endl;
cout << " 2. BMI" <<endl;
cout << " 3. Length of a line"<<endl;
cout << " 4. MinMax"<<endl;
cout << " 5. Modulus"<<endl;
cout << " 6. Taylor Series"<<endl;
cout << " 7. Quit"<<endl;
cout << " Enter the number of the operation you wish to perform: " <<endl;
cin >> getMenuItem;
if(getMenuItem == 1) {
double value1;
cout << "Please enter inches: "<<endl;
cin >> value1;
getCentimeters = 2.54 * value1;
cout << "centimeters = " << getCentimeters <<endl;
} else if(getMenuItem == 2) {
int value1, value2;
cout << "please enter your weight and height: " <<endl;
cin >> value1 >> value2;
getBMI = (value1 / pow (value2, 2)) * 703;
cout << "BMI = " << getBMI <<endl;
} else if (getMenuItem == 3) {
int value1, value2, value3, value4;
cout << "Please enter the 4 required numbers: " <<endl;
cin >> value1 >> value2 >> value3 >> value4;
getLineLength = sqrt(pow(value3 - value1, 2) + pow(value4 -value2, 2));
cout << "Length of a line = " << getLineLength <<endl;
} else if (getMenuItem == 4) {
cout << "Please enter 3 integers: " <<endl;
cin >> x >> y >> z;
Minmax ( x , y ,z , resultL, resultH);
cout << "min = "<< resultL <<endl;
cout << "max = "<< resultH <<endl;
} else if (getMenuItem == 5) {
cout << "Please enter 2 integers: "<<endl;
cin >> a >> b;
Modulus ( a, b, quotient, remainder);
cout << "quotient = " << quotient <<endl;
cout << "remainder = " << remainder <<endl;
} else if (getMenuItem == 6) {
double sum=1;
double prev=1;
int n, i, x;
cout << "Please enter x and n: " <<endl;
cin >> x >> n;
for(i=1; i<=n; i++) {
prev *= (x/i);
sum += prev;
}
error=((fabs(exp(x)– sum)));
cout << "taylor series sum =" << sum <<endl;
cout << "error = " << error <<endl;
}
return 0;
}
void Minmax(int x ,int y ,int z ,int &resultL ,int &resultH)
{
resultL = x;
resultH = x;
if (resultL > y) {
resultL = y;
}
if (resultH < y) {
resultH = y;
}
if (resultL > z) {
resultL = z;
}
if(resultH < z) {
resultH = z;
}
}
void Modulus(int a,int b,int "ient,int &remainder)
{
quotient = (a / b);
remainder = (a % b);
}
|