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

For this assignment, write a program that will process a data set of information

ID: 3531458 • Letter: F

Question

For this assignment, 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:

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.

NOTE:all of the functions mentioned in this logic are described below.

Fill the four arrays by calling thebuildArrays()function.

Display the title "Chicago Blackhawks UNSORTED Report"

Display the four arrays by calling theprintArrays()function.

Sort the four arrays by calling thesortArrays()function.

Display the title "Chicago Blackhawks SORTED Report"

Display the sorted arrays by calling theprintArrays()function.

The input for this program will be read from a disk file namedhockey.txt. (link also below)

http://faculty.cs.niu.edu/~byrnes/csci240/pgms/hockey.txt

The file consists of a set of player records. Each record represents one player and is made up of four values that are all contained on one line of the file: the first is the player name, the second is the number of goals the player scored, the third is the number of assists for the player, and the fourth is the plus/minus rating for the player. The file resembles the following:

NOTE:You may assume that if there is a player name, then there will be a number of goals, assists, and plus/minus rating.

This function will read the file of data and fill the four arrays. It takes as its arguments the array of strings and three arrays of integers. It returns the number of valid players that were placed in the arrays.

Suggested logic:

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)

The above code will open the file and then make sure that the file did indeed open correctly.

Or if you want to read a string:

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.

This function will display the information for the players. For each player, display the player name, number of goals scored, number of assists, number of points, and plus/minus rating.

This function takes as its arguments the four arrays and the number of players in the arrays.

The number of points is calculated as follows:

Use the following as a basic format for the output:

Notice that the + and - signs are printing in front of the non-zero plus/minus ratings. - signs print by default. To get + signs to display, set theshowposflag. To turn off the display of + signs, set thenoshowposflag.

This function will use the selection sort algorithm that was presented in lecture to sort the arrays inDESCENDINGorder based on the number of points.

As with the printArrays function, the number of points is calculated as follows:

This function takes as its arguments the four arrays and the number of players in the arrays.

It's important to note that the four arrays are parallel arrays, meaning that elements in each array that have the same subscript correspond. Therefore, every time the algorithm swaps two elements in an array, it must also swap the corresponding elements in the other three arrays.

Add #include <fstream> at the top of your program.

Each array should be able to hold 25 elements. Use a symbolic constant to represent the maximum size (maximum number of players) of an array.

Each array has the capability to hold 25 elements, however, that does not mean that they will all be used. This is the reason that the number of elements in the array is being passed to the sort and print functions. This value is the return value from buildArrays.

Copy the input file to your hard disk and write your program so that it reads the data from the current directory (ie. don't specify a file path).

Hand in a copy of your source code using Blackboard.

Here is the output for this assignment using thehockey.txtfile from above.

Explanation / Answer

#include <string>

#include <iostream>

#include <fstream>


int buildArrays( string playerNames[], int goals[], int assists[], int rating[] )

{

ifstream inFile;

inFile.open( "hockey.txt" );

if ( inFile.fail() )

{

cout << "The hockey.txt input file did not open";

exit(-1);

}

int i = 0,num;

char name[100];

while ( inFile )

{

strcpy(playerNames[i],name);

infile >> num;

goals[i]=num;

infile >> num;

assists[i]=num;

infile >> num;

rating[i]=num;

i++;

}

inFile.close();

return i;

}

void printArrays( string playerNames[], int goals[], int assists[], int rating[], int numPlayers )

{

int i,points;

for(i=0;i<numPlayers;i++)

{

points = goals[i]+assists[i];

std::cout<< playerNames[i] << " " << goals[i]<< " " << assists[i]<<" ";

std::cout << std::showpos<<points<<" ";

std::cout << std::noshowpos<<rating[i]<<endl;;

}

}

void sortArrays( string playerNames[], int goals[], int assists[], int rating[], int numPlayers )

{

int i,j,maxindex=0;

int temp;

char tem[100];

for(i=0;i<numPlayers-1;i++)

{

maxindex = i;

for(j=i+1;j<numPlayers;j++)

{

if((goals[j] + assists[j]) > (goals[maxindex] + assists[maxindex])

maxindex = j;

}

strcpy(tem,playerNames[i]);

strcpy(playerNames[i],playerNames[maxindex]);

strcpy(playerNames[maxindex],tem);

temp = goals[i];

goals[i] = goals[maxindex];

goals[maxindex] = temp;

temp = assists[i];

assists[i] = assists[maxindex];

assists[maxindex] = temp;

temp = rating[i];

rating[i] = rating[maxindex];

rating[maxindex] = temp;

}

}

int main()

{

string playerNames[25];

int goals[25];

int assists[25];

int rating[25];

int numPlayers = bulidArrays(playerNames,goals,assists,rating);

std::cout << "Chicago Blackhawks UNSORTED Report"<<endl;

std::cout << "Player "<<"Goals "<<"Assists "<<"Points "<<"Plus/Minus"<<endl;

std::cout <<"--------------------------------------------------------------------------------"<<endl;

printArrays(playerNames,goals,assists,rating,numPlayers);

sortArrays(playerNames,goals,assists,rating,numPlayers);

std::cout << "Chicago Blackhawks SORTED Report"<<endl;

std::cout << "Player "<<"Goals "<<"Assists "<<"Points "<<"Plus/Minus"<<endl;

std::cout <<"--------------------------------------------------------------------------------"<<endl;

printArrays(playerNames,goals,assists,rating,numPlayers);

return 0;

}

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