Thread: stuck with file system ....

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    55

    stuck with file system ....

    i am now doing a Flight Reservation System using classes and file system ...

    i know how to store data about passengers info into a file and store flight info into another file.

    the problem now is:

    Example of flight info:
    From: US
    To: Aust
    Departure: 1200
    Arrival: 1800

    the flight info is saved in the flight.dat

    Example of passenger info:
    Name: Amy
    Flight: US to Aust

    the passenger info is saved in the passenger.dat.

    Each flight can takes up to 20 passengers.
    how am i suppose to reserved a place for Amy ?
    Last edited by stalker; 10-27-2003 at 09:00 AM.

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    well. in addition to the flight information about departure and arrival, etc., each flight "has a" group of passengers. How you define the group of passengers is up to you. In C++ the group is frequently referred to as a container. Commonly used containers outside of STL include arrays and lists, whereas with STL you also have queues, dequeues, maps, etc. depending on your need. You try to match up the container for the task and your knowledge. In your case declaring an array of passengers of a predetermined size as a data member for each flight seems like a reasonable choice, but you can use whatever you like/feel comfortable with. It would be wise to consider what the default constructor for the passenger class does as that's what will be used to reserve memory for the container you choose.

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    55
    elad ... i dont get what you mean about declaring array. i dont know anything about STL also. mind showing me some example ?

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Code:
    struct book
    {
       long ID;
       int numAvailable;
    };
    
    struct Library
    {
      book books[2];
    //A Library "has a" group, here an array, of books.  Simplistic use of composition, but illustrates use of a group of user defined class/struct in another class/struct
    };
    
    int main()
    {
       Library myLibrary; //declare a Library
    
       //populate the Library
       myLibrary.books[0].ID = 4365;
       myLibrary.books[0].numAvailable = 1;
       myLibrary.books[1].ID = 1111;
      myLibrary.books[1].numAvailable = 2;
      
      //have user request a book
      cout << "which book number do you want?" << endl;
      long inputID;
      cin >> inputID;
      
      int i;
      bool found = false;
    
      //check the Library to see if the book is there
      for(i = 0; i < 2; ++i)
      {
         if(inputID == myLibrary.books[i].ID)
         { 
            //the book is in the Library
            found = true;
    
            //tell how many copies are available
            cout << "there are " << myLibrary.books[i].numAvailable << " copies of book # " << myLibrary.books[i].ID << " available." << endl;
    
            //stop search
            i = 3;
          }
       }
        //if book not found in Library let user know
        if(!found)
          cout << "sorry, we don't have a book with ID number " << inputID << " available.  Please check with your local university book store." << endl;
    }
    Last edited by elad; 10-27-2003 at 12:32 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM