Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help me code this. The assignment contains two parts. Basal metabolic rate. Stud

ID: 3587271 • Letter: H

Question

Help me code this.

The assignment contains two parts.

Basal metabolic rate. Study "Observing Program Stack" described here. As you program your project below, demonstrate to the lab instructor observing variables local to several function frames.

Create a project titled Lab5_BMR with a single file titled bmr.cpp The program should calculate the person's Basal Metabolic Rate - the number of calories per day a person's body needs to function. Then, on the basis of calculated BMR, your program should output how many doughnuts a person can consume. A medium-size doughnut contains 195 calories.

The BMR formula is as follows:

for women:

for men:

Depending on gender, BMR should be calculated by functions bmrWomen() and bmrMen() that both accept three parameters: "weight in pounds", "height in inches" and "age in years" and return the BMR. Note that the BMR has a fractional part.

The main function should prompt the user for her gender, weight, height and age; compute the BMR and the number of doughnuts that can be consumed per day; and then output both the BMR and the number doughnuts.

The number of doughnuts is: BMR divided by the number of calories in a doughnuts. Fractional number of doughnuts can be dropped. The number of calories per doughnut (195) should be put in a named constant.

On the basis of the user's gender, main() function should decide whether to invoke bmrWomen() or bmrMen(). The user should input her height in feet and inches. The main() function should compute the total number of inches (one foot has 12 inches) and pass it to the bmr functions.

Make sure to use the bmr function prototypes and put the function definitions below the main function definition.

Figures. Create a project titled Lab5_Figures. This project shall contain multiple files. Write a program that repeatedly asks the user to select either square, left or right triangle, then inputs the figure size and then prints the appropriate shape in stars. For square, the program should ask whether the user wants a filled or a hollow square. The program should quit if the user inputs an invalid option. See an example dialog below:

You can reuse your code from the Looping lab. Place star-printing code in four separate functions: filledSquare, hollowSquare, leftTriangle and rightTriangle. Each function should accept a single integer parameter - the size of the figure and return no value (be a void-function). Create three separate files figures.cpp, figures.h, and figuresInput.cpp. Place the triangle and square function definitions in figures.cpp and their prototypes in figures.h. Make sure that the header file is protected against multiple inclusion. Place the main function in figuresInput.cpp

2-

Figures. Create a project titled Lab5_Figures. This project shall contain multiple files. Write a program that repeatedly asks the user to select either square, left or right triangle, then inputs the figure size and then prints the appropriate shape in stars. For square, the program should ask whether the user wants a filled or a hollow square. The program should quit if the user inputs an invalid option. See an example dialog below:

You can reuse your code from the Looping lab. Place star-printing code in four separate functions: filledSquare, hollowSquare, leftTriangle and rightTriangle. Each function should accept a single integer parameter - the size of the figure and return no value (be a void-function). Create three separate files figures.cpp, figures.h, and figuresInput.cpp. Place the triangle and square function definitions in figures.cpp and their prototypes in figures.h. Make sure that the header file is protected against multiple inclusion. Place the main function in figuresInput.cpp

Explanation / Answer

//File Name: bmr.cpp
#include<iostream>
using namespace std;


//Main function definition
int main()
{
//Prototype of the functions to calculate bmr for women
double bmrWomen(double wip, double hii, int aiy);
//Prototype of the functions to calculate bmr for men
double bmrMen(double wip, double hii, int aiy);
//Prototype of the functions to display information
void put(double, int);
//Constant defined for medium-size dough nut contains 195 calories
const int MAX = 195;
//To store gender
char gender;
//To store weight, height and calculated calories
double weight, height, calories;
//To store age
int age;
//To store calculate number of dough nuts per day
int doughnut;
//Accepts user data from the user
cout<<" Enter the wight in pound: ";
cin>>weight;
cout<<" Enter the height in foot: ";
cin>>height;
cout<<" Enter the age: ";
cin>>age;
cout<<" Enter the gender (m/f): ";
cin>>gender;
//Converts height in foot to inches
height = height * 12;
//Checks if the gender is 'M' or 'm' then calls the bmrMen function and stores the calculates calories
if(gender == 'M' || gender == 'm')
calories = bmrMen(weight, height, age);
//Checks if the gender is 'f' or 'f' then calls the bmrWomen function and stores the calculates calories
else if(gender == 'F' || gender == 'f')
calories = bmrWomen(weight, height, age);
//Otherwise display error message
else
cout<<" Invalid gender!";
//Calculates number of dough nuts per day
doughnut = calories / MAX;
//Calls the function to display result
put(calories, doughnut);

}//End of function

//Function to bmr and dough nuts value
void put(double bmr, int nut)
{
cout<<" BMR: "<<bmr;
cout<<" Number of dough nuts that can be consumed per day: "<<nut;
}//End of function

//Function definition for BMR Women
double bmrWomen(double wip, double hii, int aiy)
{
//To store BMR for women
double bmrM;
//Calculates BMR women
bmrM = 655 + (4.3 * wip) + (4.7 * hii) - (4.7 * aiy);
//Returns BMR for women
return bmrM;
}//End of function

