Homework 3, An Array of Classes.
Short Description:
Write a program that will allow a teacher to manage their class lists.
This assignment is worth 100 points total.
Goals
When you finish this homework, you should have:
- Strengthened your ability to design programs.
- Worked with multiple source code files to build an executable.
- Solved problems involving arrays.
- Implemented a sort function.
- Implemented a find function.
Note
Please see the individual components of this assignment before implementing anything.
Formal Description
Your friend Tom the Teacher is having trouble managing his class lists. Tom teaches up to four classes a term and manages everything through the lists of names of students in his classes, or his class lists. He has asked you to assist him by writing a program to help manage these class lists.
For this program a name is a string, which could include spaces. Natalie Portman, James T. Kirk, Her Majesty The Queen and Drake are all examples of names of students in Tom's class. (Tom has some impressive students). There are no blank or empty names, all names contain at least one character.
Tom's classes are all limited to 40 students.
Tom refers to his classes and his class lists as A,B,C, and D. Sometimes he uses an extra class list E to temporarily hold a class list while he is manipulating his lists.
Over the years Tom has developed a large number of operations that he performs on class lists. Your assignment is to create a system that allows Tom to manage his class lists. You should write a command driven software system that supports the following actions.
- Load classname filename
- Read the names, one per line from the given file and store then into the given given class. If the class contains any data before this command is executed it should be erased.
- There will be one line per file and there will be no blank lines.
- If the file does not exist, your program should report filename does not exist.
- If no file name is given, your program should report No file name given to Load."
- Store classname filename
- Save the names in the list classname to the named file. Names should be written one per line. The last line should end with a new line, but there should be no extra new lines.
- If no file name is given, your program should report No file name given to Store."
- Print classname
- Print the names of the students in the class to the screen, one line per name.
- Do not print any other information.
- Common srcename1 srcname2 destname
- After this command is finished the list destname will contain names that are in both srcname1 and srcname2.
- Any data in destname will be removed before the operation begins.
- Merge srcename1 srcname2 destname
- After this command is finished the list destname will contain all of the names in srcname1 or in srcname2 (or both).
- No names will be duplicated.
- Any data in destname will be removed before the operation begins.
- Diff srcename1 srcname2 destname
- Any data in destname will be removed before the operation begins.
- After this command is finished the list destname will contain the names that are in srcname1 but not in srcname2.
- Copy srcename destname
- After this command is finished, the list dstname will be an exact copy of the list srcname.
- Erase listname
- This command will remove all names from the given class list.
- Sort listname
- This command will sort the names in the given list.
- The sort is done based on the entire string
- It should be from in ASCII collation order.
- You must implement the selection sort.
- Length istname
- Print the length of the named class.
- Print a single integer on a line.
- IsIn listname name
- Search the given list for the name.
- If the name is in the list print name is in listname.
- If the name is not in the list, print name is not in listname.
- Add listname name
- Append the name to the named list.
- Delete listname name
- Delete the name from the given list.
- Move all names beyond the given name forward to fill the new empty spot.
- If the name is not in the list print name is not in listname.
- Quit
The program you design should read commands from the command line and perform the requested activity.
Your prompt should be "> ". After the command has finished, a new line should be printed.
[bennett@mirkwood closed]$ main
> Load A file1
> Length A
4
> Print A
Natalie Portman
James T. Kirk
Her Majesty The Queen
Drake
> Quit
[bennett@mirkwood closed]$
Further Comments
- When your program starts, all class lists should be empty.
- If an invalid command is issued, your program should report command is invalid., where command is the invalid command name, and abort that command.
- If an invalid class list is given, your program should report X is not a valid class list name., where X is the invalid class list name.
- If a command results in class list that is too long, you should store first 40 names then report the error command resulted in overflow, X truncated., where command is the command name and X is the class list where the error occurred.
- For any command that takes a single class list name, if the class list name is missing print Missing class name."
- For any command that takes a source and destination class list name.
- If the first name is missing print Source class name missing.
- If the second name is missing print Destination class name missing.
- For any command that takes three class list names
- If no names are supplied print First source class name missing.
- If only one name is supplied print Second source class name missing.
- If only two names are supplied print Destination class name missing.
- You must implement selection sort and linear search functions.
- You may not use any item from the SCL, or any algorithms from the STL.
- You may not use stringstreams.
- You should read commands from standard input, one line at a time.
- Commands will be complete and free from errors not covered.
- If an error is encountered
- Print the appropriate error message
- Abort the command
- Continue processing input.