Solution
// Programmer: Clayton Price
// File: hw5.cpp
// Purpose: This file contains the main function for the program that will
// let the user know if a pair of pants is socially acceptable.
#include <iostream>
using namespace std;
//this constant is the universally used ratio of waist to inseam value that
// all tailors use.
const float UNIVERSAL_WAIST_INSEAM_RATIO = .9;
//this constant represents the minimum value for a waist measurement.
const float MIN_WAIST = 0;
//this constant represents the minimum accepted length of a human leg.
const float MIN_LEG_LENGTH = 0;
//this constant represents the maximum accepted length of a human leg.
const float MAX_LEG_LENGTH = 50;
//this constant represtns the minimum tolerance for highwater pants.
const float MIN_HIGHWATER_TOLERANCE = 0;
// The greet() function will display to the screen a welcome message. It will
// prompt for and read in user's name and return it.
// Pre: none
// Post: message displayed to screen; user's name returned.
string greet();
// The signoff() function will display to the screen a exiting message.
// Pre: none
// Post: message displayed to screen.
void signoff(const string name);
// The get_waist() function will prompt for and read in and return a waist measure.
// Pre: none.
// Post: waist measurement is returned.
float get_waist(const string name);
// The get_leg() function will prompt for and read in and return a leg length
// measure.
// Pre: none.
// Post: length of leg of user is returned.
float get_leg_measure();
// The get_tolerance() function will prompt for and read in and then return
// the user's tolerance of highwaterness for his/her trousers.
// Pre: none.
// Post: highwater tolerance is returned.
float get_tolerance(const string name);
// The inseam_calculator() function will return an inseam measure as determined
// by the_waist measurement passed.
// Pre: the_waist must be positive.
// Post: the inseam value so determined is passed back.
float inseam_calculator(const float the_waist);
// The judge_pants() function will return true or false as to whether the pants
// measurements will exceed or not the tolerance of the user as judged by
// the other parameters.
// Pre: all parameters must be positive.
// Post: true or false returned; true if pants with inseam meets user's tolerance
bool judge_pants(const float leg_measure, const float tolerance,
const float inseam);
// The pants_report() function will output a message to the user stating
// whether or not the pants will meet expectations.
// Pre: none
// Post: message output to the screen.
void pants_report(const bool good_enough);
int main()
{
/* ------------------ DECLARATIONS -------------------- */
string user_name;
float user_waist;
float user_leg;
float user_tolerance;
float inseam;
bool pants_good = false;
char response;
/* ----------------- GREET AND INPUT INFO -------------- */
user_name = greet();
do
{
cout<<endl;
user_waist = get_waist(user_name);
user_leg = get_leg_measure();
user_tolerance = get_tolerance(user_name);
/* -------------------- COMPUTING VALUES -------------- */
inseam = inseam_calculator(user_waist);
pants_good = judge_pants(user_leg,user_tolerance,inseam);
pants_report(pants_good);
do //repeat???
{
cout<<"\n\nWould you like to do this again? (y/n): ";
cin>>response;
} while (response != 'y' && response != 'n');
} while (response == 'y');
signoff(user_name);
return 0;
}
/* ------------------ FUNCTION DEFINITIONS --------------------- */
string greet()
{
string the_name;
cout<<"\n\n\nGlad you're using my silly software. "
"\n\tPlease enter your name: ";
cin>>the_name;
return the_name;
}
void signoff(const string name)
{
cout<<"\nThanks for using this program, "<<name<<". Enjoy your high-water"
" pants!!"<<endl;
return;
}
float get_waist(const string name)
{
float waist;
do
{
cout<<name<<", enter your waist measurement: ";
cin>>waist;
if (waist <= 0)
cout<<"ERROR: Invalid input....try again..."<<endl;
} while (waist <= MIN_WAIST);
return waist;
}
float get_leg_measure()
{
float leg_length;
do
{
cout<<"Ok, now enter the length of your leg: ";
cin>>leg_length;
} while (leg_length <= MIN_LEG_LENGTH || leg_length > MAX_LEG_LENGTH);
return leg_length;
}
float get_tolerance(const string name)
{
float tolerance;
do
{
cout<<"And, finally, "<<name<<", what is your water tolerance: ";
cin>>tolerance;
} while (tolerance < MIN_HIGHWATER_TOLERANCE);
return tolerance;
}
float inseam_calculator(const float the_waist)
{
return UNIVERSAL_WAIST_INSEAM_RATIO * the_waist;
}
bool judge_pants(const float leg_measure, const float tolerance,
const float inseam)
{
return (inseam >= (leg_measure - tolerance));
}
void pants_report(const bool good_enough)
{
if (good_enough)
cout<<"The pants are NOT high-water enough for you!"<<endl;
else
cout<<"Great pair of high-waters!!"<<endl;
return;
}