having a problem with control in my program i guess. this code im posting is supposed to read data from this file and then do some things . the first function below is the first function called and then i just put in the other functions that the first function uses below.
Code:
void readCourse(ifstream &I, Instructor *S[], Course *C[] )
{
string courseDepartment;
string numStudents;
string courseNumber;
string employeeID;
int courseIndex=0;
while(!I.eof())
{
I >> employeeID >> courseDepartment >> courseNumber >> numStudents;
if(I.eof())
break;
for(int instructorIndex = LOOP_BASE;
instructorIndex < MAX_INSTRUCTORS;
instructorIndex++)
{
if(S[instructorIndex]->getEmployeeID() == employeeID)
{
C[courseIndex]= new Course(courseDepartment,
courseNumber, numStudents, S, C);
printData(S);
}
}
}
}
Code:
Course::Course(string department, string number,string students, Instructor *S[], Course *C[])
{
courseDepartment = department;
courseNumber = number;
numStudents = students;
//printCourse(S, C);
}
Code:
void printInstructor(Instructor *S)
{
cout << S->getFirstName();
printSpaces(FIRST_NAME_FIELD_WIDTH - S->getFirstName().length());
cout << S->getLastName();
printSpaces(LAST_NAME_FIELD_WIDTH - S->getLastName().length());
cout << ' ' << S->getMiddleInitial()
<< ' ' << S->getEmployeeID()<<" has been hired at XYZ"<<endl;
}
void printData(Instructor *S[])
{
for(int index = LOOP_BASE; index < MAX_INSTRUCTORS; index++)
{
if(S[index] != NULL_POINTER)
printInstructor(S[index]);
break;
}
}
But when it reads from this input file:
8300 CSE 1325 92
3942 MATH 2325 18
3942 MATH 2326 25
4301 HIST 1311 26
8300 CSE 1320 24
it keeps repeating this:
This is line number 250 of the file C:\Documents and Settings\Massa\Driver.c
pp which was
compiled on Oct 4 2002 at time 11:46:46.
Ray L. Jones 3942 has been hired at XYZ
Ray L. Jones 3942 has been hired at XYZ
Ray L. Jones 3942 has been hired at XYZ
Ray L. Jones 3942 has been hired at XYZ
Ray L. Jones 3942 has been hired at XYZ
Ray L. Jones 3942 has been hired at XYZ
Ray L. Jones 3942 has been hired at XYZ
Ray L. Jones 3942 has been hired at XYZ
Press any key to continue