Need help naming data structures

This is a discussion on Need help naming data structures within the C++ Programming forums, part of the General Programming Boards category; //I'm learning to make a simple program that allows the user to create profiles which store information on each person. ...

  1. #1
    AP2
    AP2 is offline
    Registered User
    Join Date
    May 2002
    Posts
    2

    Question Need help naming data structures

    //I'm learning to make a simple program that allows the user to create profiles which store information on each person. I got the whole create a structure thing but I need to know how to let the user type in what they want the name of the structure to be (since there will be different names). Rather than a set name for the structure. Take a look at my code:

    #include <iostream.h>
    #include <string.h>
    #include <stdio.h>

    struct database
    {
    char name[30];
    float id_number;
    };

    int main()
    {

    struct database employee;

    char input_name[30];
    float input_id;

    printf("Name: ");
    cin.getline(input_name,30,'\n');
    printf("ID: ");
    cin>>input_id;


    strcpy( employee.name, input_name);
    employee.id_number = input_id;


    printf("\nName = %s", employee.name );
    printf("\nSalary = %6.2f", employee.id_number );

    return 0;
    }

    //Right now it asks the user to input some information, and reports it under the structure titled "employee". What if I don't want "employee". I want them to choose what goes there. I'm sure this is beginners stuff to you guys so I'll thank you in advance for all the advice. Thanks.

    //Mike

  2. #2
    Unregistered
    Guest
    It's quite simple.... you can't do it the way you like to do it... You can, on the other hand, get the same effect by using an std::map<char*, database*>, and store the name as search key and the employee structure as value...

  3. #3
    Ted
    Ted is offline
    Registered User
    Join Date
    Aug 2001
    Posts
    52
    The user does not name the structure, you do. The user only enters the required data and your program writes it to a (disk)
    file for storage. The file is either developed as a sequential or random access file.

    Think of it as a file of student name(s) with thier course(s)
    numbers, grades, instructors names, SSN.
    Code:
        struct database 
        { 
            char nameLast[15]; 
            char nameFirst[10]; 
            char ssn[10];
            char crsNum[9]; 
            char instName[15]
        };
    hth,

  4. #4
    AP2
    AP2 is offline
    Registered User
    Join Date
    May 2002
    Posts
    2
    Originally posted by Unregistered
    You can, on the other hand, get the same effect by using an std::map<char*, database*>, and store the name as search key and the employee structure as value...
    ahh. I'm gonna learn to use that method. Not sure exactly how to use std::map<char*, database*> right now.. anyone care to elaborate? Or point me in the right direction?

  5. #5
    Ted
    Ted is offline
    Registered User
    Join Date
    Aug 2001
    Posts
    52
    I think you might want another approach. Learn the basics first
    than get advanced. However, you can review the following if
    you think it will help.
    Code:
    CMap
    
    template< class KEY, class ARG_KEY, class VALUE, class
    ARG_VALUE >class CMap : public CObject
    
    Parameters
    
    KEY
    
    Class of the object used as the key to the map.
    
    ARG_KEY
    
    Data type used for KEY arguments; usually a reference to KEY.
    
    VALUE
    
    Class of the object stored in the map.
    
    ARG_VALUE
    
    Data type used for VALUE arguments; usually a reference to VALUE.
    
    Remarks
    
    CMap is a dictionary collection class that maps unique keys to
    values. Once you have inserted a key-value pair (element) into
    the map, you can efficiently retrieve or delete the pair using the
    key to access it. You can also iterate over all the elements in the
    map.
    
    A variable of type POSITION is used for alternate access to
    entries. You can use a POSITION to “remember” an entry and to
    iterate through the map. You might think that this iteration is
    sequential by key value; it is not. The sequence of retrieved
    elements is indeterminate.
    
    Certain member functions of this class call global helper functions
    that must be customized for most uses of the CMap class. See
    Collection Class Helpers in the Macros and Globals section of the
    MFC Reference.
    
    CMap incorporates the IMPLEMENT_SERIAL macro to support
    serialization and dumping of its elements. Each element is
    serialized in turn if a map is stored to an archive, either with the
    overloaded insertion (<<) operator or with the Serialize member
    function. 
    
    If you need a diagnostic dump of the individual elements in the
    map (the keys and the values), you must set the depth of the
    dump context to 1 or greater.
    
    When a CMap object is deleted, or when its elements are
    removed, the keys and values both are removed.
    
    Map class derivation is similar to list derivation. See the
    articleCollections in Visual C++ Programmer’s Guide for an
    illustration of the derivation of a special-purpose list class.
    
    #include <afxtempl.h>
    
    Class Members |  Base Class |  Hierarchy Chart
    
    Sample   MFC Sample COLLECT
    compliments of MSDN online

    For more INFO visit MSDN online

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's a good generalized data structures book?
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 11-16-2006, 01:01 PM
  2. i need advice about data structures
    By sawer in forum C Programming
    Replies: 2
    Last Post: 04-22-2006, 04:40 AM
  3. Data Structures C++ Book
    By Cprogrammer in forum C++ Programming
    Replies: 1
    Last Post: 09-16-2005, 01:50 AM
  4. C Programming Question
    By TK in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 07-04-2002, 08:11 PM
  5. Array Data Structures
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 03-27-2002, 06:52 PM

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