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
|
#include <iostream>
using namespace std;
void description();
// Postcondition: Description of the program is printed to the screen.
void get_input(double& input_height, double& input_weight, int& input_age);
// Precondition: User enters correct values.
// The value of if input_height has been set to the person's height. The value of
// input_weight is set to the person's weight, and the value of input_age is set
// to the peron's age
double hat(double input_height, double input_weight);
// Precondition: Both values are positive and height is in inches
// and weight is in pounds.
// Calculates the hat size of the user.
double jacket(double input_height, double input_weight, int input_age);
// Precondition: All three values are positive. Height is in inches, weight is
// in pounds, and age is an integer.
// Calculates the jacket size (chest measurement in inches) of the user.
double jacket_age(int age);
// Precondition: Age is a positive integer.
// Starting at age 40, adds 1/8 of an inch to jacket size for every 10 years older
// the user is.
double waist(double input_height, double input_weight, int input_age);
// Precondition: All three values are positive. Height is in inches, weight is
// in pounds, and age is an integer.
// Calculates the waist in inches of the user.
double waist_age(int age);
// Precondition: Age is a positive integer.
// Starting at age 30, adds 1/10 of an inch for every 2 years older the user is.
double show_output(double hat_calc, double jacket_calc, double waist_calc);
// Precondition: hat size, jacket size, and waist size were calculated correctly.
// outputs the calculates sizes to the user.
int main ()
{
double height, weight, hat_size, jacket_size, waist_in_inches;
int age;
char answer;
do
{
description();
get_input(height, weight, age);
hat_size = hat(height, weight);
jacket_size = jacket(height, weight, age);
waist_in_inches = waist(height, weight, age);
show_output(hat_size, jacket_size, waist_in_inches);
cout << "Would you like to run this program again?\n";
cin >> answer;
}
while (answer == 'y' || answer == 'Y');
return 0;
}
//Uses iostream
void description()
{
using namespace std;
cout << "This program determines hat size, jacket size, and waist in inches\n";
cout << "based on height, weight, and age.\n";
}
//Uses iostream
void get_input(double& input_height, double& input_weight, int& input_age)
{
using namespace std;
cout << "Enter your height (to the nearest half inch): ";
cin >> input_height;
while ( input_height <= 0)
{
cout << "Enter a positive number: ";
cin >> input_height;
}
cout << "Enter your weight (to the nearest half pound): ";
cin >> input_weight;
while ( input_weight <= 0)
{
cout << "Enter a positive number: ";
cin >> input_weight;
}
cout << "Enter your age (to the neatest whole number): ";
cin >> input_age;
while ( input_age <= 0)
{
cout << "Enter a positive number: ";
cin >> input_age;
}
}
double hat(double input_height, double input_weight)
{
((input_weight/input_height)*2.9);
return ( (input_weight/input_height)*2.9 );
}
double jacket(double input_height, double input_weight, int input_age)
{
double jacket_calc;
jacket_calc = (((input_height*input_weight)/288) + jacket_age);
return ( (((input_height*input_weight)/288) + jacket_age) );
}
jacket_age(int input_age)
{
double age_factor(0), jacket(0);
for (int i=30
}
double waist(double input_height, double input_weight, int input_age)
{
double waist_calc;
waist_calc = ((input_weight/5.7) + waist_age);
return ( ((input_weight/5.7) + waist_age) );
}
// waist_age
// Same structure as jacket_age function
double show_output(hat_calc, jacket_calc, waist_calc)
{
cout << "Your hat size is " << hat_size << endl;
cout << "your jacket size (chest in inches) is << jacket_size << endl;
cout << "Your waist in inches is " << waist_in_inches << endl;
}
|