Need help with this problem. Please write the code or give direction. ----------
ID: 3623925 • Letter: N
Question
Need help with this problem. Please write the code or give direction.--------------------------------------…
The relationship between the length of an adult's thighbone and the height of the adult can be approximated by the linear equations,
y = 0.432x - 10.44 for a female
y = 0.449x - 12.15 for a male
where y is the length of the femur (thighbone) in inches and x is the height in inches.
An anthropologist discovers the foot bones belonging to an adult male and estimates that the height of the male was 69 inches. A few feet away from the site where the foot bones were discovered, the anthropologist discovered a male adult thighbone that was 19 inches long. Is it possible that both the foot bones and the thighbone came from the same person?
You are to write a program that has the following input:
* Gender of that adult: (char type)
* A height determined by foot bone: (float type)
* Length of thighbone of an adult: (float type)
As output you must print both the input height and the calculated height (float type). Next, determine if the height based on the thighbone is consistent with the height determined by the foot bone (differs by no more than 0.5 inches in absolute value), and indicate the answer as "consistent" or "not consistent".
You will use this program to answer the question posed by the anthropologist by running her data. Your program, of course, should not be specific to this data only.
Program Specifications
A character is entered in main's logic. Next, main calls a bool-returning function to validate that the character entered is either an 'f', 'F', 'm', or 'M' to indicate the gender. You must use switch for this bool-function's selection logic. If the character is not correct this bool-function should write an error message (see "grade report program" for a guide).
The remainder of the logic, including the rest of the input values for this program, must be in a single void function. The main calls this function only if the input is valid using if-else for its selection logic. Caution: use fabs(x) from cmath, not abs(x). See Table 3.1 (page 129).
Therefore,
main: one char-variable only; if-else logic; calls two functions; asks for no calculations if data is not valid. bool checkData (char): switch logic; writes error message; returns indication that data is correct or not. void calculateReport ( char): gets remaining input; based of sex determines and prints if heights are consistent or not; requires nested if-else logic.
Notice that the formulas above do not calculate height, but instead calculate length of thigh. When determining the math formulas to calculate the heights for males and females, leave the literal constants in the expressions. Do not calculate any approximations. This is not a programming step, but a mathematics problem.
Turn In
Turn in a copy of your program. Run one example that answers the question for the anthropologist. Run the program a second time with thighbone 18 inches (same estimate of 69 inches from foot bone) as the input for a male. Finally, run a third example with 18 inches (same estimate of 69 inches from foot bone), but assume a female. Turn in a copy of each run.
Submit your materials through the Assignments section at the Bb site. You must attach the source file as a .cpp file and the output as .txt file. Do not zip these files.
Evaluation Check List:
Use only features introduced in the text or web materials to this point and consider all guidelines used for previous labs.
1. if-else logic in main
a. logic
b. indentation style
2. bool-returning valid function
a. logic (weighted 5 points)
b. style of switch
c. parameter passing
3. process function
a. selection logic
b. parameter passing
c. formula for x (male)
d. formula for x (female)
e. formula used to check consistent condition
f. condition (inequality) for decision
4. output for required test 1
5. output for required test 2
6. output for required test 3
Explanation / Answer
please rate - thanks
#include <iostream>
#include <cmath>
using namespace std;
bool checkData (char);
void calculateReport ( char);
int main()
{
char gender;
cout<<"Enter gender (M/F): ";
cin>>gender;
if(checkData(gender))
calculateReport(gender);
system("pause");
return 0;
}
bool checkData (char g)
{switch(g)
{case 'f':
case 'F':
case 'M':
case 'm': return true;
default: cout<<"Invalid entry program aborting ";
return false;
}
}
void calculateReport ( char g)
{float length,calcHeight,height,diff;
cout<<"Enter height determined by foot bone: ";
cin>>height;
cout<<"Enter length of thighbone of an adult: ";
cin>>length;
if(g=='f'||g=='F')
calcHeight=(length+10.44)/.423;
else
calcHeight=(length+12.15)/.449;
cout<<"input height: "<<height<<endl;
cout<<"calculated height: "<<calcHeight<<endl;
diff=calcHeight-height;
if(fabs(diff)<=.5)
cout<<"Data is consistant ";
else
cout<<"Data is inconsistant ";
}