Question: Write a C++ program that reads a file with at least 9 player names, their jersey number, position and score on separate lines for a
Write a C++ program that reads a file with at least 9 player names, their jersey number, position and score on separate lines for a baseball team.
Store the data into parallel arrays and then display the following choices in a menu
1.lowest scorer
2.highest scorer
3.search by name or position
4.total team points
5.sort either by player names along with their jersey number and score or sort by jersey number, along with their name and score
6.display to screen
7.write to file
Create a function for each menu item. Use arguments and parameter list for each function and pass in data. Do not use global variables.
Declare data types of variables (DO NOT USE AUTO)
You must deliver a .CPP file or .txt file
C++ keywords are lowercase
User defined variables and functions should be in camelCase.
Constant variables should be defined in ALL CAPS and can be separated by an underscore.
Having so much trouble getting the program to read the file.
This is what I have right now --
#include "pch.h"
#include
#include
#include
#include
using namespace std;
void readdata(ifstream &inFile, char names[], int numbers[], char position[], int score[],int SIZE);
void lowestscore(char names[], int score[], int SIZE);
void highscore(char names[], int score[], int SIZE);
int main()
{
const int SIZE = 9;
char names[SIZE];
int numbers[SIZE];
char position[SIZE];
int score[SIZE];
ifstream inFile;
ofstream outputFile;
string filename;
// Get the filename from the user.
cout << "Enter the filename: ";
cin >> filename;
// Open the file.
inFile.open(filename);
if (!inFile)
{
// Display an error message.
cout << "Error opening the file. ";
return 0;
}
readdata(inFile, names, numbers, position, score, SIZE);
lowestscore(names, score, SIZE);
return 0;
}
void readdata(ifstream &inFile, char names[], int numbers[], char position[], int score[], int SIZE)
{
for (int count = 0; count < SIZE; count++)
{
inFile >> names[count];
inFile >> numbers[count];
inFile >> position[count];
inFile >> score[count];
}
}
void lowestscore(char names[], int score[], int SIZE)
{
int count;
int lowest;
lowest = score[0];
for (int count = 1; count < SIZE; count++)
{
if (score[count] < lowest)
lowest = score[count];
}
cout << "The player with the lowest score of " << score << "is " << names << endl;
return;
}
void highscore(char names[], int score[], int SIZE)
{
int count;
int highest;
highest = score[0];
for (int count = 1; count < SIZE; count++)
{
if (score[count] > highest)
highest = score[count];
}
cout << "The player with the highest score of " << score << "is " << names << endl;
return;
}
and here is the text file im trying to read from
BASEBALL.txt --
Mike 99 First Base 2 Josh 3 Catcher 1 John 55 Left Field 2 Noah 54 Middle Field 1 Micah 15 Right Field 4 Zach 2 Short Stop 5 Chad 18 Second Base 2 Wilky 14 Thrid 10 Trevor 10 Pitcher 15
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
