Initialisation of a struct

This is a discussion on Initialisation of a struct within the C++ Programming forums, part of the General Programming Boards category; Hi guys i m supposed to initialise 30 tables Code: struct TableType { int tableNo; int maxNoOfGuests; AnsiString arrivaltime; AnsiString ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    10

    Initialisation of a struct

    Hi guys
    i m supposed to initialise 30 tables

    Code:
    struct TableType
    {
    
    int tableNo;
    int maxNoOfGuests;
    AnsiString arrivaltime;
    AnsiString name;
    int noOfGuests;
    
    }
    therefore it shd be TableType total[30];

    now i want to initialise the following

    5 tables iwth sitting capacity of 2
    5 table of 4
    10 table of 10
    10 table of 15

    any guru can advice how should we be doing it??

  2. #2
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Read a tutorial. Learn the language.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    how you do it depends on what your AnsiString type is... if it's just a char pointer, use the new and delete operators...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  4. #4
    Registered User Kurisu's Avatar
    Join Date
    Feb 2006
    Posts
    62
    Quote Originally Posted by ahluka
    Read a tutorial. Learn the language.
    Ouch dude, that is kinda harsh
    -----------------------------
    As for the question you can just use a loop structure to initialize your values.

    Code:
    TableType total[30];
    
    for(int index = 0; index < 5; index++)
    {
       total[index].maxNoOfGuests = 2;
    }
    
    for(int index = 5; index < 10; index++)
    {
      total[index].maxNoOfGuests = 4;
    }
    
    ...
    Last edited by Kurisu; 03-31-2006 at 01:43 AM.

  5. #5
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    >> Ouch dude, that is kinda harsh

    I'm having one of those days, he was closest to my cursor.


    I wish I had stayed in bed.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segfault with Linked List Program
    By kbrandt in forum C Programming
    Replies: 1
    Last Post: 06-23-2009, 07:13 AM
  2. Replies: 16
    Last Post: 10-29-2006, 04:04 AM
  3. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  4. Function validation.
    By Fhl in forum C Programming
    Replies: 10
    Last Post: 02-22-2006, 07:18 AM
  5. Search Engine - Binary Search Tree
    By Gecko2099 in forum C Programming
    Replies: 9
    Last Post: 04-17-2005, 02:56 PM

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