CS 12 - Lab 6

In this lab you are going to get more practice writing a class.

This lab depends on lab5 being completed. Because many students did not finish last week, you may complete lab5 and have it graded by the TA in this week's lab, during the first hour only.

Note that the program must be written, compiled, and executed under Linux.

Create a directory called lab6 using the mkdir command and copy your files from lab5 into this directory using the cp command.

Adding to the SSN Class

The SSN class from last week is pretty basic. It stores a social security number for a person, but not the person's name. Therefore, modify the class definition to add a private variable char *name.

Once you have done this, add a public method called setName that can be called to set a person's name. The method should take an array of characters as a parameter and use the strdup function to store a copy of the array to the name variable. The function does not need to return a value.

Finally, modify the print method to print the social security number and the name.

Modifying the Main Program

Your main program currently asks the user to enter in 10 social security numbers. Modify it so that the user is asked for names also. Use the new setName method to add the names to the SSN variables. The rest of the program should behave the same as in last week's lab.

Following is a partial sample run.

This program will allow you to enter in social security numbers and names,
then allow you to search for a social security number given the last 4 digits.

Please enter a SSN  for person 1: 555-55-5555
Please enter a name for person 1: John Doe

   .
   .
   .

Please enter a SSN  for person 10: 555-555-5555

That SSN is not valid.  Please try again.

Please enter a SSN  for person 10: 444-44-5555
Please enter a name for person 10: Jane Doe

Here is a list of all of the SSNs and names entered:

555-55-5555  John Doe
   .
   .
   .
444-44-5555  Jane Doe

Please enter the last 4 digits of an SSN to search for: 5555

The following person(s) match:

555-55-5555  John Doe
444-44-5555  Jane Doe

Grading

When you have finished the program, your TA will grade it. To receive full credit, your TA will check all of the following: