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

In C, a batch-processing code that reads in (from a file) patient data: name, ag

ID: 3575929 • Letter: I

Question

In C, a batch-processing code that reads in (from a file) patient data: name, age, sex, height, weight, activity level, systolic and diastolic blood pressure, then computes four parameters: pulse pressure (=SBP-DBP), BMI, BMR, and CRA, then writes each complete data set to an output file, checking for errors along the way. This will comprise a main function and a number of other functions. Formulas for BMR and CMR BMR = If Male, 66 + ( 6.23 x Weight ) + ( 12.7 x Height ) - ( 6.8 x Age ) If Female, 655 + ( 4.35 x Weight ) + ( 4.7 x Height ) - ( 4.7 x Age ) CMA = For sedentary, BMR x 1.2 For Lightly Active, BMR x 1.375 For Moderately Active, BMR x 1.55 For Very Active, BMR x 1.725 For Extra Active, BMR x 1.9
Data Structures
All patient data - from input or computed - should be stored in a structure. I'll call this the primary structure below. Since there will be multiple patients to process, the primary structure will need to be an array, one entry per patient data set. Taking this a step further, rather than passing this whole structure (which is a fairly big group of variables - 10 entries - per patient) by value, we'll pass it by reference. That is, when we send individual entries of this structure array to subfunctions (that is, functions other than main), we'll pass pointers to those structures, and those functions will (sometimes) return pointers as well.
Taking this to the next logical step, this means that main will contain a pointer pointer to our primary data structure, which again, will contain all input and computed data for each patient. So the first thing main can do is: malloc pointers for this single pointer pointer. Later, a function will return data for each pointer (which will point to a primary structure for each unique patient) as data is processed.

Overall Code Sequence
First, main will need to declare variables and allocate space for those that need space. Above main, you can use macros to define character strings for the three files you intend to interact with.
Main should first open three files: one for input, one for output, one for error messages. You should write a function called by main that takes three filenames (character strings), checks to makes sure all three opened correctly, and returns three FILE streams in a structure to main. If any of the fopens fail, it should return an appropriate value in at least one of the FILE streams such that main can detect this failure and exit gracefully with an error message
Main should then call another function to read in data from the input file. This function should use formatted text reading (fscanf) to read in each patient input data set and store it as one entry in the primary structure array (this will be a loop). To do this, it should malloc space for the primary structure, then return a pointer to that structure to main. Meanwhile, as noted above, main needs to have an array pointer that receives this data. Finally, and when this function returns an appropriate value, say -1 in the name string, main should recognize that the input file is exhausted, report how many datasets were read, and move on to the next step.
Main should then call yet another function to compute pulse pressure, BMI, BMR, and CRA. To do this, it needs to be passed the pointer to the primary structure that it received in the previous step (one by one - it will be called within a loop in main) and return another pointer to another, second structure (containing the four computed values) for each patient, again to be contained within the primary structure. So: the primary structure contains the input values, and a pointer to another structure that contains the computed values. This function returns that secondary pointer, memory for which which is malloc'd in the function, and points to the computed data. Within the function itself, use switch/case statements to use the integer values of Sex or Activity Level to compute appropriate values for BMR and CRA. Have default cases for each were BMR or CRA are set to zero in case the input variables are incorrectly set.
Main should then again loop through the total data - input and computed - and either 1) write them to the output file (formatted write, make it pretty) or 2) if something seems amiss, write an error condition to the error file.
For the output function, print out all input and computed values. Also use switch/case statements to print out appropriate statements for BMI and activity level as you have done previously in MATLAB. For example, for BMI note "underweight", "normal", etc., and for activity level, print out the actual description of the activity level, rather than the integer indicator.
For the error function, error conditions include: diastolic pressure less than 50; systolic pressure greater than 130; pulse pressure greater than 60; BMI > 10 or < 45; BMR < 500 or > 5000; and CRA < 600 or > 11,400. Print out to the error file the patient name and exactly what was out of bounds, including their numeric values (for example, note that DBP is low and it was 20; SBP is high and is 160; BMI is low and is 5; etc).
Main should then call a function to close all three files; this function should return a value to indicate if the fclose calls were successful, and main should respond appropriately to this returned value.
Input File and Description
The input file is here; input values Fred 65. 140. 1 29 1 120 80 Elle 64. 120. 2 22 6 115 82 Jenny 76. 43. 1 65 2 103 44 Sid 86. 212. 1 85 2 152 40 Betty 61. 128. 2 57 1 145 90 Kevin 74. 183. 1 49 3 125 73 Cathy 69. 155. 2 27 1 127 89 Bob 55. 210. 0 10 2 111 74 Bill 88. 233. 1 12 3 128 52 Maria 51. 98. 2 13 5 118 82 Enry 44. 22. 1 11 4 85 44 Tom 75. 195. 1 26 4 103 61 Angela 66. 132. 2 41 2 123 79 Amy 49. 88. 2 11 3 104 68 Laura 59. 98. 2 71 1 122 76 Scott 68. 140. 1 32 4 117 81 Frank 66. 170. 1 45 2 140 100 Mary 62. 125. 2 35 4 120 90 Lisa 67. 118. 2 24 3 124 81 Jill 63. 120. 2 30 4 110 95 Dave 70. 180. 1 44 2 130 65
Name Height Weight Sex Age Activity_Level SBP DSP
Where:
Name is a character string (up to 20 characters) Age, SBP, DSP are all integer values. Height and Weight can be integers or floating point values, as long as the correct type is used to compute BMI. Sex is an integer 1 = male, 2 = female (or reverse if you prefer) Activity level is an integer 1, 2, 3, 4, 5. Note there will be errors in the given input file. Your code needs to catch them as specified above. For now, your input file can be a one line file with the line:
Kendall 73 175 1 45 3 105 70 Or you can write your own, as you see fit ;-) In C, a batch-processing code that reads in (from a file) patient data: name, age, sex, height, weight, activity level, systolic and diastolic blood pressure, then computes four parameters: pulse pressure (=SBP-DBP), BMI, BMR, and CRA, then writes each complete data set to an output file, checking for errors along the way. This will comprise a main function and a number of other functions. Formulas for BMR and CMR BMR = If Male, 66 + ( 6.23 x Weight ) + ( 12.7 x Height ) - ( 6.8 x Age ) If Female, 655 + ( 4.35 x Weight ) + ( 4.7 x Height ) - ( 4.7 x Age ) CMA = For sedentary, BMR x 1.2 For Lightly Active, BMR x 1.375 For Moderately Active, BMR x 1.55 For Very Active, BMR x 1.725 For Extra Active, BMR x 1.9
Data Structures
All patient data - from input or computed - should be stored in a structure. I'll call this the primary structure below. Since there will be multiple patients to process, the primary structure will need to be an array, one entry per patient data set. Taking this a step further, rather than passing this whole structure (which is a fairly big group of variables - 10 entries - per patient) by value, we'll pass it by reference. That is, when we send individual entries of this structure array to subfunctions (that is, functions other than main), we'll pass pointers to those structures, and those functions will (sometimes) return pointers as well.
Taking this to the next logical step, this means that main will contain a pointer pointer to our primary data structure, which again, will contain all input and computed data for each patient. So the first thing main can do is: malloc pointers for this single pointer pointer. Later, a function will return data for each pointer (which will point to a primary structure for each unique patient) as data is processed.

