Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Part B

image text in transcribed

Baseball.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

}

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

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

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

is chegg ai included in honor code investigation or is it private

Answered: 1 week ago

Question

=+How much wealth does he have left after period one?

Answered: 1 week ago