175k views
2 votes
In this lab problem we are requiring you to compute some arithmetic operations. The following equations estimate the calories burned when exercising (source): Men: Calories = ( (Age x 0.2017) — (Weight x 0.09036) + (Heart Rate x 0.6309) — 55.0969 ) x Time / 4.184 Women: Calories = ( (Age x 0.074) — (Weight x 0.05741) + (Heart Rate x 0.4472) — 20.4022 ) x Time / 4.184 Your program will input the user for age in years, weight in pounds, heart rate in beats per minute, and time in minutes, respectively. Your job is to output calories burned for men and women. Your prompts should be as follows: Enter age (years):, Enter weight (pounds):, Enter heart rate (beats per minute):, and Enter time (minutes):. The prompts must be EXACTLY as written, including the colon (:) character, or your test cases will fail. Since you are prompting the user for input, you should not enter anything into the (optional) input box below, but input your numbers after your prompts.

1 Answer

3 votes

Answer:

// program in C++.

#include <bits/stdc++.h>

using namespace std;

// function to calculate calories burned

double calories_burned(int age,int weight,int heart_rate,int time_i, char gen)

{

// variable

double calories=0;

if(gen=='m')

// calories burned by men

calories = ((age * 0.2017 )- (weight * 0.09036) + (heart_rate * 0.6309) - 55.0969) * (time_i / 4.184);

else if(gen=='f')

// calories burned by Women

calories = ((age * 0.074) - (weight * 0.05741) + (heart_rate * 0.4472) - 20.4022) * (time_i / 4.184);

// return calories burned

return calories;

}

// main function

int main()

{

// variables

int age,weight,heart_rate,time_i;

cout<<"Enter age (years):";

// read age

cin>>age;

cout<<"Enter weight (pounds):";

// read weight

cin>>weight;

cout<<"Enter heart rate (beats per minute):";

// read heart_rate

cin>>heart_rate;

cout<<"Enter time (minutes):";

// read time

cin>>time_i;

// call function for men

double men_cal=calories_burned(age,weight,heart_rate,time_i,'m');

// call function for women

double women_cal=calories_burned(age,weight,heart_rate,time_i,'f');

// print calories burned by men

cout<<"Men calories burned :"<<men_cal<<endl;

// print calories burned by Women

cout<<"Women calories burned :"<<women_cal<<endl;

return 0;

}

Step-by-step explanation:

Read age, weight, heart rate and time from user.Then call the function calories_burned() with all the input and a character parameter for men.This function will calculate the total calories burned by the men.Similarly call the function again for women, Then it will return the calories burned by women.Print the calories burned by men and women.

Output:

Enter age (years):25

Enter weight (pounds):160

Enter heart rate (beats per minute):125

Enter time (minutes):60

Men calories burned :205.791

Women calories burned :403.856

User RNA
by
5.5k points