Create a C++program to store the team standings for the MLB as of 06/20/18 into
ID: 3918083 • Letter: C
Question
Create a C++program to store the team standings for the MLB as of 06/20/18 into parallel arrays.
Create the parallel arrays (all arrays have the same exact length of 30 rows, 5 teams in each of 6 divisions) with the appropriate data types using the .csv file listing at the end of this document. You wil be provided with the data for the following 8 fields City, State, Team Name, Wins, Losses, Runs Scored, Runs Against, and Division. Below a more complete data set copied from a website with 11 fields (notice the PCT, GB and DIFF are calculated from other columns, and/or contain mixed types/missing entries). Do not create arrays for PCT, GB, and DIFF because they can be calculated from the data in other columns:
WinsLosses PCT New York 28.5 Cleveland Philadelphia Milwaukee 1 Cardinal:s incinnati Diamondbacks Los Angeles San Francisco 1Explanation / Answer
/* As per the question the data provided will contain 8 fields in the following order:
City,State,Team Name,Wins, Losses,Runs Scored, Runs Against,Divison
*/
#include<iostream>
#include<string>
#include<fstream>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main(){
cout << "Enter the input csv file name:";
string name;
cin >> name;
ifstream fin(name.c_str());
if (!fin){
cout << "Error opening file ";
return 0;
}
string City[30];
string State[30];
string Team[30];
int wins[30];
int losses[30];
int rs[30];
int ra[30];
string div[30];
string line;
getline(fin,line); // Ignoring the first line as header
for (int i = 0; i<30; i++){
getline(fin,line);
char *ch = strtok((char *)line.c_str(),",");
City[i] = ch;
ch = strtok(NULL,",");
State[i] = ch;
ch = strtok(NULL,",");
Team[i] = ch;
ch = strtok(NULL,",");
wins[i] = atoi(ch);
ch = strtok(NULL,",");
losses[i] = atoi(ch);
ch = strtok(NULL,",");
rs[i] = atoi(ch);
ch = strtok(NULL,",");
ra[i] = atoi(ch);
ch = strtok(NULL,",");
div[i] = ch;
}
fin.close();
for (int i = 0; i<30; i++){
cout << City[i] << " " << State[i] << " " << Team[i] << " " << wins[i] << " " << losses[i] << " " << rs[i] << " " << ra[i] << " " << div[i] << endl;
}
return 0;
}