Recent Question/Assignment
(50 points)
Implement a singly linked list to store customers. You can use and adapt your class from the previous
assignment. To implement the list, you will need a class for the list and a class for the nodes. The
node class implements capabilities to store a single customer, as well as a pointer to the next node in
the list.
Once the program is started, it will print out the prompt -list - ( is followed by a whitespace):
./a.out
list
You will implement the commands -add-, -remove-, -search-, -print- and -quit-:
add
Add takes 3 arguments, representing the individual attributes of customers in the order listed below.
Append the customer to the end of the list. A list generally allows duplicates. So you do not need to
check if a customer already exists. Then repeat the prompt. You can assume that there are no spaces
within the attribute values specified by the user.
• Customer id number
• First name
• Last name
list dd 7 James Bond
list add 4345 Bugs Bunny
list add 5 Donald Duck
list
remove
Remove takes the customer id as an argument. Remove the customer with corresponding id and print
out true. If there is no customer with such an id print out false. If there are multiple customers with
the same id, remove the first occurrence of a customer with the corresponding id. Then repeat the
prompt.
list remove 123
false
list remove 7
true
list
search
Search takes the customer id as an argument. If there is a customer with such an id print out true.
Otherwise, print out false. Then repeat the prompt.
list search 123
false
list search 7
true
list
print
Print takes no arguments. Print the attributes of the customers from left to right. Separate the
individual attributes by commas and enclose each customer by parenthesis. Then repeat the prompt.
list print
(7,James,Bond)(4345,Bugs,Bunny)(5,Donald,Duck)
list
quit
Exit the program
list quit
Error Handling
• If a customer id already exists when attempting to add a customer, print out an error message
starting with -Error!-. (Do not capitalize the entire word -Error-)
• If a customer id contains other characters than digits, print out an error message starting with
-Error!-. (Do not capitalize the entire word -Error-)
• If the user types a command that is not supported, print out an error message starting with
-Error!-. (Do not capitalize the entire word -Error-)
Submit AT LEAST the following files:
• Your main file controling the flow of the program
• The prototype file for your customer class.
• The implementation file for your customer class.
• The prototype file for your node class.
• The implementation file for your node class.
• The prototype file for your list class.
• The implementation file for your list class.
Example of program execution:
g++ *.cpp
./a.out
list add 7 James Bond
list print
(7,James,Bond)
list add 3229 Bugs Bunny
list add 230 Donald Duck
list print
(7,James,Bond)(3229,Bugs,Bunny)(230,Donald,Duck)
list search 123
false
list search 7
true
list remove 7
true
list print
(3229,Bugs,Bunny)(230,Donald,Duck)
list remove 123
false
list hi
Error! Enter add, remove, print or quit.
list add 11a Papa Smurf
Error! Invalid id. Ids may only contain digits.
list add 111 Papa Smurf
list print
(3229,Bugs,Bunny)(230,Donald,Duck)(111,Papa,Smurf)
Your program will be judged on the following:
• 21 points - Passes I/O requirements
• 20 points - Code satisfies requirements of assignment
• 9 points - Professional coding style
- 3 points Adequate comments
- 3 points Modularity (small main function, separate functions, etc)
- 3 points Readability (line length, indentation, variable names)