here is the given code.
basically the program is supposed to open up the .txt file and save the data from the .txt to an apvector.
---------------------------
#include<fstream.h>
#include"apstring.cpp"
#include"apstring.h"
#include"apvector.h"
struct student
{
int id;
apstring last;
apstring first;
int grade;
char gender;
apstring bd; // birthdate
};
apvector <student> getStudents( ifstream list );
student getData( apvector <student>, int );
void main()
{
ifstream idFile;
idFile.open("idp4.txt");// means ID number period 4,
// if that clarifies anything
apvector <student> p4 ( getStudents ( idFile ) );
int id1;
cout << "Enter an id number: ";
cin >> id1;
student current = getData ( p4, id1 );
if( current.last != "Not Found" )
{
cout << current.id << '\t'
<< current.first << '\t'
<< current.last << '\t'
<< current.grade <<'\t'
<< current.gender<< '\t'
<< current.bd<< endl;
}
else
cout << "ID number "<< id1 << " not found.\n";
idFile.close();
}
apvector <student> getStudents( ifstream list )
/* pre: list is open and contains student data as follows
id number
last name
first name
grade level ( 9 10 11 12 )
gender ( m f )
birthday ( day/month )
post: data in file is stored in an apvector of type student
*/
{
apvector<students>person;
int i=0;
while(list>>person[i].id)
{
student getData( apvector <student> thisClass, int thisID )
/* pre: thisClass is initialized as is thisID
post: returns student data for matching id if found
if id is not found, returns a student with "Not Found"
in the last name field
*/
{
-------------------------
ok that's it... I have a few questions
for... apvector<students>getStudents (ifstream list) ... I know I'm supposed to make something like:
apvector<students>person;
person[i].id=
person[i].last=
person[i].first=
person[i].grade=
person[i].gender=
person[i].bd=
with a loop or something.. but what I don't get is how the program giong to know where the first person's info starts/ends and second person's begins...
How do you store a person's info in an apvector if the .txt is one big file with everyone's name/ID/birthdate/grade lvl... etc.? It doesn't know when the second person's info begins, so then I don't know when to save person[i].id... beacuse I think I'm gonna save the entire .txt file to "person[i].id" or something..
kinda confusing here but help plz