Programming Systems Design

 

CSCI 455

FALL 2005

 

Dr. K. Narayanaswamy

Programming Assignment # 6

Due Date: 10/16/2005 (11:59:59 p.m.)

 

Goal

This assignment requires you to understand how to manage a collection of structure objects in a way that resembles a real-world database.  It significantly extends the functionality of Assignment 5 by allowing for you to add students and delete students from the collection.  You will learn to use algorithms such as insertion sort and sequential or binary search.  We will improve the efficiency of these algorithms as we make further progress in the days to come.  You are expected to learn and to design and use functions in C++ using the general style of the examples done in class, including declaration of parameters.

 

Task

The program will manage a database of Student objects.  As in Assignment 5, the following are the attributes of a student:

·         Last name: a string with only alphabetic characters.  For formatting purposes, you may assume the names would be no longer than 15 characters;

·         First name: a string with only alphabetic characters.  For formatting purposes, you may assume the first name would be no longer than 15 characters;

·         Social Security Number: a string.  The social security numbers you accept must be 11 characters, with digits in positions 1, 2, 3, 5, 6, 8, 9, 10 and 11; and the “-“ in positions 4 and 7.

·         Phone Number: a string.  A valid phone number will be of length 13, and will  contain characters “(“ in position 1, “)” in position 5, and “-“ in position 9.  All other characters must be digits.

·         Age: an integer.  You may assume this field will always be an integer, but the age must be a positive integer.

Your program will support the following single character commands in a main command loop:

 

§         “I” or “i” è (Import Command) Prompts the user for a file name, and will initialize the database from the student data in that file.  That means that existing database contents will be wiped out completely and re-initialized when this command is executed.  The data in the array must be maintained in sorted order – sorted by social security number.  The command should check for and report errors as the input file is processed.  The format of the data and error checking requirements are identical to that in Assignment 5.  In all cases, IF there are any problems with the input, you should report the problem to the terminal to make the user aware with a line number on which the problem arises.  You should also specify what action was taken with the input.  You may assume the input will have the above items in the order stated in the input file.  You do not have to do error checking beyond what is indicated explicitly in the assignment requirements. 

 

§         “A” or “a” è (Add Command) Add a Student to the database you are maintaining – your program should prompt for each of the student attributes (such as social security number, last name, first name, phone, and age).   Make sure that the attributes provided as values satisfy the requirements – e.g., social security number must be valid, age must be positive, and so on.  Once all the data is validated, your program should add the new student to the existing database if there is no duplicate in the social security number.  It is critical that the addition preserve the sorted order.  You should detect if a student with the same social security number exists in the database and provide an error message about this situation. The program should validate the data for a part prior to adding it to the database.

 

§         “D” or “d” è (Display Command) This command should ask the user for a social security number of a student to display.  The command should find the student in the database and display the student’s data TO THE TERMINAL.  If a student with that social security number does not exist, print a message to the effect.    You should display the student data in any format that is readable.

 

§         “R” or “r” è (Remove Command) This commands should ask the user for a student’s social security number.  The command should then delete that student from the database.  If a student with that social security number does not exist, print a message to that effect. 

 

§         “E” or “e” è (Export Command) Prompts the user for a file name, and will export or save the entire database of students from the array into the named file.  If the output file name is the same as the input file, you should confirm that the user wants to overwrite the input data.    Note that the output file  should be saved in an identical format to the input file, so that the output file can itself be used to import new data in a subsequent run of the database program.

 

§         “S” or “s” è (Show All Command) Shows ALL the students in the current database to the terminal in a readable format.  You can use any format that is readable.

 

§         “Q” or “q” è (Quit Command) should quit the main command loop and exit the program.

 

If the command is not one of the above legal commands, your program must print an error message and prompt for a new command.

The input file contains essentially a table of students with the columns as shown in the following order: last name, first name, social security number, phone number, and age.  Each student is guaranteed to be on a different line.  In this assignment you may assume that the data will have the right format in the file.      You do not have to do error checking beyond what is indicated explicitly in the requirements.  A sample of the input file is shown below:

 

Rigney                          Bill                   000-90-2000               (310)555-1210                        23

Swartough                    John                 111-23-2000               (323)555-1210                        29

Sweeney                      Joe                   323-23-2111               (393)555-1111                        -2

Anderson                     Jim                   235-90-2000               (626)555-1210                        24

Vanguard                     Cory                3789-9-2005               (909)555-1210                        32

Biggins                         Bill                   000-89-2000               (619)555-1210                        29

Tyler                            Hayden            333-90-2000               (818)555-1210                        30

Terrence                      Cody                010-89-2000               619)555-1210                         29

Blanco                         Bill                   000-89-2000               (699)555-1210                         29

Vilnius                         Kostas              128-85-2005               (909)555-1210                        32

 

There may be a maximum of 50 students represented in the table.

Your program should read the input above, check each of the fields for validity.  If the data on a line is valid, you should add the student to the array.  Make sure that you report any errors of formatting, and ignore the student record in question.  Also, no two students can have the same social security number.  So, before a student is added, make sure that there is no student with the same social security number in the collection already.  Such an error should also be reported.  Your program should report the total number of records read and the total number of errors found (see the sample transcript).

A sample of the transcript of interaction is as follows:

 

STUDENT DATABASE PROGRAM

 

Enter command (A, D, E, I, R, S – or Q to quit) : I

Enter input file name: student.input

Ignoring Record Number 3 – bad age

Ignoring Record Number 6 – bad social security number

Ignoring Record Number 9 – bad phone number

Ignoring Record Number 10 – duplicate ssn

Processed 10 student records

4 errors were founds

 

      Enter command (A, D, E, I, R, S – or Q to quit) : s

 

