Home > Back-end >  The c subject
The c subject

Time:09-27

BMI (Body Mass Index, or BMI, English for Body Mass Index, or BMI), is to use weight in kilograms divided by height in meters square of the number, the Body Mass Index (BMI) ^ 2=weight (kg) present height (m), are commonly used to measure the degree of Body fat and a standard, whether health adults with a normal BMI between 18.5 to 23.9, so when BMI is greater than 23.9, for health is the time to lose weight!
Please define a class People, member variables defined in the class integer myWeight, members of the floating-point variables myHeight, myBMI etc., and define a member function calculateBMI () to calculate everyone's BMI, define a member function getAnswer () to determine whether need to lose weight,
Have multiple sets of data input, each person's weight (/kg), height (/m), please calculate his BMI, and whether he needs to lose weight, if need be, output "Yes!" , otherwise output "No!" Output (not including the quotes),

Input
Multiple sets of input, the two Numbers in each group on behalf of someone's weight and height,,
The Output
If you want to lose weight is output Yes! , there is No need to print the No! ,

The Sample Input
50 1.65
70
1.8080
1.75The Sample Output
No!
No!
Yes!

CodePudding user response:

The header file
 # # ifndef BMI_H_ 
# define BMI_H_
Using namespace STD.
The class BMI
{
Private:
Int myWeight;
Double myHeight;
Double myBMI;
Public:
BMI ();
BMI (int weight, double height);
Bool getAnswer ();
Void calcculateBMI ();
};

# endif

Methods to achieve
 # include & lt; Iostream> 
# include & lt; String>
# include & lt; Cmath>
# include "test. H"
Using STD: : cout;
BMI: : BMI ()
{
MyWeight=0;
MyHeight=0.0;
}
BMI: : BMI (int weight, double height)
{
MyWeight=weight;
MyHeight=height;
}
Void BMI: : calcculateBMI ()
{
MyBMI=myWeight/pow (myHeight, 2);
}
Bool BMI: : getAnswer ()
{
CalcculateBMI ();
If (myBMI & gt; 23.9)
return true;
The else
return false;
}

The main function
 # include & lt; Iostream> 
# include & lt; Vector>
# include "test. H"
Using namespace STD.
Int main ()
{
int n;
Cin & gt;> n;
vector Vec.
for (int i=0; i {
Int weight;
A double height;
Cin & gt;> Weight & gt;> Height;
BMI peo (weight, height);
Vec. Push_back (peo);
}
for (int i=0; i {
If (vec [I] getAnswer ())
Cout & lt; <"Yes!" The else
Cout & lt; <"No!" }
system("pause");
return 0;
}
  • Related