Overall Code Sequence
First, main will need to declare variables and allocate space for those that need space. Above main, you can use macros to define character strings for the three files you intend to interact with.
Main should first open three files: one for input, one for output, one for error messages. You should write a function called by main that takes three filenames (character strings), checks to makes sure all three opened correctly, and returns three FILE streams in a structure to main. If any of the fopens fail, it should return an appropriate value in at least one of the FILE streams such that main can detect this failure and exit gracefully with an error message
Main should then call another function to read in data from the input file. This function should use formatted text reading (fscanf) to read in each patient input data set and store it as one entry in the primary structure array (this will be a loop). To do this, it should malloc space for the primary structure, then return a pointer to that structure to main. Meanwhile, as noted above, main needs to have an array pointer that receives this data. Finally, and when this function returns an appropriate value, say -1 in the name string, main should recognize that the input file is exhausted, report how many datasets were read, and move on to the next step.
Main should then call yet another function to compute pulse pressure, BMI, BMR, and CRA. To do this, it needs to be passed the pointer to the primary structure that it received in the previous step (one by one - it will be called within a loop in main) and return another pointer to another, second structure (containing the four computed values) for each patient, again to be contained within the primary structure. So: the primary structure contains the input values, and a pointer to another structure that contains the computed values. This function returns that secondary pointer, memory for which which is malloc'd in the function, and points to the computed data. Within the function itself, use switch/case statements to use the integer values of Sex or Activity Level to compute appropriate values for BMR and CRA. Have default cases for each were BMR or CRA are set to zero in case the input variables are incorrectly set.
Main should then again loop through the total data - input and computed - and either 1) write them to the output file (formatted write, make it pretty) or 2) if something seems amiss, write an error condition to the error file.
For the output function, print out all input and computed values. Also use switch/case statements to print out appropriate statements for BMI and activity level as you have done previously in MATLAB. For example, for BMI note "underweight", "normal", etc., and for activity level, print out the actual description of the activity level, rather than the integer indicator.
For the error function, error conditions include: diastolic pressure less than 50; systolic pressure greater than 130; pulse pressure greater than 60; BMI > 10 or < 45; BMR < 500 or > 5000; and CRA < 600 or > 11,400. Print out to the error file the patient name and exactly what was out of bounds, including their numeric values (for example, note that DBP is low and it was 20; SBP is high and is 160; BMI is low and is 5; etc).
Main should then call a function to close all three files; this function should return a value to indicate if the fclose calls were successful, and main should respond appropriately to this returned value.
Input File and Description
The input file is here; input values Fred 65. 140. 1 29 1 120 80 Elle 64. 120. 2 22 6 115 82 Jenny 76. 43. 1 65 2 103 44 Sid 86. 212. 1 85 2 152 40 Betty 61. 128. 2 57 1 145 90 Kevin 74. 183. 1 49 3 125 73 Cathy 69. 155. 2 27 1 127 89 Bob 55. 210. 0 10 2 111 74 Bill 88. 233. 1 12 3 128 52 Maria 51. 98. 2 13 5 118 82 Enry 44. 22. 1 11 4 85 44 Tom 75. 195. 1 26 4 103 61 Angela 66. 132. 2 41 2 123 79 Amy 49. 88. 2 11 3 104 68 Laura 59. 98. 2 71 1 122 76 Scott 68. 140. 1 32 4 117 81 Frank 66. 170. 1 45 2 140 100 Mary 62. 125. 2 35 4 120 90 Lisa 67. 118. 2 24 3 124 81 Jill 63. 120. 2 30 4 110 95 Dave 70. 180. 1 44 2 130 65
Name Height Weight Sex Age Activity_Level SBP DSP
Where:
Name is a character string (up to 20 characters) Age, SBP, DSP are all integer values. Height and Weight can be integers or floating point values, as long as the correct type is used to compute BMI. Sex is an integer 1 = male, 2 = female (or reverse if you prefer) Activity level is an integer 1, 2, 3, 4, 5. Note there will be errors in the given input file. Your code needs to catch them as specified above. For now, your input file can be a one line file with the line:
Kendall 73 175 1 45 3 105 70 Or you can write your own, as you see fit ;-) In C, a batch-processing code that reads in (from a file) patient data: name, age, sex, height, weight, activity level, systolic and diastolic blood pressure, then computes four parameters: pulse pressure (=SBP-DBP), BMI, BMR, and CRA, then writes each complete data set to an output file, checking for errors along the way. This will comprise a main function and a number of other functions. Formulas for BMR and CMR BMR = If Male, 66 + ( 6.23 x Weight ) + ( 12.7 x Height ) - ( 6.8 x Age ) If Female, 655 + ( 4.35 x Weight ) + ( 4.7 x Height ) - ( 4.7 x Age ) CMA = For sedentary, BMR x 1.2 For Lightly Active, BMR x 1.375 For Moderately Active, BMR x 1.55 For Very Active, BMR x 1.725 For Extra Active, BMR x 1.9 BMR = If Male, 66 + ( 6.23 x Weight ) + ( 12.7 x Height ) - ( 6.8 x Age ) If Female, 655 + ( 4.35 x Weight ) + ( 4.7 x Height ) - ( 4.7 x Age ) CMA = For sedentary, BMR x 1.2 For Lightly Active, BMR x 1.375 For Moderately Active, BMR x 1.55 For Very Active, BMR x 1.725 For Extra Active, BMR x 1.9
Data Structures
All patient data - from input or computed - should be stored in a structure. I'll call this the primary structure below. Since there will be multiple patients to process, the primary structure will need to be an array, one entry per patient data set. Taking this a step further, rather than passing this whole structure (which is a fairly big group of variables - 10 entries - per patient) by value, we'll pass it by reference. That is, when we send individual entries of this structure array to subfunctions (that is, functions other than main), we'll pass pointers to those structures, and those functions will (sometimes) return pointers as well.
Taking this to the next logical step, this means that main will contain a pointer pointer to our primary data structure, which again, will contain all input and computed data for each patient. So the first thing main can do is: malloc pointers for this single pointer pointer. Later, a function will return data for each pointer (which will point to a primary structure for each unique patient) as data is processed.

Overall Code Sequence
First, main will need to declare variables and allocate space for those that need space. Above main, you can use macros to define character strings for the three files you intend to interact with.
Main should first open three files: one for input, one for output, one for error messages. You should write a function called by main that takes three filenames (character strings), checks to makes sure all three opened correctly, and returns three FILE streams in a structure to main. If any of the fopens fail, it should return an appropriate value in at least one of the FILE streams such that main can detect this failure and exit gracefully with an error message
Main should then call another function to read in data from the input file. This function should use formatted text reading (fscanf) to read in each patient input data set and store it as one entry in the primary structure array (this will be a loop). To do this, it should malloc space for the primary structure, then return a pointer to that structure to main. Meanwhile, as noted above, main needs to have an array pointer that receives this data. Finally, and when this function returns an appropriate value, say -1 in the name string, main should recognize that the input file is exhausted, report how many datasets were read, and move on to the next step.
Main should then call yet another function to compute pulse pressure, BMI, BMR, and CRA. To do this, it needs to be passed the pointer to the primary structure that it received in the previous step (one by one - it will be called within a loop in main) and return another pointer to another, second structure (containing the four computed values) for each patient, again to be contained within the primary structure. So: the primary structure contains the input values, and a pointer to another structure that contains the computed values. This function returns that secondary pointer, memory for which which is malloc'd in the function, and points to the computed data. Within the function itself, use switch/case statements to use the integer values of Sex or Activity Level to compute appropriate values for BMR and CRA. Have default cases for each were BMR or CRA are set to zero in case the input variables are incorrectly set.
Main should then again loop through the total data - input and computed - and either 1) write them to the output file (formatted write, make it pretty) or 2) if something seems amiss, write an error condition to the error file.
For the output function, print out all input and computed values. Also use switch/case statements to print out appropriate statements for BMI and activity level as you have done previously in MATLAB. For example, for BMI note "underweight", "normal", etc., and for activity level, print out the actual description of the activity level, rather than the integer indicator.
For the error function, error conditions include: diastolic pressure less than 50; systolic pressure greater than 130; pulse pressure greater than 60; BMI > 10 or < 45; BMR < 500 or > 5000; and CRA < 600 or > 11,400. Print out to the error file the patient name and exactly what was out of bounds, including their numeric values (for example, note that DBP is low and it was 20; SBP is high and is 160; BMI is low and is 5; etc).
Main should then call a function to close all three files; this function should return a value to indicate if the fclose calls were successful, and main should respond appropriately to this returned value.
Input File and Description
The input file is here; input values Fred 65. 140. 1 29 1 120 80 Elle 64. 120. 2 22 6 115 82 Jenny 76. 43. 1 65 2 103 44 Sid 86. 212. 1 85 2 152 40 Betty 61. 128. 2 57 1 145 90 Kevin 74. 183. 1 49 3 125 73 Cathy 69. 155. 2 27 1 127 89 Bob 55. 210. 0 10 2 111 74 Bill 88. 233. 1 12 3 128 52 Maria 51. 98. 2 13 5 118 82 Enry 44. 22. 1 11 4 85 44 Tom 75. 195. 1 26 4 103 61 Angela 66. 132. 2 41 2 123 79 Amy 49. 88. 2 11 3 104 68 Laura 59. 98. 2 71 1 122 76 Scott 68. 140. 1 32 4 117 81 Frank 66. 170. 1 45 2 140 100 Mary 62. 125. 2 35 4 120 90 Lisa 67. 118. 2 24 3 124 81 Jill 63. 120. 2 30 4 110 95 Dave 70. 180. 1 44 2 130 65 Fred 65. 140. 1 29 1 120 80 Elle 64. 120. 2 22 6 115 82 Jenny 76. 43. 1 65 2 103 44 Sid 86. 212. 1 85 2 152 40 Betty 61. 128. 2 57 1 145 90 Kevin 74. 183. 1 49 3 125 73 Cathy 69. 155. 2 27 1 127 89 Bob 55. 210. 0 10 2 111 74 Bill 88. 233. 1 12 3 128 52 Maria 51. 98. 2 13 5 118 82 Enry 44. 22. 1 11 4 85 44 Tom 75. 195. 1 26 4 103 61 Angela 66. 132. 2 41 2 123 79 Amy 49. 88. 2 11 3 104 68 Laura 59. 98. 2 71 1 122 76 Scott 68. 140. 1 32 4 117 81 Frank 66. 170. 1 45 2 140 100 Mary 62. 125. 2 35 4 120 90 Lisa 67. 118. 2 24 3 124 81 Jill 63. 120. 2 30 4 110 95 Dave 70. 180. 1 44 2 130 65
Name Height Weight Sex Age Activity_Level SBP DSP
Where:
Name is a character string (up to 20 characters) Age, SBP, DSP are all integer values. Height and Weight can be integers or floating point values, as long as the correct type is used to compute BMI. Sex is an integer 1 = male, 2 = female (or reverse if you prefer) Activity level is an integer 1, 2, 3, 4, 5. Note there will be errors in the given input file. Your code needs to catch them as specified above. For now, your input file can be a one line file with the line:
Kendall 73 175 1 45 3 105 70 Or you can write your own, as you see fit ;-)

Explanation / Answer

Given below is the code for the question along with ouput

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#define INPUT_FILE "patients.txt"

#define OUTPUT_FILE "patients-out.txt"

#define ERROR_FILE "patients-err.txt"

#define MAX_REC 100

typedef struct{

FILE *input;

FILE *output;

FILE *error;

int error_flag;

char err_msg[512];

}Files;

typedef struct{

int pulse_pressure;

double BMI;

double BMR;

double CMR;

}Calculated;

typedef struct{

char name[21];

int age;

int sex;

double height;

double weight;

int activity_level;

int SBP;

int DSP;

Calculated *computed;

}Patient;

Files OpenFiles(char *inputFname , char *outputFname, char *errFname);

Patient* ReadFromFile(FILE *fp);

Calculated* Calculate(Patient *p);

int LogError(Patient* p, FILE *fp);

int main()

{

Files files;

Patient **patients, *p;

int count = 0, i;

double val;

  

files = OpenFiles(INPUT_FILE, OUTPUT_FILE, ERROR_FILE);

if(files.error_flag)

{

printf(" %s", files.err_msg);

exit(1);

}

  

//allcoate space for array of pointers

patients = (Patient **) malloc(sizeof(Patient *) * MAX_REC);

  

//read all records

while(1)

{

p = ReadFromFile(files.input);

if(strcmp(p->name, "-1") == 0) //end of file

break;

patients[count++] = p;

}

fclose(files.input);

  

printf("Loaded %d records from input file", count);

for(i = 0; i < count; i++)

{

patients[i]->computed = Calculate(patients[i]);

}

  

fprintf(files.output, "%20s %10s %10s %5s %5s ", "Name", "Height", "Weight", "Sex", "Age");

fprintf(files.output, "%10s %10s %10s ", "SBP", "DSP", "Pressure");

fprintf(files.output, "%15s ", "BMI");

fprintf(files.output, "%10s", "BMR");

fprintf(files.output, "%20s ", "Activity Level");

fprintf(files.output, "%10s ", "CMR");

for(i = 0; i < count; i++)

{

if(!LogError(patients[i], files.error))

{

p = patients[i];

fprintf(files.output, "%20s %10.2f %10.2f %5d %5d ", p->name, p->height, p->weight, p->sex, p->age);

fprintf(files.output, "%10d %10d %10d ", p->SBP, p->DSP, p->computed->pulse_pressure);

  

val = p->computed->BMI;

if(val < 16)

fprintf(files.output, "%15s ", "underweight");

else if(val < 25)

fprintf(files.output, "%15s ", "normal");

else

fprintf(files.output,"%15s ", "overweight");

  

fprintf(files.output, "%10.2f", p->computed->BMR);

  

switch(p->activity_level)

{

case 1:

fprintf(files.output, "%20s ", "Sedentary");

break;

case 2:

fprintf(files.output, "%20s ", "Lightly Active");

break;

case 3:

fprintf(files.output, "%20s ", "Moderately Active");

break;

case 4:

fprintf(files.output, "%20s ", "Very Active");

break;

case 5:

fprintf(files.output, "%20s ", "Extra Active");

break;

  

}

  

fprintf(files.output,"%10.2f ", p->computed->CMR);

}

}

fclose(files.error);

fclose(files.output);

printf(" Please check output files %s and %s ", OUTPUT_FILE, ERROR_FILE);

}

Files OpenFiles(char *inputFname , char *outputFname, char *errFname)

{

Files f;

int len;

f.input = fopen(inputFname, "r");

f.output = fopen(outputFname, "w");

f.error = fopen(errFname, "w");

f.error_flag = 0;

if(f.input == NULL)

{

f.error_flag = 1;

sprintf(f.err_msg, "Error opening input file %s ", inputFname);

}

  

if(f.output == NULL)

{

f.error_flag = 1;

len = strlen(f.err_msg);

sprintf(f.err_msg + len, "Error opening output file %s ", outputFname);

}

  

if(f.error == NULL)

{

f.error_flag = 1;

len = strlen(f.err_msg);

sprintf(f.err_msg + len, "Error opening error log file %s ", errFname);

}

  

return f;

  

}

Patient* ReadFromFile(FILE *fp)

{

Patient* p = (Patient *) malloc(sizeof(Patient));

  

if(fscanf(fp,"%s %lf %lf %d %d %d %d %d",p->name, &p->height, &p->weight, &p->sex, &p->age, &p->activity_level, &p->SBP, &p->DSP) != 8)

{

strcpy(p->name, "-1");

}

return p;

}

Calculated* Calculate(Patient *p)

{

Calculated* c = (Calculated*) malloc(sizeof(Calculated));

double w = p->weight *0.45, h = p->height * 0.025; //convert to kg and cm

  

c->pulse_pressure = p->SBP - p->DSP;

c->BMI = w / (h * h);

  

switch(p->sex)

{

case 1:

c->BMR = 66 + 6.23 * w + 12.7 * h - 6.8 * p->age;

break;

case 2:

c->BMR = 655 + ( 4.35 * w ) + ( 4.7 * h ) - ( 4.7 * p->age );

break;

default:

c->BMR = 0;

}

  

switch(p->activity_level)

{

case 1:

c->CMR = c->BMR * 1.2;

break;

case 2:

c->CMR = c->BMR * 1.375;

break;

case 3:

c->CMR = c->BMR * 1.55;

break;

case 4:

c->CMR = c->BMR * 1.725;

break;

case 5:

c->CMR = c->BMR * 1.9;

break;

default:

c->CMR = 0;

}

  

return c;

}

int LogError(Patient *p, FILE *fp)

{

int error = 0;

if(p->sex != 1 && p->sex != 2)

{

error = 1;

fprintf(fp, "Sex should be 1 or 2 but it is %d, ", p->sex);

  

}

if(p->activity_level < 1 || p->activity_level > 5)

{

error = 1;

fprintf(fp, "Activity level is %d but it should in 1-5, ", p->activity_level);

  

}

if(p->DSP < 50)

{

error = 1;

fprintf(fp,"DSP[%d] is low, ", p->DSP);

}

if(p->SBP > 130)

{

error = 1;

fprintf(fp, "SBP[%d] is high, ", p->SBP);

}

  

if(p->computed->pulse_pressure > 60)

{

error = 1;

fprintf(fp, "Pulse Pressure[%d] is high, ", p->computed->pulse_pressure);

}

  

if(p->computed->BMI > 45 || p->computed->BMI < 10)

{

error = 1;

fprintf(fp, "BMI[%.2f] out of range 10-45, ", p->computed->BMI);

}

if(p->computed->BMR < 500 || p->computed->BMR > 5000)

{

error = 1;

fprintf(fp, "BMR[%.2f] is out of range 500-5000, ", p->computed->BMR);

}

if(p->computed->CMR < 600 || p->computed->CMR > 11400)

{

error = 1;

fprintf(fp, "CMR[%.2f] is out of range 600-11400, ", p->computed->CMR);

}

  

if(error)

{

fprintf(fp,"[Name: %s] ", p->name);

}

return error;

}

