Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • C Structure

    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 803
    Answer it

    Im a Network Admin and start Learning Programming,I start with C and reading a book. anyone can help answer and explain to me how to come up with it.

    1.Write a structure that is to be used with a binary tree. The structure is to hold title name and phone number of everyone in your city or town.

    2.Write a code for the data type that is necessary to create a data type that will store a social security number of the format 999-99~9999. Dont use simple character array,Use structure.

 2 Answer(s)

  • Here is the general syntax of declaring a structure
    struct structure_name
    {
    data_type variable_name1;
    data_type variable_name2;
    .
    .
    data_type variable_nameN;
    };
    You can create any custome data type using structure.

    1. For your first question, you can use following structure
      struct node { char name[100]; char phoneNumber[16]; struct node *left; struct node *right; }

    2. For your second question you can use following structure
      struct node { int left, middle, right; }

    I will recommend you to check this C tutorial on structure and binary tree data structure.

  • When they are talking about structures in C, they mean struct. A struct is a lot like a class except a struct 's data members will be public by default.

    include

    struct Title{ string name; string phone_number;

    };

    //data type is another name for struct too

    struct SSN{ string prefix ="999"; string center="99"; string post="9999"; };

    Now, within the struct you can create methods to validate the numbers and other information.

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: