Write a class called “client”.
Your client class will have the following private data members:
• A string for the client’s first name
• A string for the client’s last name
• A float for the client’s height in inches
• An int for the client’s weight in pounds
• A float for the client’s body mass index (BMI)
• An int for the client’s calorie requirements
• A char for the client’s gender
Your client class will have the following public member functions:
A constructor that accepts 5 arguments. The 5 arguments represent the client’s 1) first name (string), 2) last name (string), 3) height (float), 4) weight (int), and 5) gender (char). The values for these parameters will be passed from main upon the creation of the client object, and your constructor will use those values to initialize the appropriate private data members.
A member function that will calculate the BMI. This function will accept no arguments and will have a return type of void. The function will calculate the BMI using the formula on the next page and based on the height and weight private data members.
Body mass index (BMI) formula:
BMI = (weight / (height * height))*703
Where weight is the client’s weight in pounds, and height is the client’s height in inches.
A function that will calculate a client’s calorie requirements. This function will accept no arguments and will have a return type of void. Calorie requirements are the number of calories a client needs to ingest daily in order to maintain his/her current weight. Your function will calculate the calorie requirements based on the weight and gender data members and using the criteria below.
Criteria for Calorie Requirements (assuming moderate activity level for all clients)
--For a female: 18 calories per pound of body weight
--For a male: 21 calories per pound of body weight
A function to print the client’s information. This function will accept no arguments and will have a return type of void. It will print the client’s full name, gender, height, weight, BMI, and calorie requirements. Additionally, this function will print a statement about the client’s BMI based on the table below (e.g. “Your BMI falls within the optimal range”). If a client’s BMI is below or exceeding optimal range, advise him/her to make an appointment with the nutritionist.
In main, first ask the user for the client’s 1) first name, 2) last name, 3) gender, 4) height in inches, and 5) weight in pounds. After you have obtained these values, create a client object and pass the values as arguments, thus executing the 5 argument constructor. Once the object has been created, you can invoke the member functions to calculate the BMI, calculate the calorie requirements, and lastly, print the client’s information.
I'm having trouble figuring out how to return my bmi and calorie calculation back into my main function with no arguments.
I've tried using
"return bmi;"
"{return bmi;}" Next to the function also
If there is any other problem with my program please let me know, much appreciated.
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
|
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class client
{
private:
string FirstName;
string LastName;
float height;
int weight;
float bmi;
int calories;
char gender;
public:
client(){}
client(string f, string l, float h, int w, char g)
{
FirstName = f;
LastName = l;
height = h;
weight = w;
gender = g;
}
void ClientInfo(string f, string l, float h, int w, char g)
{
FirstName = f;
LastName = l;
height = h;
weight = w;
gender = g;
}
void BMI()
{
bmi = (weight / (height * height)) * 703;
}
void Calorie()
{
if (gender == 'm' || gender == 'M')
{
calories = (weight * 21);
}
else if (gender == 'f' || gender == 'F')
{
calories = (weight * 18);
}
return;
}
void Information()
{
if (bmi <= 18.5)
{
cout << FirstName << LastName << " your BMI is " << bmi << endl;
cout << "Your BMI fall below Optimal Range " << endl;
cout << "Please schedule an appiontment with nutritionist" << endl;
}
else if (bmi >= 18.5 && bmi <= 24.9)
{
cout << FirstName << LastName << " your BMI is " << bmi << endl;
cout << "Your BMI is Optimal Range" << endl;
}
else (bmi >= 25);
{
cout << FirstName << LastName << " your BMI is " << bmi << endl;
cout << "Your BMI exceeds Optimal Range" << endl;
cout << "Please schedule an appiontment with nutritionist" << endl;
}
}
};
int main()
{
client Info[5];
string FirstName;
string LastName;
float height;
int weight;
float bmi = 0;
int calories = 0;
char gender;
client c1("", "", 0, 0, 'g');
c1.BMI();
cout << "Enter client's First Name: ";
cin >> FirstName;
cout << "Enter client's Last Name: ";
cin >> LastName;
cout << "Enter client's Gender (m/f): ";
cin >> gender;
cout << "Enter " << FirstName << "'s height in inches: ";
cin >> height;
cout << "Enter " << FirstName << "'s weight in pounds: ";
cin >> weight;
cout << endl << endl << "Client's Name: " << FirstName << " " << LastName << endl;
cout << "Gender: " << gender << endl;
cout << "Height in inches: " << height << endl;
cout << "Weight in pounds: " << weight << endl;
cout << "Calorie Requirmemnt: " << calories << endl;
cout << "Body Mass Index: " << bmi << endl;
c1.Calorie();
c1.Information();
system("PAUSE");
return 0;
}
|