Deitel & Deitel, C How to Program 6th Edition, Exercise 10.21 (Computerization of Health Records)
// 10.21 (Computerization of Health Records)
#include <stdio.h>
int ageCalculator(int, int, int, int, int, int);
void heartRateCalculator(int, int *, int *, int *);
float bmiCalculator(int, int);
typedef enum gender { MALE, FEMALE } Gender;
typedef struct currentDate { int year; int day; int month; } CurrentDate;
typedef struct birthday { int year; int day; int month; } Birthday;
typedef struct healthProfile { // a person's basic health variables
char *firstName;
char *lastName;
Gender sex;
int height; //in inches
int weight; // in pounds
Birthday birthday;
CurrentDate currentDate;
int age;
int maxHeartRate; // highest heart rate
int targetHeartRateLow, targetHeartRateHigh;
float BMI;
} HealthProfile;
int main() {
HealthProfile person;
person.firstName = "Ugur"; // Person's data
person.lastName = "Damar";
person.sex = MALE;
person.height = 74;
person.weight = 220;
person.birthday.year = 1995;
person.birthday.day = 18;
person.birthday.month = 3;
person.currentDate.year = 2018;
person.currentDate.month = 6;
person.currentDate.day = 5;
person.age = ageCalculator(person.currentDate.month,
person.birthday.month, person.currentDate.day,
person.birthday.day, person.currentDate.year,
person.birthday.year);
heartRateCalculator(person.age, &person.maxHeartRate,
&person.targetHeartRateLow, &person.targetHeartRateHigh);
person.BMI = bmiCalculator(person.weight, person.height);
printf("First Name: %s\n", person.firstName);
printf("Last Name: %s\n", person.lastName);
printf("Sex: %s\n", person.sex ? "Female" : "Male");
printf("Height: %d (Inches)\n", person.height);
printf("Weight: %d (Pounds)\n", person.weight);
printf("Age: %d\n\n", person.age);
printf("Person's max heart rate is: %d bpm\n", person.maxHeartRate);
printf("Person's target heart rate range is between %d-%d bpm\n",
person.targetHeartRateLow, person.targetHeartRateHigh);
printf("Person's BMI value: %f\n", person.BMI);
printf("\nBMI VALUES\n");
printf("Underweight: less than 18.5\n");
printf("Normal : between 18.5 and 24.9\n");
printf("Overweight : between 25 and 29.9\n");
printf("Obese : 30 or greater\n");
printf("\n\n\n");
return 0;
}
//Age calculater takes current date and birthday to calculate age
int ageCalculator(int month, int bmonth, int day, int bday,
int year, int byear) {
int age;
if (month > bmonth || (month == bmonth && day >= bday))
age = year - byear;
else
age = year - byear - 1;
return age;
}
/* Heart rate calculater calculates maximum heart rate and
the necessary heart rate range call by reference */
void heartRateCalculator(int age, int *max, int *targetLow, int *targetHigh) {
*max = 220 - age;
*targetLow = *max / 2;
*targetHigh = *max * 0.85;
}
// BMI calculater takes weight in lb and height in inchesand calculates the BMI in kg/m^2
float bmiCalculator(int weight, int height) {
return (float) weight / height / height * 703;
}
OUTPUT
First Name: Ugur
Last Name: Damar
Sex: Male
Height: 74 (Inches)
Weight: 220 (Pounds)
Age: 23
Person's max heart rate is: 197 bpm
Person's target heart rate range is between 98-167 bpm
Person's BMI value: 28.243240
BMI VALUES
Underweight: less than 18.5
Normal : between 18.5 and 24.9
Overweight : between 25 and 29.9
Obese : 30 or greater
Press any key to continue . . .
#include <stdio.h>
int ageCalculator(int, int, int, int, int, int);
void heartRateCalculator(int, int *, int *, int *);
float bmiCalculator(int, int);
typedef enum gender { MALE, FEMALE } Gender;
typedef struct currentDate { int year; int day; int month; } CurrentDate;
typedef struct birthday { int year; int day; int month; } Birthday;
typedef struct healthProfile { // a person's basic health variables
char *firstName;
char *lastName;
Gender sex;
int height; //in inches
int weight; // in pounds
Birthday birthday;
CurrentDate currentDate;
int age;
int maxHeartRate; // highest heart rate
int targetHeartRateLow, targetHeartRateHigh;
float BMI;
} HealthProfile;
int main() {
HealthProfile person;
person.firstName = "Ugur"; // Person's data
person.lastName = "Damar";
person.sex = MALE;
person.height = 74;
person.weight = 220;
person.birthday.year = 1995;
person.birthday.day = 18;
person.birthday.month = 3;
person.currentDate.year = 2018;
person.currentDate.month = 6;
person.currentDate.day = 5;
person.age = ageCalculator(person.currentDate.month,
person.birthday.month, person.currentDate.day,
person.birthday.day, person.currentDate.year,
person.birthday.year);
heartRateCalculator(person.age, &person.maxHeartRate,
&person.targetHeartRateLow, &person.targetHeartRateHigh);
person.BMI = bmiCalculator(person.weight, person.height);
printf("First Name: %s\n", person.firstName);
printf("Last Name: %s\n", person.lastName);
printf("Sex: %s\n", person.sex ? "Female" : "Male");
printf("Height: %d (Inches)\n", person.height);
printf("Weight: %d (Pounds)\n", person.weight);
printf("Age: %d\n\n", person.age);
printf("Person's max heart rate is: %d bpm\n", person.maxHeartRate);
printf("Person's target heart rate range is between %d-%d bpm\n",
person.targetHeartRateLow, person.targetHeartRateHigh);
printf("Person's BMI value: %f\n", person.BMI);
printf("\nBMI VALUES\n");
printf("Underweight: less than 18.5\n");
printf("Normal : between 18.5 and 24.9\n");
printf("Overweight : between 25 and 29.9\n");
printf("Obese : 30 or greater\n");
printf("\n\n\n");
return 0;
}
//Age calculater takes current date and birthday to calculate age
int ageCalculator(int month, int bmonth, int day, int bday,
int year, int byear) {
int age;
if (month > bmonth || (month == bmonth && day >= bday))
age = year - byear;
else
age = year - byear - 1;
return age;
}
/* Heart rate calculater calculates maximum heart rate and
the necessary heart rate range call by reference */
void heartRateCalculator(int age, int *max, int *targetLow, int *targetHigh) {
*max = 220 - age;
*targetLow = *max / 2;
*targetHigh = *max * 0.85;
}
// BMI calculater takes weight in lb and height in inchesand calculates the BMI in kg/m^2
float bmiCalculator(int weight, int height) {
return (float) weight / height / height * 703;
}
OUTPUT
First Name: Ugur
Last Name: Damar
Sex: Male
Height: 74 (Inches)
Weight: 220 (Pounds)
Age: 23
Person's max heart rate is: 197 bpm
Person's target heart rate range is between 98-167 bpm
Person's BMI value: 28.243240
BMI VALUES
Underweight: less than 18.5
Normal : between 18.5 and 24.9
Overweight : between 25 and 29.9
Obese : 30 or greater
Press any key to continue . . .
Let me know in the comments if this page helped you somehow.
It is nice to know if my work helped someone, thanks :)
Comments
Post a Comment