Question: write a program that will process a data set of information for the Chicago Blackhawks. The information in the file will be needed for later
write a program that will process a data set of information for the Chicago Blackhawks. The information in the file will be needed for later processing, so it will be stored in a set of arrays that will be displayed, sorted, and displayed (again).
For the assignment, declare four arrays, each of which will hold a maximum of 25 elements:
- one array of strings to hold the player names
- one array of integers to hold the number of goals scored for each of the players
- one array of integers to hold the number of assists for each of the players
- one array of integers to hold the plus/minus rating for each of the players
The four arrays will be parallel arrays. This means that the information for one player can be found in the same "spot" in each array. This also means that any time information is moved in one array the same move must be made to the other arrays in order to maintain data integrity.
buildArrays notes:
-
The data is being read from an input file. Before the file can be processed, you must:
-
declare an input file stream (see "Programming Note 1" below)
ifstream inFile;
open the file and make sure that it opened correctly
inFile.open( "hockey.txt" ); if ( inFile.fail() ) { cout << "The hockey.txt input file did not open"; exit(-1); } The above code will open the file and then make sure that the file did indeed open correctly.
To read from a file, use the name of the ifstream in place of cin. For example if you want to read an integer:
int num; inFile >> num;
Or if you want to read a string:
string str; inFile >> str;
To test if there are records in the file, simply use the name of the input file stream as a boolean variable. For example:
while ( inFile )
As long as there are records in the file, the name of the input file stream name will resolve to true. Once all of the records have been read from the file, the input file stream name will resolve to false.
Once a value has been read from a file, it can be put into the appropriate array element:
goals[i] = num;
After all of the data has been read from the file, the file must be closed. To do this, execute the following:
inFile.close();
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
