S
SB
Hello. I have an input file which is laid out in the following manner...
Name
Day 1
am time 1
am time 2
appointment
pm time 1
pm time 2
appointment
Day 2
am time 1....
This is repeated for three people, for five days. So for each person (three
names), there is five days worth of the am/pm time 1/2, appointment data.
The problem I'm having is reading each line and storing it's value in the
corresponding person's class member. I have a Doctor class (which represents
a person in the file) and that class has a five element array of a Day class
(each day's data gets its own Day object). I also have a Schedule class
which contains an array of three Doctor classes. Here is the code for
reading the input file and populating the objects data members...
void Schedule::loadSchedule(ifstream& inputFile)
{
string temp; // temp variable for storing each line read from file
int i; // for doc index
int j; // for day index
// read from input file and populate each doctors data
for (i = 0; i < NUMBER_OF_DOCTORS; i++)
{
getline(inputFile, temp);
doc.setName(temp);
cout<<endl<<"name is <"<<doc.getName()<<">";
j = 0; // reset day counter for each doctor
for (j; j < NUMBER_OF_DAYS; j++)
{
// make sure we haven't accidentally read beyond the end of the file
if (inputFile.eof())
{
cout<<"End of File has been reached while reading the input
file."<<endl;
exit(1);
}
getline(inputFile, temp);
doc.setDay(i, temp);
cout<<endl<<"day is <"<<doc.getDay(j)<<">";
getline(inputFile, temp);
doc.setAmStart(i, temp);
cout<<endl<<"am start for "<<doc.getDay(j)<<" is
<"<<doc.getAmStart(j)<<">";
getline(inputFile, temp);
doc.setAmEnd(i, temp);
cout<<endl<<"am end for "<<doc.getDay(j)<<" is
<"<<doc.getAmEnd(j)<<">";
getline(inputFile, temp);
doc.setAmAppt(i, temp);
cout<<endl<<"am appointment for "<<doc.getDay(j)<<" is
<"<<doc.getAmAppt(j)<<">";
getline(inputFile, temp);
doc.setPmStart(i, temp);
cout<<endl<<"pm start for "<<doc.getDay(j)<<" is
<"<<doc.getPmStart(j)<<">";
getline(inputFile, temp);
doc.setPmEnd(i, temp);
cout<<endl<<"pm end for "<<doc.getDay(j)<<" is
<"<<doc.getPmEnd(j)<<">";
getline(inputFile, temp);
doc.setPmAppt(i, temp);
cout<<endl<<"pm appointment for "<<doc.getDay(j)<<" is
<"<<doc.getPmAppt(j)<<">";
}
}
// close the file
inputFile.close();
}
Here is the output from the cout statement in the above code...
name is <Andrew Jones>
day is <Monday>
am start for Monday is <9>
am end for Monday is <12>
am appointment for Monday is <Lecture>
pm start for Monday is <13>
pm end for Monday is <16>
pm appointment for Monday is <Free>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
name is <Eric Roberts>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <Tuesday>
am start for Tuesday is <9>
am end for Tuesday is <12>
am appointment for Tuesday is <Free>
pm start for Tuesday is <13>
pm end for Tuesday is <16>
pm appointment for Tuesday is <Surgery>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
name is <Mathew Hayden>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <Wednesday>
am start for Wednesday is <9>
am end for Wednesday is <12>
am appointment for Wednesday is <Free>
pm start for Wednesday is <13>
pm end for Wednesday is <16>
pm appointment for Wednesday is <Lecture>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
The problem is the empty less than/greater than signs. I don't know why data
is not being populated for those values. Is it the way I'm using getline or
something? Interestingly, the less than/greater than signs that do contain
data are all correct. I matched them up with the data in the input file and
it matches. So the values that are getting populated are being done in the
correct order. Can anyone see what I'm doing wrong here? Any help is
appreciated!
Thank you in advance!
Name
Day 1
am time 1
am time 2
appointment
pm time 1
pm time 2
appointment
Day 2
am time 1....
This is repeated for three people, for five days. So for each person (three
names), there is five days worth of the am/pm time 1/2, appointment data.
The problem I'm having is reading each line and storing it's value in the
corresponding person's class member. I have a Doctor class (which represents
a person in the file) and that class has a five element array of a Day class
(each day's data gets its own Day object). I also have a Schedule class
which contains an array of three Doctor classes. Here is the code for
reading the input file and populating the objects data members...
void Schedule::loadSchedule(ifstream& inputFile)
{
string temp; // temp variable for storing each line read from file
int i; // for doc index
int j; // for day index
// read from input file and populate each doctors data
for (i = 0; i < NUMBER_OF_DOCTORS; i++)
{
getline(inputFile, temp);
doc.setName(temp);
cout<<endl<<"name is <"<<doc.getName()<<">";
j = 0; // reset day counter for each doctor
for (j; j < NUMBER_OF_DAYS; j++)
{
// make sure we haven't accidentally read beyond the end of the file
if (inputFile.eof())
{
cout<<"End of File has been reached while reading the input
file."<<endl;
exit(1);
}
getline(inputFile, temp);
doc.setDay(i, temp);
cout<<endl<<"day is <"<<doc.getDay(j)<<">";
getline(inputFile, temp);
doc.setAmStart(i, temp);
cout<<endl<<"am start for "<<doc.getDay(j)<<" is
<"<<doc.getAmStart(j)<<">";
getline(inputFile, temp);
doc.setAmEnd(i, temp);
cout<<endl<<"am end for "<<doc.getDay(j)<<" is
<"<<doc.getAmEnd(j)<<">";
getline(inputFile, temp);
doc.setAmAppt(i, temp);
cout<<endl<<"am appointment for "<<doc.getDay(j)<<" is
<"<<doc.getAmAppt(j)<<">";
getline(inputFile, temp);
doc.setPmStart(i, temp);
cout<<endl<<"pm start for "<<doc.getDay(j)<<" is
<"<<doc.getPmStart(j)<<">";
getline(inputFile, temp);
doc.setPmEnd(i, temp);
cout<<endl<<"pm end for "<<doc.getDay(j)<<" is
<"<<doc.getPmEnd(j)<<">";
getline(inputFile, temp);
doc.setPmAppt(i, temp);
cout<<endl<<"pm appointment for "<<doc.getDay(j)<<" is
<"<<doc.getPmAppt(j)<<">";
}
}
// close the file
inputFile.close();
}
Here is the output from the cout statement in the above code...
name is <Andrew Jones>
day is <Monday>
am start for Monday is <9>
am end for Monday is <12>
am appointment for Monday is <Lecture>
pm start for Monday is <13>
pm end for Monday is <16>
pm appointment for Monday is <Free>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
name is <Eric Roberts>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <Tuesday>
am start for Tuesday is <9>
am end for Tuesday is <12>
am appointment for Tuesday is <Free>
pm start for Tuesday is <13>
pm end for Tuesday is <16>
pm appointment for Tuesday is <Surgery>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
name is <Mathew Hayden>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <Wednesday>
am start for Wednesday is <9>
am end for Wednesday is <12>
am appointment for Wednesday is <Free>
pm start for Wednesday is <13>
pm end for Wednesday is <16>
pm appointment for Wednesday is <Lecture>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
The problem is the empty less than/greater than signs. I don't know why data
is not being populated for those values. Is it the way I'm using getline or
something? Interestingly, the less than/greater than signs that do contain
data are all correct. I matched them up with the data in the input file and
it matches. So the values that are getting populated are being done in the
correct order. Can anyone see what I'm doing wrong here? Any help is
appreciated!
Thank you in advance!