Question: This is C++ Problem, needs to be compiled with GNU++ Compiler All of the files needed for this (baseball.cpp, player.h Player.cpp, and baseball.txt are provided

This is C++ Problem, needs to be compiled with GNU++ Compiler

All of the files needed for this (baseball.cpp, player.h Player.cpp, and baseball.txt are provided below.

This is C++ Problem, needs to be compiled with GNU++ Compiler Allof the files needed for this (baseball.cpp, player.h Player.cpp, and baseball.txt are

Baseball.cpp

#include "Player.h"

#include

#include

// declaration of functions

// 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;

int number = 0, // number, hits, walks, outs

hits,

walks,

outs,

players,

index,

teamSize = 0;

// 2) output descriptive messages

cout

// 3) declare an array of LIST_LENGTH players

// 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

// 7) if player number is not in the list

// 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

// 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]

// 9) attempt to input the data for the next Player

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

}

// 10) display the results

// 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

}

}

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

#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

{

out

return out;

}

// end of the class member functions

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

private: // data attributes int Number, Hits, Walks, Outs; };

// end of the class #endif

Write a program in a file named Baseball.cpp that uses a Player class stored within an array. The program should read data from the file baseball.txt for input. The Player class is declared in a file named Player.h, is stored in a file named Player.cpp and supports a constructor that sets the four data attributes (Number, Hits, Walks and Outs) equal to zero. In addition, there are extractor and mutator member functions for each of the data attributes. There is also an overload of the assignment operator foir assignment of Player objects. Finally, there is an overload of the output operator

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!