CS 120 Final Project | Pizza Tracking System Program
CSCI 120, Dr. BYRNES
Henry ZHONG, ███ omitted due to privacy concerns ███.
Due and Submitted by 2018.12.07, 9:00.
Edited for personal GitHub exhibition on 2019.07.29.
This document was edited based on the original lab report of CS 120's final project; as it was not written to be an introduction of the project itself, many knowledge of the project is presumed. Please checkout project_instruction to get an insight of the project requirement, and refer to Section 2. Sample Input/Output for execution samples.
In short, it is a command line program which manages the workflow of a pizza deliver system. Supported features: order registering, pizza making, driver assigning, driver delivering, and drivers' performance review.
Note that although the professor has given a skeleton framework in project_instruction, I designed and implemented my own data structure as I believe my approach is neater in terms of lines of code, and uses more advance C++ features (we only exposed to such features for the last two projects). In reflection, I have to admit that although my design is shorter, it sacrifices the "loosely coupled" principle of software engineering. In the later year of study, I realized that I have somehow built a lightweight relational database (utilizing the idea of id-collision) with many design flaws from a database perspective.
1. Program Design
1.1. Core Data Structure
Our core data structure are:
vector<map<string, string>> order_rec
vector<map<string, float>> driver_rec
Whereas every order shall be store as a vector
node within order_rec
(in a chronological order) and every logged-in driver shall be store as a vector
node within driver_rec
.
I choose to use vector<map<string, string>>
as the data structure for order_rec
mainly due to three reasons: 1) the built-in feature of dynamic allocation fits the purpose of adding orders. 2) the versatile support of data retrieving methods provided by STL <vector>
gives my high flexibility. 3) My familiarity with vector
from the pervious Hash Table lab.
I decided to use map<string, string>
as the inner data structure of order_rec
because I want to set the key
to be a descriptive word that describing the value
it hold; thus, the key
must be string
type. Also, consider the value
should be able to hold a variety set of information (time
, name
, YES/NO
, and etc.), it is also reasonable to be string
. Similarly, since most of the information regarding driver
is number, so the key
for driver_rec
is set to be float
.
Regarding some minor data structure design:
- Some
queue
andmap
liketo_serve_queue
,to_dept_queue
,to_delv_map
, andto_arrive_map
are created to simulate the matching of orders with implicit commands. map<string, int> order_sys
andmap<string, float> driver_sys
are built to assign numerical ID toorder
s anddriver
s.stack<string> time_stack
andqueue<string> str_queue
are used inmain.cpp
to keep track of the latest time-related input, and to store tokenized inputs.
1.2. Workflow
The workflow logic is simple. main.cpp
reads the input commands from the input.txt
in a line by line manner and calling their input functions in Base.h #1 (input functions)
accordingly. Thus Base.h #1 (input functions)
shall therefore store data into Base.h #3 (private data members)
in a organized form.
Once the output functions are called in main.cpp
, Base.h #2 (output function)
will be triggered, it shall retrieve data from Base.h #3 (private data members)
, process these data with functions from Time.h
, and therefore produce the output.
2. Sample Input/Output
Given Sample Input
2.1.>> Program Input
login Bev
order 18:00 1 mushroom to 123 Holden Hall
order 18:02 4 spinach to 100 Liberty St
login Abe
serve 18:20
depart 18:20 Abe
serve 18:28
deliver 18:30 Abe 2.00
order 18:30 1 cheese 1 sausage to 1000 Beall Ave
depart 18:31 Bev
arrive 18:40 Abe
logout Abe
status
summary
quit
>> Program Output
Orders waiting to cook:
18:30 1 cheese 1 sausage to 1000 Beall Ave
Orders waiting to depart:
Drivers:
Bev 18:02 4 spinach to 100 Liberty St
Number of orders completed: 1
Average time per delivery: 30.0
Driver Bev:
Number of deliveries completed: 0
Average time per delivery: N/A
Total driving time: 0
Total tips: 0.00
Driver Abe:
Number of deliveries completed: 1
Average time per delivery: 10.0
Total driving time: 20
Total tips: 2.00
Program ended with exit code: 0
Self-designed Input
2.2.>> Program Input
login Mike
order 18:15 10 Pepperoni pizzas, 10 hotdogs, 10 Fanta orange drinks, 10 mozzarella cheese sticks to 11 Babcock Hall
login Alex
order 18:30 15 cheese sticks to Taylor 200
serve 19:00
depart 19:00 Mike
serve 19:10
deliver 19:30 Mike 10.00
depart 19:50 Alex
deliver 20:00 Alex 0.50
arrive 20:10 Mike
login Jen
order 20:35 1 milkshake, 1 small cheesecake, 1 strawberry parfait to Taylor 200
logout Mike
serve 20:45
arrive 20:55 Alex
logout Alex
status
summary
quit
>> Program Output
Orders waiting to cook:
Orders waiting to depart:
20:35 1 milkshake, 1 small cheesecake, 1 strawberry parfait to Taylor 200
Drivers:
Number of orders completed: 2
Average time per delivery: 82.5
Driver Mike:
Number of deliveries completed: 1
Average time per delivery: 30.0
Total driving time: 70
Total tips: 10.00
Driver Alex:
Number of deliveries completed: 1
Average time per delivery: 10.0
Total driving time: 65
Total tips: 0.50
Driver Jen:
Number of deliveries completed: 0
Average time per delivery: N/A
Total driving time: 0 Total tips: 0.00
Program ended with exit code: 0
3. Work Distribution & Reflection
███ Edited & omitted due to privacy concerns ███
I've written Base.h
, Time.h
, and main.cpp
files.
My teammate has designed and verified two sample inputs demonstrated in Section 2.1 & 2.2. We also designed and discussed the framework (use of data structure and etc.) together.
███ Edited & omitted due to privacy concerns ███
We used Bitbucket
and slack
for collaboration, and we have met on 11.28, 12.5, and 12.6 for discussion.
4. Documentation
Base.h
4.1.Since the parameter
s are all quite self-explanatory in the following functions, this documentation section will omit the introduction of parameter
s.
-
Base()
- Constructor
- Result: set
c_order_id
andc_driver_id
to0
.
-
void add_order (const string i_order_info, const string i_order_time);
- Triggered by
order
command. - Result: (In this order's
vector
node)- pushed
map
s withkey
oforder_info
,order_time
,is_serve
,serve_time
,is_dept
,dept_time
,driver_name
,is_delv
,delv_time
,driver_tip
,is_arrive
, andarrive_time
toorder_rec
. - set key
order_info
to valuei_order_info
. - set key
order_time
to valueorder_time
. - set rest of the keys to value
"NO"
or"UNKNOWN"
.
- pushed
- Triggered by
-
void serve_order (const string i_serve_time) throw (logic_error);
- Triggered by
serve
command. - Requirement: There is a placed but not-yet-cooked order.
- Result: (In this order's
vector
node)- set key
is_serve
to value"YES"
; - set key
serve_time
to valuei_serve_time
;
- set key
- Triggered by
-
void dept_driver (const string i_driver_name, const string i_dept_time) throw (logic_error)
- Triggered by
depart
command. - Requirement:
- There is a served but not-yet-departed order.
- The assigned
i_driver_name
is available.
- Result: (In this order's
vector
node)- set key
is_dept
to value"YES"
. - set key
dept_time
to valuei_dept_time
. - set key
driver_name
to valuei_driver_name
.
- set key
- Triggered by
-
void delv_driver (const string i_driver_name, const string i_delv_time, const string i_driver_tip) throw (logic_error)
- Triggered by
delivery
command. - Requirement:
- There is a departed but not-yet-delivered order.
- The assigned
i_driver_name
is matched with the departed driver.
- Result: (In this order's
vector
node)- set key
is_delv
to value"YES"
. - set key
delv_time
to valuei_delv_time
. - set key
driver_tip
to valuei_driver_tip
.
- set key
- Triggered by
-
void arrive_driver (const string i_driver_name, const string i_arrive_time) throw (logic_error)
- Triggered by
arrive
command. - Requirement:
- There is a delivered but not-yet-arrived driver.
- The assigned
i_driver_name
is matched with the delivered driver.
- Result: (In this order's
vector
node)- set key
is_arrive
to"YES"
. - set key
arrive_time
toi_arrive_time
.
- set key
- Triggered by
-
void login_driver (const string i_driver_name)
- Triggered by
login
command. - Requirement: driver name has no white-spaces.
- Result: (In this driver's
vector
node)- pushed
map
s with key ofdriver_name
,is_login
,is_dept
,total_delv_count
,total_delv_time
,total_drive_time
, andtotal_tip
todriver_rec
. - set key
driver_name
to valuedriver_id
, which is obtained fromc_driver_id
. - set key
is_login
to value1
. - set all other keys to value
0
.
- pushed
- Triggered by
-
void logout_driver (const string i_driver_name) throw (logic_error)
- Triggered by
logout
command. - Requirement:
i_driver_name
must be available. - Result: (In this driver's
vector
node)- set key
is_login
to value0
.
- set key
- Triggered by
-
float get_driver_id (const string i_driver_name) throw (logic_error)
- Requirement:
i_driver_name
exists indriver_sys
. - Result: return
i_drive_name
'sdriver_id
by checkingdriver_sys
.
- Requirement:
-
string get_driver_name (const float i_driver_id) throw (logic_error);
- Requirement:
i_driver_id
is bigger than0
while less thandriver_sys.size()
; - Result: return
driver_id
'si_drive_name
by checkingdriver_sys
.
- Requirement:
-
get_order_id (const string i_order_info) throw (logic_error);
- Requirement:
i_order_info
exists inorder_sys
. - Result: return
i_order_info
'sorder_id
by checkingorder_sys
.
- Requirement:
-
bool is_driver_avbl (const string i_driver_name) throw (logic_error);
- Requirement:
i_driver_name
exists indriver_sys
. - Result:
- true:
i_driver_name
is logged-in but not departed. - false: otherwise.
- true:
- Requirement:
Time.h
4.2.- Time();
- Constructor.
- float time_to_min (const Time time);
- Parameters:
time
: time to be convert.
- Result: return a valid
Time time
from hour-min format to minutes.
- Parameters:
- Time elapsed_time (const Time start, const Time end);
- Requirement:
Time end
is later thanTime start
. - Parameters:
start
: start time.end
: end time.
- Result: return the passed duration from
Time start
toTime end
.
- Requirement:
- bool is_time (const int i_hour, const int i_min);
- Parameters:
i_hour
: input time's hour value for checking.i_min
: input time's min value for checking.
- Result:
- true:
0 <= i_hour <= 23
and0 <= i_min <= 59
. - false: otherwise.
- true:
- Parameters:
- bool is_same_or_later (const Time time_1, const Time time_2);
- Parameters:
time_1
andtime_2
: times to check.
- Result:
- true:
time_2
is same or later thantime_1
. - false: otherwise.
- true:
- Parameters:
- bool is_legal_input (const string last_time_str, const string current_time_str);
- Parameters:
last_time_str
,current_time_str
: times to check, instring
format.
- Result:
- true: if
current_time_str
is later thanlast_time_str
whereas both of them are legit time (is_time() == true
). - false: otherwise.
- true: if
- Parameters:
main.cpp
4.3.Please refer to the actual main.cpp
file, in-line comments/documentations is provided.
It might be worthy to mention that code in main.cpp
shall keep track of the two latest time-related inputs (order_time
, serve_time
, and etc.), and it shall return and exit the program if the current input is invalid (earlier than pervious input, or not in a correct Hour:Min
time format);