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

This is c++ program i need help with and it needs to be compiled with GNU++ Comp

ID: 3860667 • Letter: T

Question

This is c++ program i need help with and it needs to be compiled with GNU++ Compiler

it has part A, b please do both

Part A

Part B

Baseball.cpp

#include "Player.h"

#include <iostream>

#include <fstream>


void displayArray(Player team[], int team_size);

int sequeSearch(Player team[], int team_size,int number);


int main()

{


fstream fin("baseball.txt");


const int LIST_LENGTH = 20;


int number = 0, hits, walks, outs,players,index,teamSize = 0;


cout << "This program tracks a baseball player's number "

<< "and their number of hits, walks, and outs for "

<< "each games in a season. ";


Player team[LIST_LENGTH];


fin >> number >> hits >> walks >> outs;


while (!fin.eof())

{


int index=sequeSearch(team, teamSize, number);


if(index == -1)

{


team[teamSize].setNumber(number);

team[teamSize].setHits(hits);

team[teamSize].setWalks(walks);

team[teamSize].setOuts(outs);

teamSize++;

}

else

{


team[index].setHits(hits);

team[index].setWalks(walks);

team[index].setOuts(outs);

}


fin >> number >> hits >> walks >> outs;

}


displayArray(team,teamSize);


fin.close();

}

void displayArray(Player team[], int team_size)

{

cout << " Player Hits Walks Outs "

<< "------ ---- ----- ---- ";


for (int i=0; i < team_size; i++)

{


cout << team[i] << endl;

}

}

int sequeSearch(Player team[], int team_size,int number)

{

for (int i=0; i < team_size; i++)

{

if(team[i].getNumber()==number)

return i;

}

return -1;

}

Baseball.txt

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

Player.cpp

#include "Player.h"
#include <iostream>
#include <iomanip>
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<<(ostream& out, const Player & p)
{
out << setw(2) << p.Number << " "
<< setw(2) << p.Hits << " "
<< setw(2) << p.Walks << " "
<< setw(2) << p.Outs;
return out;
}

Player.h

Player.h:

#ifndef PLAYER
#define PLAYER
#include <iostream>
using namespace std;
class Player
{
public:
Player();
int getNumber() const;
int getHits() const;
int getWalks() const;
int getOuts() const;
void setNumber(int);
void setHits(int);
void setWalks(int);
void setOuts(int);
const Player& operator=(const Player &);
friend ostream& operator<<(ostream&, const Player & );
private:
int Number, Hits, Walks, Outs;
};
#endif

Modify the program that you wrote for the last exercise in a file named Basebal12.cpp that uses the Player class stored within an array. 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 Basebal1.cpp is the only file that you need to modify for this assignment. Once all of the input data from the file is 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 The main() function for this program is once again in the file Baseball2.cpp Your solution from the last assignment connects to the sequential input file baseball.txt, inputs all of the int values in the file, and updates the Player's statistics for display. We'll need to remember to disconnect from the input file when we're done. Once again, all output should be displayed to the monitor. 1. process to connect the input file fin to the program and set teamSize to0 2. output an informational message to the screen about the program 3. process declare an array of length 20 of type Player named team[ ] 4. input the Number, Hits, Walks and Runs of a Player 5. process while not-end-of-file fin a. process determine if the Number is stored in the first teamSize elements b. process if the Number is not stored in the array i. process Number of teamsize is argument to setNumber() li. process Hits of teamSize is argument to setHits() ii. process Walks of teamSize is argument to setWalks() iv. process Outs of teamSize is argument to setouts() v. process increase teamSize by 1 C. process else if team[ index] contains Number i. process Hits +getHits () of index is argument to setHits() li. process Walks + getWalks() of index is argument to setWalks () i. process Outs getouts () of index is argument to setouts () d. input the Number, Hits, Walks and Runs of a Player

Explanation / Answer

#include<iostream>

#include<cstring>

#include<ctime>

using namespace std;

void INIT(void);

char repeat = 'n';

int N = 11;

int PosAssign[4][9] = {0};

struct player

{

int inFld;

int outFld;

};

player* P;

int main()

{

int y = 0;

int i=0,j=0;

int posNum = 0;

srand((unsigned)time(0));

cout << "Each run produces a full game lineup ";

do

{

cout << "Enter number of players: ";

cin >> N;

P = new player[N];

INIT();

y = rand()%N;

for(j=0; j<=5; j++)

{

PosAssign[0][j] = y;

P[y].inFld = 1;

y = (1+y)%N;

}

for(j=6; j<=8; j++)

{

PosAssign[0][j] = y;

P[y].outFld = 1;

y = (1 + y)%N;

}

for( i=1; i<4; i++)

{

y = PosAssign[i-1][6];

posNum = 0;

j = 0;

do

{

if( (PosAssign[i-1][0] != y)&&(PosAssign[i-1][posNum] != y)&&( P[y].inFld < 2) )

{

PosAssign[i][posNum] = y;

P[y].inFld++;

posNum++;

}

j++;// this is just to prevent infinite loop in case not all positions can be filled

y = (1 + y)%N;

}while( (posNum <= 5)&&(j < 100) );

j = 0;

posNum = 6;// now for positions 6 thru 8

do// assign outfield positions

{

if( (PosAssign[i-1][0] != y)&&(P[y].outFld < 1) )

{

PosAssign[i][posNum] = y;

P[y].outFld = 1;

posNum++;

}

y = (1 + y)%N;

j++;

}while( (posNum <= 8)&&(j < 100) );

}

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

{

cout << endl << endl <<"lineup for inning " << i+1 << " is ";

for( j=0; j<=8; j++)

cout << PosAssign[i][j] << " ";

}

cout << endl << endl << "# of in/outfield assigns for each player are " << endl;

for(j=0; j<N; j++)

cout <<P[j].inFld << P[j].outFld << " ";

delete [] P;

cout << endl << "repeat (y/n)? " << flush;

cin >> repeat;

}while( repeat=='y');

return 0;

}

void INIT(void)

{

int j=0, k=0;

for(j=0; j<4; j++)

for(k=0; k<9; k++)

PosAssign[j][k] = -1;

for(j=0; j<N; j++)

P[j].inFld = P[j].outFld = 0;

return;

}

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