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

Redo this program to develop a program that reads from a blood pressure file as

ID: 3551457 • Letter: R

Question

Redo this program to develop a program that reads from a blood pressure file as follows, and calculate the average. Requirement: declare an array for pressure measurements, and store all these blood pressures Requirement: use a loop to go over each person Redo this program to develop a program that reads from a blood pressure file as follows, and calculate the average. Requirement: declare an array for pressure measurements, and store all these blood pressures Requirement: use a loop to go over each person

Explanation / Answer

Lab1.h file


#include<string.h>

using namespace std;

float ReadBP(string filename);



data.txt

ID Name How many Pressure measurements

4132 Tom 6 80 90 81 100 89 79

5123 Jim    5    100 110 120 121 122

4322 Mike 3 89 121 111

6544 Nancy 6 95 122 112 121 123 99



.cpp file


#include <iostream>

#include <fstream>

#include <cstdlib> //this header file was not in

#include "Lab1.h"

using namespace std;

int main()

{

   float totalaverage = ReadBP("data.txt");
  
   cout << "average blood pressure for all patients is "<< totalaverage << endl;
  
   system("pause");
  
   return 0;

}

float ReadBP(string filename)

{
  
   fstream ifile;
  
   ifile.open(filename.c_str());    //modified code
  
   int ID, num, bp;
  
   string name;
  
   getline(ifile, name);
  
   //cout << name << endl;
  
   float total=0;
  
   int totalnum=0;
  
   //declare an array for pressure measurements, and store all these blood pressures
   // initilising all elements of 2-d blood-pressure array of size 1000x50
   int BP[1000][50]; //assuming 1000 patients and 50 records per patient at max.
  
   int i=0,j=0;
  
   while(true)
  
   {
  
        ifile >> ID >> name >> num;
       
        if( ifile.eof() ) break;    //new line added
               
        int count=0;
       
        j=0;
       
        while (count < num)
       
        {
            int value =0;
           
            ifile >> value;
           
            BP[i][j]=value; //putting read BP value from file into array
           
            count++;
           
            j++; //incrementing patient's record number
  
        }
  
        i++; //incrimenting patient number. i is same as patient numbers
  
   }
  
   //now we have stored all the available bp's into our 2-d matrix
   //now we will loop over the 2-d matrix to find out the average bp for each person and the total average
  
   //use a loop to go over each person

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote