Thread: Erasing the content of an array struct. 3 questions

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    10

    Unhappy Erasing the content of an array struct. 3 questions

    So, i'm trying to simulate a program that organizes clients on a plane.

    I made a menu, and i have to make 4 options;

    1. Add passengers to a seat [Check]
    2. Check reservations [Check]
    3. Erasing reservations
    4. Check available spaces.

    This is my struct;

    Code:
    struct Person { 
       char Name[65]; 
       char ID[20];
       char gender[10]; 
       int age; 
    }Vip[4][3],Smokers[9][5],Non[9][5];
    Then i have a switch to select the options, i already made 1 and 2 completely, and thank god they are working, it took me all afternoon

    Could you help me out with the two other options?

    How can i erase the content of my seats?

    And how do i make it so that it can "realize" that the seat is already taken


    How can i make it count the available seats?

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Your data organization looks sloppy. I suggest you rework out your data structure. Using classes would be nice (since this is a C++ application), but you can still improve your organization with just using structures. Here's an example:

    Code:
    enum Gender
    {
        MALE,
        FEMALE
    };
    
    struct Person {
        std::string name; 
        std::string id;
        Gender gender;
        int age; 
    };
    
    struct Seat { 
        Person person;
        bool available;
    };
    
    struct Plane {
        Seat vip_seats[4][3];
        Seat smoker_seats[9][5];
        Seat nonsmoker_seats[9][5];
    };
    I think with these type of data structures, you can easily answer the questions you have.
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    10
    thanks for your reply bithub, well, it really got me to want to learn to use those but..

    i really wouldn't know how to link them and treat them lol, i'm just a noob, the teacher knows we cant do this well cause we just started the subject but he's testing us and only a few will pass...

    I'm still trying to figure out a method to erase the structures ("removing a reservation") with my current setup

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    You can't "erase" an index from an array. That's why I added the "available" member so that you can check if a seat is taken or not.
    bit∙hub [bit-huhb] n. A source and destination for information.

  5. #5
    Registered User
    Join Date
    Jul 2010
    Posts
    10
    Oh i see, i think i figured out a way that will work to check the availabilty.

    I still HAVE to add an option that wipes the reservations clean though... how would i do that?

    Thanks for the support bithub

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    If you set the seat to "available", wouldn't that be the equivalent of deleting the reservation?
    bit∙hub [bit-huhb] n. A source and destination for information.

  7. #7
    Registered User
    Join Date
    Jul 2010
    Posts
    10
    Oh okay, that way i would make it re-writable! [i understand what i said] hahah

    that's a great idea

    BUT!!!!

    the teacher could still check the struct and it would still have the data of the passenger

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Uh right. But the task is to create a program to can add and remove reservations, no? Then the user won't "browse" the code, so for all intents and purposes, it works fine.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help about array of struct
    By rob90 in forum C Programming
    Replies: 10
    Last Post: 12-27-2009, 01:55 PM
  2. Problem with copying a string into array in a struct
    By JFonseka in forum C Programming
    Replies: 15
    Last Post: 05-04-2008, 05:07 AM
  3. Replies: 10
    Last Post: 05-18-2006, 11:23 PM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. Bi-Directional Linked Lists
    By Thantos in forum C Programming
    Replies: 6
    Last Post: 12-11-2003, 10:24 AM