Question: Output: Programs: Baseball9.cpp: #include Player.h #include #include // declaration of functions void displayArray(Player team[], int team_size); int sequeSearch(Player team[], int team_size,int number); // implementation of

![void displayArray(Player team[], int team_size); int sequeSearch(Player team[], int team_size,int number); //](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f4e35901108_01666f4e3587a51e.jpg)




![3) declare an array of LIST_LENGTH players Player team[LIST_LENGTH]; // 4) attempt](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f4e35c6db7a_01966f4e35bf10bd.jpg)
Output:

Programs:
Baseball9.cpp:
#include "Player.h"
#include
#include
// declaration of functions
void displayArray(Player team[], int team_size);
int sequeSearch(Player team[], int team_size,int number);
// implementation of the main program
int main()
{
// 1) connect to input file
fstream fin("baseball.txt");
// objects used to store data
const int LIST_LENGTH = 20;
// number, hits, walks, outs
int number = 0, hits, walks, outs,players,index,teamSize = 0;
// 2) output descriptive messages
cout
// 3) declare an array of LIST_LENGTH players
Player team[LIST_LENGTH];
// 4) attempt to input the data for the first Player
fin >> number >> hits >> walks >> outs;
// 5) loop on end of file
while (!fin.eof())
{
// 6) find the index of this Player's number
int index=sequeSearch(team, teamSize, number);
// 7) if player number is not in the list
if(index == -1)
{
// 7a) set the Number field for team[teamSize]
// 7b) set the Hits field for team[teamSize]
// 7c) ste the Walks field for team[teamSize]
// 7d) set the Outs field for team[teamSize]
// 7e) increase teamSize by 1
team[teamSize].setNumber(number);
team[teamSize].setHits(hits);
team[teamSize].setWalks(walks);
team[teamSize].setOuts(outs);
teamSize++;
}
else
{
// 8) else player number is in the list
// 8a) update the Hits field for team[index]
// 8b) update the Walks field for team[index]
// 8c) update the Outs field for team[index]
team[index].setHits(hits);
team[index].setWalks(walks);
team[index].setOuts(outs);
}
// 9) attempt to input the data for the next Player
fin >> number >> hits >> walks >> outs;
}
// 10) display the results
displayArray(team,teamSize);
// 11) disconnect from input file
fin.close();
} // end of main
void displayArray(Player team[], int team_size)
{
cout
// 2) loop over team size
for (int i=0; i
{
// 3) display i'th player
cout
}
}
int sequeSearch(Player team[], int team_size,int number)
{
for (int i=0; i
{
if(team[i].getNumber()==number)//check number exists then return i
return i;
}
return -1;//if number not found in list tyhen return -1
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Player.cpp:
#include "Player.h" #include #include using namespace std; Player::Player() { Number = Hits = Walks = Outs = 0; } int Player::getNumber() const { return Number; } int Player::getHits() const { return Hits; } int Player::getWalks() const { return Walks; } int Player::getOuts() const { return Outs; } void Player::setNumber(int n) { Number = n; } void Player::setHits(int h) { Hits = h; } void Player::setWalks(int w) { Walks = w; } void Player::setOuts(int o) { Outs = o; } // support for assignments const Player& Player::operator=(const Player & p) { // bypass self assignment if (this != &p) { Number = p.Number; Hits = p.Hits; Walks = p.Walks; Outs = p.Outs; } return *this; } // support for output to the monitor ostream& operator ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Player.h:
#ifndef PLAYER #define PLAYER #include using namespace std; class Player { public: // member functions // constructor Player(); // extractors int getNumber() const; int getHits() const; int getWalks() const; int getOuts() const; // mutators void setNumber(int); void setHits(int); void setWalks(int); void setOuts(int); // support for assignments and output to the monitor const Player& operator=(const Player &); friend ostream& operator ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
baseball.txt
1 2 2 2 19 0 5 1 2 0 0 6 18 4 2 0 4 1 2 3 12 2 2 2 7 0 0 3 8 1 4 1 10 2 2 2 3 2 1 3 11 6 0 0 2 0 5 1 19 0 0 6 17 4 2 0 9 3 2 1 4 2 1 3 3 1 2 3 7 0 0 3
Modify the program that you wrote for the last exercise in a file named Basebal19.cpp that uses the Player class stored within an arrav. The program should read data from the file baseball.txt for input. The Player class should once again be stored in files named Player.h and Player.cpp, however Basebal19.cpp is the only file that stored in the array, code and invoke a function named selectionSort that sorts the array of Player objects in the ascending order of the Player Number field using the Selection Sort algorithm. Display the Number, Hits, Walks and Outs data attributes to the monitor for each array element both before and after sorting. There are many sorting algorithms that can be used to sort a list of keys. Introductory techniques include the Selection Sort (and a variation known as the Bubble Sort) and the Insertion Sort. More sophisticated algorithms include the Quick Sort, the Merge Sort and the Heap Sort, which are discussed in more advanced courses in Computer Science. The wide variety of our uses for dats bases usually involves choices on using one sorting algorithm over another based upon the demands that we make upon memory configurations and CPU execution time. Esch of the sorting techniques has different strengths and weaknesses. This is why we have the need Modify the program that you wrote for the last exercise in a file named Basebal19.cpp that uses the Player class stored within an arrav. The program should read data from the file baseball.txt for input. The Player class should once again be stored in files named Player.h and Player.cpp, however Basebal19.cpp is the only file that stored in the array, code and invoke a function named selectionSort that sorts the array of Player objects in the ascending order of the Player Number field using the Selection Sort algorithm. Display the Number, Hits, Walks and Outs data attributes to the monitor for each array element both before and after sorting. There are many sorting algorithms that can be used to sort a list of keys. Introductory techniques include the Selection Sort (and a variation known as the Bubble Sort) and the Insertion Sort. More sophisticated algorithms include the Quick Sort, the Merge Sort and the Heap Sort, which are discussed in more advanced courses in Computer Science. The wide variety of our uses for dats bases usually involves choices on using one sorting algorithm over another based upon the demands that we make upon memory configurations and CPU execution time. Esch of the sorting techniques has different strengths and weaknesses. This is why we have the need