Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 379
  • Last Modified:

Container Classes and Linked Lists - More

Hello good people and thanks for all your patience and help.

I'm working on yet another C++ project which involves a class to 'contain' and a linked
list. I need some more help breaking down the program into its component pieces.

This program is to produce an information manager similar to a rolodex, which is made
up of cards arranged in alphabetical order. Each card contains information, usually
names, addresses, phone numbers and type of the person's business(the reason
why the person is in the rolodex to begin with). i.e. :

First:     Last:       Occupation:                 Address:                                  Phone:

Tony     Hansen    Writer                         12 E. St. NY, NY   33333       555-9999

When the last card is read, the "rolodex" is at the start of the list since a rolodex
is built on a circular track.

The rolodex should be stored in alphabetic sorted order by last name.
The program needs to demonstrate that entries can be added, deleted, and
changed. Also, show that you can search the rolodex for specific information.
The list should also be able to be printed/displayed.

A string class should be used for the individual pieces of information. The cards
should also be represented by a user-defined class. This means you should use the
idea of a container class.

One class should represent a Card entry, anf the Rolodex class is the "container"
which 'contains' a linked list of card entries, and manages them as they are added/removed.
Thus, Rolodex has pointers to a linked list of Card objects. Each Card object
represents one item in the rolodex.
To add a new item to the rolodex, first create and populate the new Card entry,
then pass it to the rolodex addItem() member(which maintains the list in sorted
order). When finding an entry, the rolodex returns a Card* to one of its entries.

Here's what I have thus far........................................................................

HEADER FILE
class rolodex {

      public:

            void initialize_rolodex();
            void addEntry();
            void deleteEntry();
            void displayRolodex();xz
            rolodex changeEntry(rolodex person);
            rolodex(); // default CTOR
            ~rolodex();  // default DTOR

      private:

            char firstName;
            char LastName;
            char occupation;
            char address;
            char phone_number;
            int rolodex_record_number;
};


IMPLEMENTATION FILE
#include <iostream.h>
#include "project2.hpp"

int main()

{
      rolodex R1;
      R1.addEntry();
  return(0);
}

// Initilaize the rolodex
void rolodex::initialize_rolodex()
{
   rolodex Rdx; // initial rolodex object, Rdx
}

// Add an entry to the rolodex
void rolodex::addEntry()
{
  cout << "Enter first name:  ";
  cin >> firstName;
  cout << endl;
  cout << "Enter last name:  ";
  cin >> LastName;
  cout << endl;
  cout << "Enter person's occupation:  ";
  cin >> occupation;
  cout << endl;
  cout << "Enter person's telephone number:  ";
  cin >> phone_number;
  cout << endl;
}

// Delete an entry from the rolodex
void rolodex::deleteEntry()
{
  cout << "Enter the record number of the rolodex entry you wish to delete  ";
  cin >> rolodex_record_number;
  cout << "The record number you entered was " << rolodex_record_number << endl;

}

// Change an entry held in the rolodex

rolodex rolodex::changeEntry(rolodex person)
{
  int choice = 0;  // used for selection of rolodex entry to be updated.
  char yes_no;
  cout << "Please enter the desired field to be changed for " << person.LastName << endl;
  cout << "1: First name, 2: last name, 3: occupation, 4: address, 5: phone number  ";
  cin >> choice;
  switch (choice) {
     case 1: cout << "Change " << person.firstName << "? y/n";
           cin >> yes_no;
           if ( yes_no == 'y' )  {
            cout << "Enter new first name ";
            cin >> person.firstName; }
            else break;
            break;

      case 2: cout << "Change " << person.LastName << "? y/n";
           cin >> yes_no;
           if ( yes_no == 'y' )  {
            cout << "Enter new last name ";
            cin >> person.LastName;  }
            else break;
            break;

      case 3: cout << "Change " << person.occupation << "? y/n";
           cin >> yes_no;
           if ( yes_no == 'y' )  {
            cout << "Enter new occupation ";
            cin >> person.occupation;  }
            else break;
            break;

      case 4: cout << "Change " << person.address << "? y/n";
           cin >> yes_no;
           if ( yes_no == 'y' )  {
            cout << "Enter new address ";
            cin >> person.address;  }
            else break;
            break;

      case 5: cout << "Change " << person.phone_number << "? y/n";
           cin >> yes_no;
           if ( yes_no == 'y' )  {
            cout << "Enter new telephone number ";
            cin >> person.phone_number; }
            else break;
            break;


      default: break;
      }  // end switch block
  return(person);
} // end changeEntry()

