C++:Problem12

Problem:
Write a program that asks the user’s height, weight, and age and then computes clothing sizes according to the formulas:

• Hat size = weight in pounds divided by height in inches and all that multiplied by 2.9.
• Jacket size (chest in inches) = height times weight divided by 288 and then adjusted by 1/8 of an inch for each 10 years over age 30. (Note that the adjustment only takes after a full ten years. So, there is no adjustment for ages 30 through 39, but 1/8 of an inch is added for age 40.)
Waist in inches = weight divided by 5.7 and then adjusted by adding 1/10 of an inch for each 2 years over age 28. (Note that the adjustment only takes place after a full 2 years. So, there is no adjustment for age 29, but 1/10 of an inch is added for age 30.)

Objective:
• Software Design
• Writing functions
• Function prototypes with comments: purpose, precondition and postconditon
• Call to functions
• Function definitions
• Using logical data types for variables
• Using good format for source program

Software Design:
Problem: Write a program that asks the user’s height, weight, and age and then computes clothing sizes according to the formulas:

• Hat size = weight in pounds divided by height in inches and all that multiplied by 2.9.
• Jacket size (chest in inches) = height times weight divided by 288 and then adjusted by 1/8 of an inch for each 10 years over age 30. (Note that the adjustment only takes after a full ten years. So, there is no adjustment for ages 30 through 39, but 1/8 of an inch is added for age 40.)
• Waist in inches = weight divided by 5.7 and then adjusted by adding 1/10 of an inch for each 2 years over age 28. (Note that the adjustment only takes place after a full 2 years. So, there is no adjustment for age 29, but 1/10 of an inch is added for age 30.)


A. Analyze:

GIVEN:
- (User) enters his/her height.
- (User) enters his/her weight.
- (User) (User) enters his/her age.

FIND:
- Hate size in inches.
- Jacket size (chest in inches.)
- Waist in inches.

B. Data Types:
1. Functions
a. double hat(double weight ,double height)

b. double jacket(double height,double weight,int age)
Local variables:
double size;
int j;

c. double waist(double height,double weight,int age)
Local variables:
double size2;
int k;


2. Input variables
double height;
double weight;
int age;
char answer;

C. Formulas:
For the hat size ((weight/height) * 2.9);
For age smaller than or equal to 30
size = (height * weight) / 288);
For age bigger than 30
size =((height * weight) / 288)+((1.0/8)*j); where j= (age-30)/10;
For age smaller than or equal to 28
size2 = weight/(5.7);
For age bigger than 28
size2 = (weight/(5.7))+( (1.0/10)*k); where k = (age-28)/2;
D. Algorithm:
1. Introduction
2. Ask user for his/her height.
3. Ask user for his/her weight.
4. Ask user for his/her age.
5. Calculations
a. The size of the hate.
b. The size of the jacket.
c. The size of the waist.
6. Output Results
7. Closing

Display:
This program will calculate a customers size for hat
jacket and waist based on inputs of age weight and height.

Enter the customer's height in inches: 67
Enter the customer's weight in pounds: 240
Enter the customer's age: 45


Your Hat size: 10.39
Your Jacket size: 55.96
Your Waist size: 42.91


Would you like to continue (y/n)? y
Enter the customer's height in inches: 55
Enter the customer's weight in pounds: 120
Enter the customer's age: 23


Your Hat size: 6.33
Your Jacket size: 22.92
Your Waist size: 21.05


Would you like to continue (y/n)? n
End of program

Code:
#include
#include
#include
using namespace std;

//function declaration
double hat(double,double);
//purpose: find size of hat
//preconditon: input weight in pounds & height in inches
//postcondtion: return size of hat

//function declaration
double jacket(double,double,int);
//purpose: find size of jacket
//preconditon: input height in inches & weight in pounds & age
//postcondtion: return size of jacket

//function declaration
double waist(double,double,int);
//purpose: find size of waist
//preconditon: input weight in pounds & age
//postcondtion: return size of waist

int main ()
{
//variable declaration
double height, weight;
int age;
char answer;

//format decimal
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

cout << "\t\t This program will calculate a customers size for hat\n"
<< "\t\t jacket and waist based on inputs of age weight and height.\n\n";

do
{
cout<< "Enter the customer's height in inches: ";
cin>>height;
cout<< "Enter the customer's weight in pounds: ";
cin>>weight;
cout<< "Enter the customer's age: ";
cin>>age;
cout< cout<< "\tYour Hat size: "< cout<< "\tYour Jacket size: "< cout<< "\tYour Waist size: "< cout<< "Would you like to continue (y/n)? ";
cin>>answer;
}while(toupper(answer) == 'Y');
cout<< "End of program"< return 0;
}

//function definition
double hat(double weight ,double height)
{
return ((weight/height) * 2.9);
}

//function definition
double jacket(double height,double weight,int age)
{
double size;
int j;
if (age>=30)
{
if((age % 10) !=0)
age = age-(age%10);
j= (age-30)/10;
size =((height * weight) / 288)+((1.0/8)*j);
}
else
size =((height * weight) / 288);
return size;
}

//function definition
double waist(double height,double weight,int age)
{
double size2;
int k;
if(age >= 28)
{
if((age % 2) !=0)
age = age-(age%2);
k = (age-28)/2;
size2 = (weight/(5.7))+( (1.0/10)*k);
}
else
size2 = weight / (5.7);
return size2;
}