Thread: Can someone paraphrase to explain this textbook quesion to me, please?

  1. #1
    Registered User
    Join Date
    Apr 2006
    Location
    Taxachusetts
    Posts
    10

    Can someone paraphrase to explain this textbook quesion to me, please?

    OK, maybe I'm just dense, or slow, or overtired. However, I do
    not seem to be able to get my head around this textbook question that is assigned as homework. On a weekend, getting an answer from my professor or classmates is obviously not going to happen, so I am hoping that y'all can give me a kickstart in explaining what I need to do here..This is the question literally transposed from the book (I added italic emphasis where I am confused):



    You're working for a company that wants to take client contact information as it is entered by a salesperson from a stack of business cards that he or she has collected, and output the information to a file (contacts.dat) in alphabetical order. Assume that there are nver more than 100 cards to enter. The program should prompt the salesperson for each of the following values for each card:

    Last name
    First name
    Middle name or initial
    Title
    Company name
    Street address
    City State
    Zip code
    Phone number
    Fax number
    Email address

    After the data are entered for each card, the user should be asked if there is another cad to enter. This data should be sorted by last name, using a version of the SortedList class from Chapter 13 that will hold up to 100 struct values, each with a number corresponding to an iterm in the list above. Because the struct is so large, however, it will be more efficient if each element of the list array is a pointer to one of the struct values, and the class merely rearranges the pointers within the array in order to do the sorting. You should dynamicaly create a new
    struct for each component of the list array to point to as the cards are input.
    Thus, the program won't allocate struct memory for any more cards than ar entered. The print function of the class will need to be modified to output the list to the contacts.dat file instead of cout. Each member of the struct should be written on a separate line. The function should also write the number of cards that are in the list as the first line of the file.




    OK, so...I'm not really overwhelmned here with what I'll need to do so much as just missing the point of clarity on what is wanted. Is this question essentially saying "rewrite what already exists to be an array of structures", or? I've attached the header file of the class that's referenced in the question, just for clarity. I am inclined to edit the SortedList class to typecast a struct type, and change the private data array to handle it, but then this is where I start getting confused about the pointers excercise (which in this case, really should be a pointers excercise since the chapter primarily covered pointers)..

    PLEASE, I'm not asking how to code anything here, not even asking for pseudo-code, but rather what is the reasonable paraphrase of what this question is asking?

    Thanks!!!
    Last edited by imCrushedByCode; 04-22-2006 at 05:14 PM. Reason: horrid line breaks

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    first define a class or structure that contains the data you have to collect about each card. Then in SortedList.h redeclar the typedef ItemType to be your class.
    Code:
    class MyClass
    {
      /// blabla
    };
    
    typedef MyClass ItemType;

    Now, one instance of class SortedList will contain an array of 100 MyClass objects. It is that array you should use for data entry.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > ItemType data[MAX_LENGTH];
    It's basically telling you to write this
    ItemType *data[MAX_LENGTH];

    And when you call insert(), you need to do
    data[i] = new ItemType;

    > typedef int ItemType;
    And you replace this with a struct/class of last name, first name etc.
    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.

  4. #4
    Registered User
    Join Date
    Apr 2006
    Location
    Taxachusetts
    Posts
    10
    Quote Originally Posted by Salem
    > ItemType data[MAX_LENGTH];
    It's basically telling you to write this
    ItemType *data[MAX_LENGTH];

    And when you call insert(), you need to do
    data[i] = new ItemType;

    > typedef int ItemType;
    And you replace this with a struct/class of last name, first name etc.
    Aahh..I see said the blind man! Thank you! I attempted to replace 'int' with struct, ran into issues, attempted to try some other things, but at any rate, let me ask you this: when you say replace the typedef with struct/class of last name, you mean just drop the typedef and explicitly decalare the incoming parameters to be of type struct, or is another class that handles the struct being implied here?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    As in
    Code:
    typedef struct {
      string aName;
      // blah
    } ItemType;
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you explain these bitwise operations?
    By 6tr6tr in forum C++ Programming
    Replies: 6
    Last Post: 10-29-2008, 01:19 PM
  2. Please Explain me few terms that i have listed in here.
    By chottachatri in forum C++ Programming
    Replies: 3
    Last Post: 02-26-2008, 08:20 AM
  3. Please explain?
    By neo_phyte in forum C Programming
    Replies: 3
    Last Post: 08-25-2006, 05:23 AM
  4. Can someone explain to me what this code means
    By Shadow12345 in forum C++ Programming
    Replies: 3
    Last Post: 12-22-2002, 12:36 PM
  5. Can someone explain "extern" to me?
    By valar_king in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2001, 12:22 AM