/*
Create a program that uses a count controlled loop to read the patient's "readings" from a file and adds them up individually,
calculates the average for each person (ID), and displays the two totals.
Input -
(numPatients-)
20
idNum numBP bpReading (1, 2, 3, 4)
1234 - 4 - 150 156 120 130
5678 - 3 - 200 198 187
9101 - 4 - 157 152 166 160
1121 - 4 - 140 140 142 137
1131 - 1 - 158
1141 - 4 - 210 220 206 211
1151 - 3 - 205 206 207
1161 - 2 - 199 192
1171 - 2 - 120 117
1181 - 4 - 204 201 209 210
1192 - 4 - 200 200 201 190
0212 - 3 - 182 188 200
2232 - 4 - 194 196 190 151
4252 - 4 - 161 180 174 179
6272 - 2 - 190 134
8293 - 4 - 120 126 135 140
0313 - 2 - 149 132
2333 - 4 - 168 151 160, 154
4353 - 3 - 110 109 120
6373 - 4 - 150 150 162 159
Output -
idNum Total Average
1234 - bpTotal, bpAverage
5678 - bpTotal, bpAverage
9101 - bpTotal, bpAverage
1121 - bpTotal, bpAverage
1131 - bpTotal, bpAverage
1141 - bpTotal, bpAverage
1151 - bpTotal, bpAverage
1161 - bpTotal, bpAverage
1171 - bpTotal, bpAverage
1181 - bpTotal, bpAverage
1192 - bpTotal, bpAverage
0212 - bpTotal, bpAverage
2232 - bpTotal, bpAverage
4252 - bpTotal, bpAverage
6272 - bpTotal, bpAverage
8293 - bpTotal, bpAverage
0313 - bpTotal, bpAverage
2333 - bpTotal, bpAverage
4353 - bpTotal, bpAverage
6373 - bpTotal, bpAverage
Constraints-
Only read data until the end of the file.
Operations -
1. Read file for numPatients
counter = numPatients
2. While counter < numPatients
read idNum, numBP, bpReadings (1, 2, 3, 4)
3. bpTotal = bpReadings (1 + 2 + 3 + 4)
4. bpAverage = bpTotal / numBP
5. Each time the end of line is read, counter++
6. Repeat until counter > 20
7. Display
idNum Total Average
1234 - bpTotal, bpAverage
5678 - bpTotal, bpAverage
9101 - bpTotal, bpAverage
1121 - bpTotal, bpAverage
1131 - bpTotal, bpAverage
1141 - bpTotal, bpAverage
1151 - bpTotal, bpAverage
1161 - bpTotal, bpAverage
1171 - bpTotal, bpAverage
1181 - bpTotal, bpAverage
1192 - bpTotal, bpAverage
0212 - bpTotal, bpAverage
2232 - bpTotal, bpAverage
4252 - bpTotal, bpAverage
6272 - bpTotal, bpAverage
8293 - bpTotal, bpAverage
0313 - bpTotal, bpAverage
2333 - bpTotal, bpAverage
4353 - bpTotal, bpAverage
6373 - bpTotal, bpAverage
*/
#include <iostream>
#include <string>
#include <iomanip>
#include <conio.h>
#include <fstream>
using namespace std;
string idNum;
int counter, counter2, numBP, bpReading1, bpReading2, bpReading3, bpReading4, numPatients;
int bpTotal = 0;
int bpAverage = 0;
int main()
{
cout << "ID\t BP Total\t BP Average";
cout << endl;
ifstream ifile("bpDATA.txt");
counter = 0;
while (counter <= numPatients)
{
ifile >> idNum >> numBP;
cout << idNum << "\t" ;
counter2 = 0;
{
if (counter2 != numBP)
{
ifile >> bpReading1;
counter2++;
}
else if (counter2 != numBP)
{
ifile >> bpReading2;
counter2++;
}
else if (counter2 != numBP)
{
ifile >> bpReading3;
counter2++;
}
else (counter = numBP);
ifile >> bpReading4;
}
bpTotal = bpReading1 + bpReading2 + bpReading3 + bpReading4;
bpAverage = bpTotal / numBP;
cout << bpTotal << "\t" << bpAverage;
counter++;
}
_getch();
return 0;
}
mike.severini.3 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.