Extend the program to display which player has the highest batting average (hits / atBats) and that average. ---------------------- stats.txt file info: Andrus 574 148 Beltre 543 151 Choo 531 146 Fielder 592 182 Odor 405 108 ---------- Program to modify: /* COSC 1437 Activity 3 Baseball Statistics */ #include #include #include using namespace std; // Structure to hold batting statistics struct Player { string name; int atBats; int hits; }; int main() { ifstream statFile; string playerName; int bats, hits; Player * baseballArray[100]; Player * aPlayer; int numPlayers = 0; statFile.open("stats.txt"); // Continue reading until the end of file while (statFile >> playerName) { statFile >> bats >> hits; // Dynamically create a new Player aPlayer = new Player; aPlayer->name = playerName; aPlayer->atBats = bats; aPlayer->hits = hits; // Store the pointer to the Player struct in the array baseballArray[numPlayers++] = aPlayer; // Display this information cout << aPlayer->name << " has " << aPlayer->atBats << " at bats and " << aPlayer->hits << " hits" << endl; } // For Activity 3: Display which player has the highest batting average. // Display the player's name and average }

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter8: I/o Streams And Data Files
Section: Chapter Questions
Problem 8PP: (Data processing) A bank’s customer records are to be stored in a file and read into a set of arrays...
icon
Related questions
Question

Extend the program to display which player has the highest batting average (hits / atBats) and that average.

----------------------

stats.txt file info:

Andrus 574 148

Beltre 543 151

Choo 531 146

Fielder 592 182

Odor 405 108

----------

Program to modify:

/* COSC 1437 Activity 3 Baseball Statistics */

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

// Structure to hold batting statistics

struct Player

{

string name;

int atBats;

int hits;

};

int main()

{

ifstream statFile;

string playerName;

int bats, hits;

Player * baseballArray[100];

Player * aPlayer;

int numPlayers = 0;

statFile.open("stats.txt");

// Continue reading until the end of file

while (statFile >> playerName)

{

statFile >> bats >> hits;

// Dynamically create a new Player

aPlayer = new Player;

aPlayer->name = playerName;

aPlayer->atBats = bats;

aPlayer->hits = hits;

// Store the pointer to the Player struct in the array baseballArray[numPlayers++] = aPlayer;

// Display this information

cout << aPlayer->name << " has " << aPlayer->atBats << " at bats and " << aPlayer->hits << " hits" << endl;

}

// For Activity 3: Display which player has the highest batting average. // Display the player's name and average }

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning