Thread: Help with possible triple-nested structure.

  1. #1
    Registered User
    Join Date
    Apr 2014
    Location
    New York
    Posts
    52

    Help with possible triple-nested structure.

    Hello all, I'm trying to make a political card game using continents, countries, and states as areas that two sides vie to control.

    I think I need to use structures. One for the continents, one for the countries, and one for the states.

    My current problem is how to set this up in code. Do I say that the continent structure contains the country structure and the state structure? Or, do I say the continent structure contains the country structure which contains the state structure?

    Or, is it the opposite, where the the continent structure is contained in the country structure. And the country structure is contained in the state structure?

    Some pseudo code to demonstrate what I'm thinking about:

    Code:
    struct Continent
    {
        int stuff;
    };
    
    struct Country
    {
        struct Continent info;
        int more_stuff;
    };
    
    struct State
    {
        struct Country more_info;
        int other_stuff;
    };
    
    or
    
    struct Continent
    {
        int stuff;
    };
    
    struct Country
    {
        struct Continent info;
        int more_stuff;
    }; 
    
    struct State
    {
        struct Continent info;
        struct Country more_info;
        int other_stuff;
    };
    Any help would be... helpful

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,533
    Can a country be on more than one continent?

    Can a state have more than one country?
    Country and state are pretty synonymous, unless you're counting odd-balls like the Vatican (a state) within a country (Italy).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    794
    I would choose the second one. However, do all countries have "States"? How are other countries subdivided, or not?
    How would you handle the difference in Politics in the various countries?

  4. #4
    Registered User
    Join Date
    Apr 2014
    Location
    New York
    Posts
    52
    My apologies, I had a difficult time wording my question. In this case 'state' would also mean province or territory, or some other sub-division of a county.

    I am concerned about my second option, in that the struct Country contains the struct Continent and the struct State contains the structs Continent and State.
    Wouldn't the struct State contain two of the struct Continent? One by itself and the one contained in struct Country?

    If I need to do a better job of explaining what I'm trying to do, please let me know.

  5. #5
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    794
    The whole this is very complex. Countries spanning Asia and Europe, Italy that contains separate "Countries", The Vatrican and San Marino. Countries that have no concept of divisions, and probably other complications I don't even know about. Then there is the whole discussion of the differences of "Politics" in various countries.

    I would define the simple versions of the structs as:
    Code:
    struct Continent
    {
        int stuff;
    };
     
    struct Country
    {
        struct Continent info;  //Multiples?
        int more_stuff;
    }; 
     
    struct State
    {
        struct Country more_info;
        int other_stuff;
    };
    Or:

    Code:
    struct Continent
    {
        int stuff;
    };
     
    struct State
    {
        int other_stuff;
    };
    
    struct Country
    {
        struct Continent info; // Multiples?
        struct state[X];  //Array of "States" or "Divisions"
         int more_stuff;
    };
    Good luck!

  6. #6
    Registered User
    Join Date
    Sep 2020
    Posts
    193
    Data models are hard!

    How about using the more abstracted 'regions' structure?

    Countrys could be owners of regions...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Nested Structure help ~
    By Siaw in forum C Programming
    Replies: 6
    Last Post: 10-09-2011, 02:59 AM
  2. Nested Structure help ~
    By Siaw in forum C Programming
    Replies: 32
    Last Post: 10-09-2011, 01:48 AM
  3. pointer to nested structure
    By wahid in forum C Programming
    Replies: 2
    Last Post: 11-10-2010, 04:05 AM
  4. Triple structure
    By dpp in forum C++ Programming
    Replies: 13
    Last Post: 06-25-2009, 11:42 PM
  5. nested structure help
    By whistler in forum C Programming
    Replies: 1
    Last Post: 05-17-2002, 10:48 AM

Tags for this Thread