Homework 2: Pointers, Pointers Everywhere, but will they all link?
Short Description:
Write a program that implements a simple order tracking system for a small company.
Goals
When you finish this homework, you should have:
- Refreshed your knowledge of pointers and linked lists.
- Refreshed your knowledge of programming.
Formal Description
Your task is to write a simple order tracking system for a small company. To simplify the implementation you need only track the following fields for each order
- The customer name, a string possibly containing spaces. We will assume that each customer has only one order and that no two customers have the same name.
- The order number, a unique positive integer.
- The customer number, a unique positive integer.
- The order status, one of:
Ordered, In Production
or Shipped
.
You should assume that there is a vary large set of associated data, such as items ordered, quantity, and special instructions. This data has been removed to simplify the program. You should only allocate memory for each order once and you should not copy the data from one location to another.. To accomplish this this, you will most likely need a node with three link fields.
Your system should begin by prompting the user for a file name. It should read and process the commands in this file.
Note, you may assume that the file name, along with all other commands are in the correct format. The user may attempt to perform an illegal operation, but the command to do that will be correctly formatted.
As your program processes each command, please print Processing command "command
". Follow this with a new line character. Please see the example below. This is strictly for debugging purposes and should be easy to turn off.
Commands:
The input file will contain zero or more of the following commands. All commands will be in correct format
- Insert customer_number, order_number, customer name
- Delete order_number
- Delete the order from the system if it is present.
-
Delete 4321
- Your program should not crash if the order is not present.
- Update order_number
- If the order is present in the system, it should change the status to the next status
Update 4321
- Ordered -> In Production -> Shipped
- The program should take no action if a shipped order is updated.
- Your program should not crash if the order does not exist.
- Print Order order_number
- Print the record corresponding to the order number. See below for output formatting instructions.
-
Print Order 4321
- Print Name customer name
- Print Customer customer_number
- Print the record corresponding to the customer number. See below for output formatting instructions.
-
Print Customer 12345
- Print All Order
- Print All Customer
- Print All Name
- Print the list ordered by the given field. See below for output formatting instructions.
- Comment comment string to end of line
Output Formatting Instructions
When printing a single record print as follows
- Print a tab.
- Print Customer Name: , left justified, 18 spaces wide filled with spaces.
- Print the name associated with the record.
- Print a newline.
- Print a tab.
- Print Customer Number: , left justified, 18 spaces wide filled with spaces.
- Print the customer number associated with the record.
- Print a newline.
- Print a tab.
- Print Order Number: left justified, 18 spaces wide filled
- Print the order number associated with the record.
- Print a newline.
- Print a tab.
- Print Order Status: left justified, 18 spaces wide filled
- Print the status (Ordered, In Production, Shipped).
- Print a newline.
with spaces.
The above record would appear as follows, the ↩ indicates a newline.
Customer Name: George Washington↩
Customer Number: 12345↩
Order Number: 4321↩
Order Status: Ordered↩
↩
When printing a list of orders
- Print Orders sorted by
- Print one of the following (Name, Customer Number, Order Number)
- Print a new line
- Print each record, as described above
- Print a blank line between each record.
Printing Several records by Customer Name would appear as follows:
Orders sorted by Customer Name
↩
Customer Name: George Bush↩
Customer Number: 12346↩
Order Number: 4322↩
Order Status: Ordered↩
↩
Customer Name: George H. W. Bush↩
Customer Number: 12344↩
Order Number: 4323↩
Order Status: Ordered↩
↩
Customer Name: George Washington↩
Customer Number: 12345↩
Order Number: 4321↩
Order Status: Ordered↩
↩
In any case where no customer is present, either the list is empty or the record is missing, simply print a blank line.
A sample data file is here.
My output for the sample data file is here
Programming Requirements
There is a concerned that they may be a very large number of records, so they ask that you store each record only once and do not sort the records. This means that the records need to be stored in linked lists, ordered by each of the fields.
To do this you must build a list structure which simultaneously supports three lists. For the above data the data structure may be visualized as follows:
Note, there is only one node allocated per data item. This is a requirement of the project.
You should implement a MultiList class built in an implementation and header file. Your class should implement all methods necessary for a class containing dynamic memory.
If you wish to disable any of the member functions required for a class with dynamic memory, you must do so properly. You must not have memory leaks however.
Your data structure should support
- $O(n)$ search.
- $O(1)$ insert after location.
- $O(1)$ delete after location.
- Once inserted, data may not be copied.
You may only use the following library containers:
- Strings
- Streams
- Array, either c style or
std::array
- Shared Pointers
- Unique Pointers
- Enumerations, but only scoped or strong enumerations.
- Variants
You may not use the list, vector
, or any other mass container class. The idea is for you to implement and master linked lists.
You should provide a UML document describing all classes implemented.
Your code MUST compile with the following compiler flags on cslab103
CXXFLAGS = -g -O3 -Wpedantic -Wall -Wextra -Wmisleading-indentation -Wunused -Wuninitialized -Wshadow -Wconversion -Wfloat-equal -Wparentheses -Wunreachable-code -std=c++17
Some Notes
I declared two enumerated types, one for the order status and one for the different fields I would build a list over.
- I built a
ToString
function for each for output.
- For the fields I build a
Next
function as well.
I employed multiple arrays of shared_ptr
to represent
- The multiple links in an individual node
- The multiple head pointers in the MultiList class
- A set of internal "pointers" for iteration across the individual lists.
I made use of templates for functions such as Find.
Required Files
A single tar or zip file containing the source code, documentation, and makefile for this program. This file should not contain object files or executables.
Submission
Upload your tar or zip file by the due date to the D2L folder Homework 2.