We are beginners in C++, and we have an assignment due on Wed. We are to create an input file, scores.txt, to contain a list of no more than 32 student records. Each record will have the following format:
<last name><sp><firstname><sp><p01><sp>...<p05><sp><hw01 ><sp>...<hw12><sp>
We have to declare 2D arrays for lastname, firstname, and grades. We already have that finished. We are having trouble reading in the input file, scores.txt, to the array and then returning the length. If anyone could tell us if that is correct or at least almost correct, we'd appreciate it.
Thanks in advance.
Here's what we have so far:
using namespace std;
const char LNAME_SIZE = 20;
const char LAST = 32;
int readScores(ifstream& scores_file, ofstream& records_file, const char lname[LNAME_SIZE + 1], int length);
// reads scores.txt into the arrays and returns the length
char lname[LAST][LNAME_SIZE + 1];
// connect the input stream to the file scores.txt
// tests the input stream
if ( fin.fail() )
cerr << "Error opening file scores.txt for reading. Aborting!"
// connect the output stream to the file records.txt
// tests the output stream
if ( fout.fail() )
cerr << "Error opening file records.txt for reading. Aborting!"
length = readScores(fin, fout, lname, length);
}// end of main()
int readScores(ifstream& scores_file, ofstream& records_file, const char lname[LNAME_SIZE + 1], int length)
while ( !scores_file.eof() )
for (int row = 0; row < 1; row++)
for (int col = 0; col < 1; col++);
length = lname[row][col];
records_file << lastName;
}// end readScores()