Thread: homework help about ofstream/ifstream.. help PLZ

  1. #1
    Registered User
    Join Date
    Dec 2001

    Red face homework help about ofstream/ifstream.. help PLZ

    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.


    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;"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 << << '\t'
    << current.first << '\t'
    << current.last << '\t'
    << current.grade <<'\t'
    << current.gender<< '\t'
    <<<< endl;
    cout << "ID number "<< id1 << " not found.\n";



    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
    int i=0;

    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:


    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

  2. #2
    Registered User
    Join Date
    Dec 2001
    You need to have a student class with the same number of arguments matching the types of data in the file. Such as: name, id , grade,gender and birthdate. Name will probably be a string object so you don't have two; it makes it simpler. When a class such as 'student' is made, it will store all of the info within it. The member functions for this class would probably be just a getdata function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. Help with Homework plz!
    By mythassassin in forum C++ Programming
    Replies: 4
    Last Post: 10-16-2007, 03:07 PM
  3. Need help with homework assignment plz..
    By RVDFan85 in forum C++ Programming
    Replies: 13
    Last Post: 10-05-2006, 10:33 PM