Figure I might as well go ahead and clear up that this is obviously a school assignment. I have completed a somewhat decent amount of code (not saying I have a lot of faith in it's correctness tho) and need assistance to figure the rest out. I'm at a complete loss due to teacher and book not really covering material in a way to prepare for the assignment. I have looked over the tutorials for I/O on this site as well as others and if I need to change things, I'm wide open for assistance. I did attempt to figure out as much as I could, but I'm stuck. Thanks in advance for anyone who takes time to assist me. I greatly appreciate it.
To clear things up from the start, here are the instructions:
The program is to take a text file, students.txt, containing information about the currently-enrolled students in a school. Each
line represents a record for a different student and contains the student's identification number (eight digits), credit hours
completed, and grade point average. A sample line follows:
10082352 66 3.04
Program is supposed to have the identification number and grade point average for each student in the file copied to one of four
different text files based on the number of credit hours completed:
Less than 32 freshmen.txt
32 to 63 sophomores.txt
64 to 95 juniors.txt
96 or more seniors.txt
Next is to write the identification number and grade point average of each student on a single line (one line per student) in the
appropriate file. For example, since the student mentioned above has completed 66 credit hours, the following would be
added to the file juniors.txt:
10082352 3.04
The number of students in the original file is unknown, so the program will need to read these records in until you reach the end of
the file.
Also, no student should have a negative number of credit hours, and the maximum number of credit
hours that a student can accumulate is 250. If the program encounters a student record with an erroneous number of
credit hours, write the entire record for that student (identification number, credit hours, and grade point average) to the
file hoursError.txt rather than any of the four aforementioned files. The lowest grade point average a student may have is 0.0, and the highest grade point average a
student may have is 4.0. If the program encounters a student record with an erroneous grade point average, write the
entire record for that student to the file averageError.txt rather than any of the four aforementioned files.As was previously stated, the student's identification number should be eight digits. If the program
encounters a student record with an identification number of fewer or greater than eight digits, write the entire record for
that student to the file identError.txt rather than any of the four aforementioned files.Assume that an identification number error has highest precedence, then the
number of credit hours completed, then the grade point average. Don't write a student record to multiple error files: only
the one that has the highest precedence should receive the record.
I'm going in the direction that I believe it needs to have the input file made into a dynamic array, but not sure how to do that.
Here is the code I have with compiler errors formatted within brackets after comment code. e.g. //[compiler error]
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
/** [ I get the "unknown size" error on all of these b/c I don't know how to assign them ] */
int studentID[];
int creditHours[];
double gpa[];
int main()
{
int studentID[];
int creditHours[];
int gpa[];
ifstream students;
ofstream freshman, sophomores, juniors, seniors;
ifstream in_stream;
in_stream.open("students.txt");
if (in_stream.fail())
{
cout<< "Input file opening failed.\n";
exit(1);
}
ofstream out_stream;
out_stream.open("freshmen.txt");
out_stream.open("sophomores.txt");
out_stream.open("juniors.txt");
out_stream.open("seniors.txt");
out_stream.open("hoursError.txt");
out_stream.open("averageError.txt");
out_stream.open("identError.txt");
if (out_stream.fail())
{
cout<< "Output file opening failed.\n";
exit(1);
}
out_stream.setf(ios::fixed);
out_stream.setf(ios::showpoint);
out_stream.precision(2);
while (!students.eof())
{
void getInput(ifstream students, int &studentID, int &creditHours, int &gpa);
}
/** [ error C2446: '<' : no conversion from 'int *' to 'int' There is no context in which this conversion is possible ] & [ error C2040: '<' : 'int' differs in levels of indirection from 'int []' ] */
for (int i=0; i < studentID; i++)
out_stream << studentID[i] << creditHours[i] << gpa[i] << endl;
in_stream.close();
out_stream.close();
}
/** [ error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ]*/
getInput(ifstream students, int &studentID, int &creditHours, int &gpa);
// [ error C2447: '{' : missing function header (old-style formal list?) ]
{
int i = 0;
while(!students.eof())
{
students >> &studentID[i] >> &creditHours[i] >> &gpa[i];
cout << studentID[i] << creditHours[i] << gpa[i] << endl;
i++;
}
return;
}
Thanks again for anyone who has patience to assist me. It's greatly appreciated.