Last Name           First Name           Social Security #                Phone #                  Age

Biggins                         Bill                   000-89-2000               (619)555-1210                        29

Rigney              Bill                   000-90-2000               (310)555-1210                        23

Swartough                    John                 111-23-2000               (323)555-1210                        29

Vilnius              Kostas                         128-85-2005               (909)555-1210                        32

Anderson                     Jim                   235-90-2000               (626)555-1210                        24

Tyler                            Hayden            333-90-2000               (818)555-1210                        30

 

Enter command (A, D, E, I, R, S – or Q to quit) : A

      Enter ssn: 345-67-8890

      Enter last name: Jones

      Enter first name: Edith

      Enter phone number: (310) 555-5656

      Enter age: 35

      Student added…

 

Enter command (A, D, E, I, R, S – or Q to quit) : s

Last Name           First Name           Social Security #                Phone #                  Age

Biggins                         Bill                   000-89-2000               (619)555-1210                        29

Rigney              Bill                   000-90-2000               (310)555-1210                        23

Swartough                    John                 111-23-2000               (323)555-1210                        29

Vilnius              Kostas                         128-85-2005               (909)555-1210                        32

Anderson                     Jim                   235-90-2000               (626)555-1210                        24

Tyler                            Hayden            333-90-2000               (818)555-1210                        30

Jones                            Edith                345-67-8890              (310) 555-5656            35

 

Enter command (A, D, E, I, R, S – or Q to quit) : r

      Enter ssn to remove:  235-90-2000

      Student removed

 

Enter command (A, D, E, I, R, S – or Q to quit) : s

Last Name           First Name           Social Security #                Phone #                  Age

Biggins                         Bill                   000-89-2000               (619)555-1210                        29

Rigney              Bill                   000-90-2000               (310)555-1210                        23

Swartough                    John                 111-23-2000               (323)555-1210                        29

Vilnius              Kostas                         128-85-2005               (909)555-1210                        32

Tyler                            Hayden            333-90-2000               (818)555-1210                        30

Jones                            Edith                345-67-8890              (310) 555-5656            35

 

Enter command (A, D, I, R, S – or Q to quit) : D

      Enter ssn to display: 000-90-2000

Last Name           First Name           Social Security #                Phone #                  Age

Rigney              Bill                   000-90-2000               (310)555-1210                        23

 

            Enter command (A, D, E, I, R, S – or Q to quit) : E

            Enter output file name: foobar.txt

            Database saved to foobar.txt

 

      Enter command (A, D, E, I, R, S – or Q to quit) : Q

            Exiting the database program…

 

 


 

A sample of the output file foobar.txt in the above example is:

 

Biggins                         Bill                   000-89-2000               (619)555-1210                        29

Rigney              Bill                   000-90-2000               (310)555-1210                        23

Swartough                    John                 111-23-2000               (323)555-1210                        29

Vilnius              Kostas                         128-85-2005               (909)555-1210                        32

Tyler                            Hayden            333-90-2000               (818)555-1210                        30

Jones                            Edith                345-67-8890              (310)555-5656            35

 

Note that the output file format HAS TO BE COMPATIBLE WITH THE INPUT FORMAT in this Assignment.  In short, one should be able to import a file saved by your program.

Hint:  This assignment is an extension of the kind of program you can see on the course website.   There are aspects of the current assignment that are different – e.g., validation of input, exclusion of duplicates, a few details of the Import command or Export command.  But, the basic concept and building blocks are similar.  See the link under Course Materials.  Item # 13, Car Database Program is very similar.

You may use sequential or binary search as you feel comfortable.

Submit instructions

1.      Save each assignment in a separate file (e.g., assign6.cpp). Do not delete or change the assignment after submission. This will help in case there are problems in submitting your assignment.

2.      If relevant, submit your program and any header files required to run it.

3.      The grader will test your program by compiling and executing your program. You are completely responsible for making sure that you submit the program correctly.

4.      For example, to submit the first assignment, use the following “submit” command with tag p6 (from the directory where you have the program file):

submit -user csci455 -tag ass6 assign6.cpp
Grading Criteria:

The following are the grading criteria for this assignment.  You should use this as a checklist prior to submission if you want to get full credit for it.

 

PROGRAM CORRECTNESS:

80 points

I command works correctly if fields are right

8

E command exports file in the same format as input file

8

A command works correctly if inputs are right

6

A and I command exclude bad ssn, bad telephone, bad age

4

A and I command ensure no duplicate ssn’s in the database

4

R command removes a student with a particular ssn if found

8

R command provides an error message if not found

2

D command displays a student with a particular ssn if found

6

D command provides an error message if not found

2

S command shows ALL the student data correctly

8

Q command quits the program correctly

2

Illegal commands are properly detected and handled

2

Requirements Carried Forward from the Prior Assignment (no positive points – but –5 per requirement that you do not satisfy):

Ø      Detects and excludes bad SSN

Ø      Detects and excludes bad phone number

Ø      Detects and excludes bad age

Ø      Use a Function to check validity of social security number

Ø      Use a Function to check validity of phone number

Ø      Use a Function to read the input file (will be called by the Import command)

Ø      Use a Function to write the output file (will be called by the Export command)

Ø      Problems with input file or output file opens detected and handled properly

0

Program uses a function to delete a student with a particular ssn

5

Program uses a common function to display a single student to the terminal (to be called from D and S commands)

5

Program uses a common function to add a single Student to the database  (to be called from I and A commands)

5

PROGRAM DESIGN & STYLE:

20 points

Program uses an array of struct to represent Student data

5

Program is easy to change to different numbers of students

5

Program is readable (indentation and mnemonic variables)

5

Program is documented (header, functions and the major steps/loops of program)

5

 

The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees