DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2007

    Airplane Seating Program Problem

    Hello my friends and I have been reading several C++ tutorials online and reading many books, my all time favorite is C++ for dummies:) because it is simple to understand. Me and my friends are bored and have decided to create a little game, but we have to learn to program before we make that leap. My brother's friend gave us an interesting problem to solve to test our knowledge so far and I would have to say it has not been going to good. What the problem he gave us is we have to create a program that:
    1) Prints out the seating chart of a airplane
    2) Reserve a seat
    3) Unreserve a seat
    4) Exit the program

    Me and my friends have decided that we will be using multidimensional arrays since we have just learned them to print out our seating chart 8x6. Then instead of using a bunch of loops and cout statements we were going to try to save a text file and load that which we kinda are trying to solve that. What we are stuck on is when we ask the user to Reserve a seat or unreserve a seat it will save it and when the user wants to print the seating chart it will show that the seat they reserved is reserved with the character 'R' and any empty seat will be set with 'E' for empty. Also confused on how to enter and print out input from an array? This is what we have so far:

    #include <iostream>
    #include <fstream>
    using namespace std;
    void print(), reserve_seat();
    void unreserve_seat(), reset_chart();
    void exit();
    char seat[8][6];
    ifstream fin;
    ofstream fout;
    bool quit = false;
    int main ()
        char menu_option;
        fin.open ("Seat Reservations.txt");
        if (fin.fail())
            cout << "\a";
            for (int x = 0; x <= 8; x++)
                for (int y = 0; y <= 5; y++)
                    seat[x][y] = 'E';
            for (int x = 0; x <= 8; x++)
                for (int y = 0; y <= 5; y++)
                    fin >> seat[x][y];
        fin.close(   ) ;
            cout << "Airplane seat reservation program\n" << endl;
            cout << "1: Print seating chart\n"
                 << "2: Reserve a seat\n"
                 << "3: Un-reserve a seat\n"
                 << "4: Reset seating chart\n"
                 << "5: Exit program\n"
                 << endl
                 << "Make a selection: ";
    while (!quit)
            cin >> menu_option;
            switch (menu_option)
                   case 1:
                   case 2:
                   case 3:
                   case 4:
                   case 5:
                           cout << "Wrong Choice Please Choose Again!\n";
    return 0;
    void print()
         cout << "Print Chart\n";
    void reserve_seat()
         cout << "Reserve Seat\n";
    void unreserve_seat()
         cout << "Unreserve Seat\n";
    void reset_chart()
         cout << "Reset Chart\n"; 
    void exit()
         cout << "Exit\n";    
    We were also thinking about not using the fstream and saving it to a file and loading it because this seems to high advance for our level, but I dunno.
    A B C D E F
    1 E E E E E E
    2 E E E E E E
    3 E E E E E E
    4 E E E E E E
    5 E E E E E E
    6 E E E E E E
    7 E E E E E E

    Thats what we are shooting for, we hope :)

    Thank you for the help
    and Have a Happy Thanksgiving!

  2. #2
    Join Date
    Oct 2005
    when the user ask to reserve a seat, he should input the col number and the row number, for example D 7 ..
    map this input to the array indexes, like if your array hold from 0 to 6 indexes in rows ... so the input should be entred in the index number input-1 , in this case 7 in (7-1) which is 6 ..
    for the col. you can do the same thing after converting the character to an integer value and substracting the constant difference ..
    finally his reservation should change the array [6][3] , I assume the array is of the type char, and directly assign in this location the "R" or "E" in case of unreservation ...
    to display the array you need 2 nested loops, one goes from row 0 to 5 inside another which does from col 0 to 6 ...

    Hope this can helps .
    Programmer&Cracker CS

Similar Threads

  1. Help with Server program
    By sedricbenson@ho in forum C++
    Replies: 2
    Last Post: 11-07-2006, 08:18 AM
  2. Problem with Roulette Program
    By persianjewunit in forum Java
    Replies: 2
    Last Post: 05-15-2006, 07:13 PM
  3. The invisible program
    By James Abbott in forum VB Classic
    Replies: 0
    Last Post: 11-24-2001, 01:42 AM
  4. Replies: 1
    Last Post: 06-08-2001, 12:06 PM
  5. Airplane seating
    By Mikel in forum Java
    Replies: 0
    Last Post: 04-07-2000, 06:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.