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

• 04-22-2006
imCrushedByCode
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
City State
Zip code
Phone number
Fax number

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!!!
• 04-22-2006
Ancient Dragon
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.
• 04-23-2006
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.
• 04-23-2006
imCrushedByCode
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?
• 04-23-2006
Salem
As in
Code:

typedef struct {
string aName;
// blah
} ItemType;