input file: patients.txt

Fred 65. 140. 1 29 1 120 80

Elle 64. 120. 2 22 6 115 82

Jenny 76. 43. 1 65 2 103 44

Sid 86. 212. 1 85 2 152 40

Betty 61. 128. 2 57 1 145 90

Kevin 74. 183. 1 49 3 125 73

Cathy 69. 155. 2 27 1 127 89

Bob 55. 210. 0 10 2 111 74

Bill 88. 233. 1 12 3 128 52

Maria 51. 98. 2 13 5 118 82

Enry 44. 22. 1 11 4 85 44

Tom 75. 195. 1 26 4 103 61

Angela 66. 132. 2 41 2 123 79

Amy 49. 88. 2 11 3 104 68

Laura 59. 98. 2 71 1 122 76

Scott 68. 140. 1 32 4 117 81

Frank 66. 170. 1 45 2 140 100

Mary 62. 125. 2 35 4 120 90

Lisa 67. 118. 2 24 3 124 81

Jill 63. 120. 2 30 4 110 95

Dave 70. 180. 1 44 2 130 65

output file : patients-out.txt

Name Height Weight Sex Age SBP DSP Pressure BMI BMR Activity Level CMR

Cathy 69.00 155.00 2 27 127 89 38 normal 839.62 Sedentary 1007.54

Maria 51.00 98.00 2 13 118 82 36 overweight 791.73 Extra Active 1504.28

Angela 66.00 132.00 2 41 123 79 44 normal 728.44 Lightly Active 1001.61

Amy 49.00 88.00 2 11 104 68 36 overweight 781.32 Moderately Active 1211.04

Laura 59.00 98.00 2 71 122 76 46 normal 520.07 Sedentary 624.08

Mary 62.00 125.00 2 35 120 90 30 normal 742.47 Very Active 1280.77

Lisa 67.00 118.00 2 24 124 81 43 normal 781.06 Moderately Active 1210.64

Jill 63.00 120.00 2 30 110 95 15 normal 756.30 Very Active 1304.62

output file: patients-err.txt

BMR[281.93] is out of range 500-5000, CMR[338.31] is out of range 600-11400, [Name: Fred]

Activity level is 6 but it should in 1-5, CMR[0.00] is out of range 600-11400, [Name: Elle]

DSP[44] is low, BMI[5.36] out of range 10-45, BMR[-231.32] is out of range 500-5000, CMR[-318.06] is out of range 600-11400, [Name: Jenny]

DSP[40] is low, SBP[152] is high, Pulse Pressure[112] is high, BMR[109.65] is out of range 500-5000, CMR[150.76] is out of range 600-11400, [Name: Sid]

SBP[145] is high, [Name: Betty]

BMR[269.34] is out of range 500-5000, CMR[417.47] is out of range 600-11400, [Name: Kevin]

Sex should be 1 or 2 but it is 0, BMI[49.98] out of range 10-45, BMR[0.00] is out of range 500-5000, CMR[0.00] is out of range 600-11400, [Name: Bob]

Pulse Pressure[76] is high, [Name: Bill]

DSP[44] is low, BMI[8.18] out of range 10-45, BMR[66.85] is out of range 500-5000, CMR[115.31] is out of range 600-11400, [Name: Enry]

BMR[459.70] is out of range 500-5000, [Name: Tom]

BMR[262.48] is out of range 500-5000, CMR[452.78] is out of range 600-11400, [Name: Scott]

SBP[140] is high, BMR[257.55] is out of range 500-5000, CMR[354.13] is out of range 600-11400, [Name: Frank]

Pulse Pressure[65] is high, BMR[293.66] is out of range 500-5000, CMR[403.78] is out of range 600-11400, [Name: Dave]