// Enter your name as a comment for program identification // Program assignment PlayBall.cpp // Enter your class section, and time /* The program PlayBall.cpp keeps track of the hits, walks, and outs of a baseball team. Use parallel arrays to keep track of each player's statistics. The player number is the index of the array. Read a file with data that includes player number, hits, walks, and outs. The data file will contain multiple games. Not every player will have stats in each game. */ /* An input file PlayBall.txt is used to enter the data. */ /* The names are written to an output file a maximum of 20 characters per line. */ //header files /* use the correct preprocessor directives for input/output, strings, and file stream */ #include #include #include using namespace std; // function prototypes // It is always a good idea to use functions in order to // break down the problem into smaller pieces. Declare // the prototypes for any functions you use here. /* The function instruct describes the use and purpose of the program. */ void instruct(); // main function int main() { // declare variables /* an ifstream object infile for the data file, a string variable fileName for the name of the text file, and temporary variables to hold data read in from the text file. You need to declare your parallel arrays here*/ ifstream infile; string fileName = "PlayBall.txt"; int player, hit, walk, out; // open the input file infile.open(fileName.c_str()); if (!infile) { cout << "Cannot open input file.\n"; return 1; } // call the function instruct instruct(); // read in the first player number infile >> player; // loop through data until end of file while (!infile.eof()) { // read in the player's statistics infile >> hit >> walk >> out; // you have the data read in from next line of the file // at this point. You need to save it in your parallel // arrays at this point. // read in the next player number infile >> player; } // after you are done reading in the file, display your results // close the input file infile.close(); return 0; } /* The function instruct describes the use and purpose of the program. */ void instruct() { cout << "This program keeps track of " << "the hits, walks, and outs of a baseball " << "team.\n\n"; }