//Function definition for BMR men
double bmrMen(double wip, double hii, int aiy)
{
//To store BMR for men
double bmrW;
//Calculates BMR men
bmrW = 66 + (6.3 * wip) + (12.9 * hii) - (6.8 * aiy);
//Returns BMR for men
return bmrW;
}//End of function

Sample Run 1:

Enter the wight in pound: 45

Enter the height in foot: 5

Enter the age: 40

Enter the gender (m/f): M
BMR: 851.5
Number of dough nuts that can be consumed per day: 4

Sample Run 2:

Enter the wight in pound: 56

Enter the height in foot: 4

Enter the age: 32

Enter the gender (m/f): f
BMR: 971
Number of dough nuts that can be consumed per day: 4

Second program

//File Name: figures.h
#ifndef figures_h
#define figures_h
//Prototype for the function to display fill square with star
void filledSquare(int);
//Prototype for the function to display hollow square with star
void hollowSquare(int);
//Prototype for the function to display left triangle with star
void leftTriangle(int);
//Prototype for the function to display right triangle with star
void rightTriangle(int);

#endif

//File Name: figures.cpp
#include "figures.h"
#include <iostream>
using namespace std;
//Function to display fill square with star
void filledSquare(int n)
{
//Loops row till n - 1
for(int r = 0; r < n; r++)
{
//Loops column till n - 1
for(int c = 0; c < n; c++)
{
cout<<"* ";
}//End of inner for loop
//Displays new line
cout<<endl;
}//End of outer for loop
}//End of function

//Function to display hollow square with star
void hollowSquare(int n)
{
//Loops row till n - 1
for(int r = 0; r < n; r++)
{
//Loops column till n - 1
for(int c = 0; c < n; c++)
{

//Checks if it is first row or last row
if(r == 0 || r == n-1)
cout<<"* ";
//Checks if it is first column or last column
else if(c == 0 || c == n-1)
cout<<"* ";
else
cout<<" ";
}//End of inner for loop
//Displays new line
cout<<endl;
}//End of outer for loop
}//End of function

//Function to display left triangle with star
void leftTriangle(int n)
{
//Loops row till n - 1
for(int r = n; r >= 1; r--)
{
//Loops column till n - 1
for(int c = r; c >= 1; c--)
{
cout<<"* ";
}//End of inner for loop
//Displays new line
cout<<endl;
}//End of outer for loop
}//End of function

//Function to display right triangle with star
void rightTriangle(int n)
{
//Loops row till n - 1
for(int r = n; r >= 1; r--)
{
//Loops r to n - 1 to display space
for(int s = r; s < n; s++)
cout<<" ";
//Loops column till n - 1
for(int c = r; c >= 1; c--)
{
cout<<"* ";
}//End of inner for loop
//Displays new line
cout<<endl;
}//End of outer for loop
}//End of function

//File Name: figuresInput.cpp
#include<iostream>
#include "figures.cpp"
using namespace std;

//Displays menu and accepts user choice
void menu(int &figure, int &size, char &choice)
{
//Displays menu
cout<<" 1. square";
cout<<" 2. top left triangle";
cout<<" 3. top right triangle";
//Accepts user data
cout<<" select figure: ";
cin>>figure;
cout<<" select size: ";
cin>>size;
//Checks if figure is one then asks for fill or hollow
if(figure == 1)
{
cout<<" filled or hollow [f/h]: ";
cin>>choice;
}//End of if
}//End of function

//Main function definition
int main()
{
int figure, size;
char choice;
//Calls function to displays menu
menu(figure, size, choice);
//Checks if figure is one and choice is 'f' or 'F'
if(figure == 1 && (choice == 'f' || choice == 'F'))
//Calls the function to displays fill square
filledSquare(size);
//Checks if figure is one and choice is 'h' or 'H'
else if(figure == 1 && (choice == 'h' || choice == 'H'))
//Calls the function to displays hollow square
hollowSquare(size);
//Checks if figure is two
else if(figure == 2)
//Calls the function to displays left triangle
leftTriangle(size);
//Checks if figure is three
else if(figure == 3)
//Calls the function to displays right triangle
rightTriangle(size);
else
cout<<" Invalid Choice! ";
}//End of main function

Sample Run 1:

1. square
2. top left triangle
3. top right triangle
select figure: 5

select size: 6

Invalid Choice!

Sample Run 2:

1. square
2. top left triangle
3. top right triangle
select figure: 1

select size: 6

filled or hollow [f/h]: f
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *

Sample Run 3:

1. square
2. top left triangle
3. top right triangle
select figure: 1

select size: 8

filled or hollow [f/h]: h
* * * * * * * *
* *
* *
* *
* *
* *
* *
* * * * * * * *

Sample Run 4:


1. square
2. top left triangle
3. top right triangle
select figure: 2

select size: 10
* * * * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*

Sample Run 5:


1. square
2. top left triangle
3. top right triangle
select figure: 3

select size: 7
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*