CptS 122 – Data Structures
Programming Assignment 5: Grocery Store
Simulation
Assigned: Wednesday, October 3,
Due:
I. Learner
Objectives:
At the conclusion
of this programming assignment, participants should be able to:
II.
Prerequisites:
Before starting
this programming assignment, participants should be able to:
Note: Parts of this
assignment were inspired by Deitel and Deitel’s Supermarket Simulation problem (Exercise 12.15). We’ve all had the
pleasant experience of standing in line at the grocery store. As I’m standing
in line I’m always trying to figure out if I chose the line with the fastest
service. In most cases, I fail miserably. Let’s write a program to simulate two
lines in a grocery store, which will allow us to better understand how to
select the fastest line.
For this assignment
you will need to simulate two lines using queues. This will require that you
develop enqueue ( ) (insert), dequeue
( ) (delete), and printQueue ( ) operations for a
queue. Although you will instantiate two queues, each one of these will consist
of the same kind of queue nodes. Define a queue node in the following manner:
typedef struct queueNode
{
int customerNumber; // Unique identifier; starts at 1; after 24
hours should be reset to 1
int serviceTime; //
Random time; varies between express and normal lanes; units in minutes
int totalTime; //
totalTime = serviceTime +
sum of serviceTimes of customers in line before this
customer; units in minutes
struct
queueNode *pNext;
} QueueNode;
One of your queues
will represent the express lane and the other a normal lane. You will randomly
generate arrival times and service times of customers into each lane. The
express lane has customers arrive every one to five minutes, and customers
arrive every three to eight minutes in the normal lane. Service times vary from
one to five minutes, and three to eight minutes, for express and normal lane
customers, respectively. As customers arrive into each line print out a message
indicating in which line each customer arrives, along with the overall
corresponding arrival time and customer number. When customers have finished
checking out, print out a message indicating which line the customer was in,
along the corresponding customer number and totalTime in the line. Allow for the simulation to
run for n number of minutes,
where n is inputted by the user.
The general program
flow is as follows:
Hints: Since this
is a simulation one minute is really one unit of time. Thus, the incrementing
of an integer variable could represent one minute of time elapsing.
BONUS:
Modify QueueNode such that it contains a pointer to the start
of a dynamic singly linked list. The linked list will consist of grocery items
corresponding to one person. These items should be strings like “cereal”,
“milk”, “steak”, etc. Adjust the serviceTime of the QueueNode so that it is no longer random, but
proportional to the number of items for the person served.
IV. Submitting Assignments:
V. Grading Guidelines:
This assignment is
worth 100 points. Your assignment will be evaluated based on a successful
compilation and adherence to the program requirements. We will grade according
to the following criteria:
BONUS:
Up to 20 pts for implementation of grocery item list/customer