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

Language: C++ For my project i need to write a program that loads in data into 5

ID: 641427 • Letter: L

Question

Language: C++

For my project i need to write a program that loads in data into 5 arrays, one array for each mortality condition, using the hospital code as the array index; arrays of 5,000 elements each will be sufficient to hold all of the data for each mortality condition.

the text file is called "hm.txt" and here is a sample of the data:

0 MORT_30_AMI 13

0 MORT_30_COPD 8.8

0 MORT_30_HF 12.4

0 MORT_30_PN 11.4

0 MORT_30_STK 14.5

1 MORT_30_AMI 18

1 MORT_30_COPD 7.8

1 MORT_30_HF 17.1

1 MORT_30_PN 14

1 MORT_30_STK 15.6

2 MORT_30_AMI 18.4

2 MORT_30_COPD 7.1

2 MORT_30_HF 14.2

2 MORT_30_PN 15

2 MORT_30_STK 17.9

3 MORT_30_AMI

Explanation / Answer

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

int main(){
   ifstream inFile("hm.txt");
   int index;
   string mortCond;
   double rate;
   double MORT_30_AMI[5000], MORT_30_COPD[5000], MORT_30_HF[5000], MORT_30_PN[5000], MORT_30_STK[5000];
   while(inFile >> index >> mortCond >> rate){
       if(mortCond == "MORT_30_AMI") MORT_30_AMI[index] = rate;
       if(mortCond == "MORT_30_COPD") MORT_30_COPD[index] = rate;
       if(mortCond == "MORT_30_HF") MORT_30_HF[index] = rate;
       if(mortCond == "MORT_30_PN") MORT_30_PN[index] = rate;
       if(mortCond == "MORT_30_STK") MORT_30_STK[index] = rate;
   }
   cout << fixed << setprecision(2);
   for(int i = 0; i < index; i++){
       cout << MORT_30_AMI[i] << " " << MORT_30_COPD[i] << " " << MORT_30_HF[i] << " " << MORT_30_PN[i] << " " << MORT_30_STK[i] << " " << endl;
   }
   cout << endl;
}