I have to submit a lab today, i was absent for the previous lecture, i really don't know whats going on. I want to learn how to do this and that's why i am not copying it directly from someone.
The Question is
Functions Needed
int readRoster(char name[][20], int number[], int hr[])
Prompt the user for the input file name. Open the file and read all of the players in the file. The players will be in the following format:
Number firstName lastName HomeRuns
You will need to use strcpy and strcat. I will show these in class. After reading in all the players return the number of players on the roster.
void printRoster(char name[][20], int number[], int hr[], int numPlayers)
Print out all the players in your arrays. Players number on the left followed by players name and then in parentheses the number of homeruns.
void sortNumber(char name[][20], int number[], int hr[], int numPlayers)
Implement the bubble sort to sort based on the players number.
void sortHR(char name[][20], int number[], int hr[], int numPlayers)
Implement the bubble sort to sort based on the home runs.
Main function
Declare arrays to hold all of our data.
char name[20][20];
int hr[20];
int number[20];
int numPlayers;
Read in the Players
Print Roster
Sort on Number
Print Roster
Sort on Home Runs
Print Roster
Turn in the following:
1. Source code from the problem (.cpp file)
2. Output from your program
--
Code i compiled uptil now
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cstdlib> // for user input
using namespace std;
int readRoster(char name[][20], int number[], int homeRuns[]);/*
Prompt the user for the input file name. Open the file and read all of the
players in the file. The players will be in the following format:
Number firstName lastName HomeRuns
You will need to use strcpy and strcat. I will show these in class. After
reading in all the players return the number of players on the roster.*/
int main ()
{
int numPlayers;
char name[20][20];
int homeRuns[20];
int number[20];
numPlayers = readRoster(name, number, homeRuns);
cout << endl << "The Total number of players are ... " << numPlayers;
return 0;
}
int readRoster(char name[][20], int number[], int homeRuns[])
{
int numPlayers =0;
ifstream inFile;
string filename;
string a;
bool keepReading = true;
cout << "Please enter filename: ";
cin >> filename;
inFile.open(filename.c_str());
while(!inFile.eof())
{
// use getline to read entire line
cin.ignore();
getline(inFile, a);
cout << a << endl;
numPlayers++;
}
return numPlayers;
}
Also how would i assign things like to their respective variables?
12 A.J. Pierzynski 14
24 Joe Crede 4
15 Tadahito Iguchi 6
14 Paul Konerko 31
5 Juan Uribe 12
The prof said he is going to give us a file with data similar to this, first numers are playerNumbers, second word it first name, third word is last name and fourth numbers are noOfHomeRuns.
I want to take an input from the user (just file name, and will will have a data with similar format), and then assign it to thier respective variables could someone tell me how to do that also?
I have to submit this program by midNight tonight or else i lose 50% of the grade, could anyone help me out? I am not asking you to write the entire code for me, but help walk me through. If you are around chicago, i could buy u a couple beers on the weekend or something...