C++ I/O functions and struct with arrays and strings

Hey im new to c++ and am having a really hard time with this program, please help!

Im supposed to design a program to read racers from a text file, sort them by ranking their race times, and print it to a new data file.

Each racer was identified with a Bib number and raced twice in the blue race course and twice in the red race course. A racer's combined time is their fastest blue-race + their fastest red-race. The fastest(lowest) total time will be the winner of the evening's race event. Rank the racers.

The datafile datatypes will conform to the following format:

char[]\n
char[]\n
char[]\n
int\t char[]\t int\t char\t double\t double\t double\t double\n
int\t char[]\t int\t char\t double\t double\t double\t double\n
int\t char[]\t int\t char\t double\t double\t double\t double\n
...
...
...
int\t char[]\t int\t char\t double\t double\t double\t double\n
int\t char[]\t int\t char\t double\t double\t double\t double\n
EOF

The first to third lines are char[]'s and can be considered to be lines of titles.
From the fourth line on:
the first int is the bib#;
the char[] is the racer's first and last name;
next is the int with the racer's age;
then the char for the racer's gender;
the first double is the first blue racecourse time; the second double is the first red racecourse time;
the third double is the second blue racecourse time, and the fourth double is the second red racecourse time.


My biggest problem is passing values between the functions i have no clue how to set up my function prototypes, I supposed to use pass by value, reference, and array reference. I dont even know what my parameters are.

I have no clue whats wrong with it, and it is a lot, or where to start to fix it, ive been working on it for over a week and cant get anything going, please help me! I have started the program like this:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

struct Racer_struct
{
int rank;
int bib;
string name;
int age;
char gender;
double b1, b2, r1, r2;
double totalTime;
};

int readRacers(ifstream& fin, Racer_struct racers[], int& SIZE);
void sortRacers(Racer_struct racers[], int SIZE);
void printToFile(ofstream& fout, Racer_struct racers[], int& SIZE);

int main()
{
int SIZE;
Racers_struct racers[];
char slalom[];
ifstream fin;
ofstream fout;

fin.open("racerF2010.txt");
fout.open("ranked.dat");

if(fin.fail() || fout.fail())
{
cout << "One or both files could not be opened." << endl;
exit (1);
}
while(!fin.eof())
{
readRacers(?????)
sortRacers(?????)
printToFile(?????)
}
fout.close();
fin.close();
return 0;
}

int readRacers(ifstream& fin)//dont know what goes in for parameters...
{
//dont know how to setup the read from file function...
}

void sortRacers(Racer_struct racers[].....)//dont know what goes inside function for parameters...
{
Racer_struct temp;

for(int i=0; i<SIZE-1; i++)
{
for(int j=i+1; j<SIZE; j++)
{
if(racers[i].totalTime>racers[j].totalTime)
{
temp=racer[i];
racers[i]=racers[j];
racers[j]=temp;
}
}
}
return;
}

void prinToFile(ofstream& fout, racer_struct racers[], int& SIZE)//dont know what goes inside for function parameters or how to setup the print to file function...
{
for(int i=0; i<SIZE; i++)
{
fout << i+1 << "Place: "
<< racers[i].bib << "\t" << racers[i].name << "\t"
<< racers[i].age << "\t" << racers[i].gender << "\t"
<< racers[i].b1 << "\t" << racers[i].r1 << "\t"
<< racers[i].b2 << "\t" << racers[i].r2 << endl;
}
return;
}
Topic archived. No new replies allowed.