void rolodex::displayRolodex()
{
// display the contents of the rolodex
cout << "First,    Last,    Occupation,    Address,   Telephone Number" << endl;

}
// Default constructor for the class rolodex
rolodex::rolodex()
{
}

rolodex::~rolodex()
{

// Default destructor; takes no action

}


Could someone please help me with some direction again? As with my other
question regarding containers and linked lists I am equally confused. If I could
just get setup and explanation, I'm sure I could do it.

S.
0
swright243
Asked:
swright243
  • 5
  • 4
1 Solution
 
nietodCommented:
first of all you need a string class for storing the string information.

thus the rolodex class should look like,

class rolodex {

   public:
//  removed for space
   private:

   String  firstName;
   String LastName;
   String occupation;
   String  address;
   String  phone_number;
   int rolodex_record_number;
   };
0
 
nietodCommented:
Actually you have the same problem here as you did in the zoo.  You need more than one class.  One class represents the Rolodex file and the other represents the cards in it, like

class RolodexFile
{
   public:

   void initialize_rolodex();  // Do you really need this?  Or is this what the CTOR doesj?
   void addEntry();
   void deleteEntry();
   void displayRolodex();xz
   rolodex changeEntry(rolodex person);
  RolodexFile(); // default CTOR
   ~RolodexFile();  // default DTOR

   private:
// here you need linked list type data.
   RolodexCard *First;
   RolodexCard *Last;
};

class RolodexCard {

   public:

   void displayRolodexCard();
  RolodexCard(); // default CTOR
   ~RolodexCard();  // default DTOR

   private:

   String firstName;
   String LastName;
   String occupation;
   String address;
   String phone_number;
   int rolodex_record_number;
   friend RoladexFile;
};
0
 
nietodCommented:
Now that should give you some idea where you are going.  But don't try to get there all at once.

When you get a big problem like this try to outline the general approach you are going to take, think about all the classes you will need and what their resposibilities will be.  Then try to wrote the classes a little bit at a time.  Don't try to tackle the whole problem at once.  Here is what I see when I think about the problem.

Three classes are needed:
A string class (called String?) for storing names, addresses, phone numbers and other information.
A Rolodex card information class for storing the information that goes on a single card.
A Roladex file information for storing all the rolodex cards objects.

The reposibilities:

String class:
Can store string of any desired length.  
Can be used to compare two strings.  (needed when searching the rolodex)
Can be use to read and write strings from a stream.

Rolodex card:
Stores information for a single contact.
Can be used to read and write contact information from a stream
Contact information can be obtained or set using functions, like GetName() or SetName().

Rolodex File:
Stores a list of Rolodex cards in alphabetical order.
Rolodex card objects can be added or deleted.
Rolodex cards can be access in sequential order.

Now you have an idea of the different classes and responsibilities.  Looking at this it should be obvious that the first thing you need is a working string class?  do you have one?  If so, let me see it, if not lets start on that.

When does all this have to be done?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
nietodCommented:
One more thing.  Once you have come up with your list of classes and their responsibilities.  The next things you ned to think about, and these are all interelated are:
1.  What data is stored in the class.
2.  How is it obtained from the class.(if allowed)
3.  How is it set by users fo the class (if allowed)
4.  How does the constructor initalize the data.
5.  How does the destructor clean-up the data.

For a class like the RolodexCard, you might have a Name member that is a string.
You would need to provide a function to set the name to a new value, like SetName(), one to get the current value of the name, like GetName().  The constructor(s) needs to initialize this.  Soem constructors may initialize it to an empty string, others might take a parameter that is a name string and set the stored name string to this string.  The destrucor must destroy the name.  If the name is stored in a string class, the string class should take care of that automatically, so actually the destructor doesn't need to do anything.

This sort of thinking should be applied to all the classes and all the data they store.  Can you handle that?  (Bear in mind that you won't get it perfect at the start, you will add new data members and change others etc as time goes on, but this is a good way to start.)
0
 
swright243Author Commented:
Hello again nietod and thank you again for responding. I'll get you some of the answers you asked for in the next comment, probably tonight, Monday.
S.
0
 
swright243Author Commented:
08/23/98
0
 
swright243Author Commented:
09/05/98
0
 
nietodCommented:
9/25/98
0
 
swright243Author Commented:
Adjusted points to 400
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now