quick question

This is a discussion on quick question within the C++ Programming forums, part of the General Programming Boards category; Hi! I have a quick question. I am doing a project for my C++ OOD class and I'm creating a ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    16

    Question quick question

    Hi! I have a quick question. I am doing a project for my C++ OOD class and I'm creating a program for a reservation system for an airline. I'm trying to find a way to store information for five planes with 30 seats for each plane which includes 2 rows of 6 seats for first class and 3 rows of 6 seats for economy class. I'd like to display the info like:

    Chicago Plane

    First Class 1a 2a 3a 4a 5a 6a

    First Class 1b 2b 3b 4b 5b 6b

    Economy 1c 2c 3c 4c 5c 6c

    Economy 1d 2d 3d 4d 5d 6d

    Economy 1e 2e 3e 4e 5e 6e


    Should I use a multidimensional array to accomplish this or is there an easier way to do this? Sorry, still pretty new to this.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Sure, a multidimensional array would be one way to do it. But you'd probably end up with a pretty big and complicated variable.

    I'd suggest something more like this.
    Code:
    class seat {};
    
    class plane {
        seat firstclass[2][6];
        seat economyclass[3][6];
    };
    
    class airline {
        plane flight[5];
    };
    You could represent the seats as a simple array with 30 elements as well. It depends on how you want to reference the data.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    16

    Reservation

    I forgot, I'm sorry. I have to have 30 days worth of reservation seats available for 5 planes with 30 seats. How would I initialize the values for this? I don't want to initialize them all individually...seems like that would be a waste. I'm racking my brain trying to figure how to do this. I'm going to display the seat spread for that day and plane and then ask them which they would like to cancel or book.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I don't understand what you're trying to do, but never ever use something like this:
    Code:
    seat seat1;
    seat seat2;
    seat seat3;
    /* ... */
    It's just stupid. That's what arrays are for.

    If you're worried about having to go
    Code:
    seat[0] = 0;
    seat[1] = 0;
    then do it in a loop or create a constructor for the class that does the initialization for you.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Or use a vector which initializes to 0 automatically.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Or if all you're doing is initializing to zero, for arrays, use
    Code:
    int array[N] = {};
    or "= {0}" for C compatibility.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21