Please follow the instruction in the exercise below. The program should include
ID: 3640371 • Letter: P
Question
Please follow the instruction in the exercise below. The program should include %comments, input statements, fprintf output statements, multiway path control structures like "if", "elseif", "end". Lifesaver rating will be given for step by step instructions of the program.The following are formulas for calculating the training heart rate (THR) for
men and women
For men (Karvonen formula): THR = [(220 – AGE) – RHR] × INTEN + RHR
For women: THR = [(206 – 0.88 × AGE) – RHR] × INTEN + RHR
where AGE is the person’s age, RHR the resting heart rate, and INTEN the fitness
level (0.55 for low, 0.65 for medium, and 0.8 for high fitness). Write a
program in a script file that determines the THR. The program asks users to
enter their gender (male or female), age (number), resting heart rate (number),
and fitness level (low, medium, or high). The program then displays the training
heart rate. Use the program for determining the training heart rate for the
following two individuals:
(a) A 21-years-old male, resting heart rate of 62, and low fitness level.
(b) A 19-years-old female, resting heart rate of 67, and high fitness level.
Explanation / Answer
%clearing the sreen and everything
clc,close all,clear all
%taking inputs from the user
gender=input('Enter your gender("male" or "female"): ','s');
age=input('Enter your age: ');
rhr=input('Enter your resting heart rate number: ');
fl=input('Enter your fitness level("low","medium" or "high"): ','s');
%Checking for the fitness level and accordingly assigning the
%inten level
if strcmp(fl,'low')==0 inten=0.55;
elseif strcmp(fl,'medium')==0 inten=0.65;
elseif strcmp(fl,'high')==0 inten=0.8;
end
%checking the gender and accordingly calculating the Training
%heart rate
if strcmp(gender,'male')==0 thr=[(220 - age) - rhr] * inten + rhr;
elseif strcmp(gender,'female')==0 thr=[(206 - 0.88 * age) - rhr] * inten + rhr;
end
%creating a object fid for the file "thr.txt" which will hold the Training
%heart rate
fid = fopen('thr.txt', 'w');
%prints the result into a file "thr.txt"
fprintf(fid, 'The training heart rate of a: %s age: %u having resting ',gender,age);
fprintf(fid,'heart rate number: %u and fitness level: %s is: %f',rhr,fl,thr);
fclose(fid);
%shows the file"thr.txt" in a notepad
winopen('thr.txt');