Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this computer assignment, you are to write and implement a C++ program to si

ID: 3639407 • Letter: F

Question

For this computer assignment, you are to write and implement a C++ program to
simulate the behavior of a typical grocery store. The purpose of this program is simply to collect statistical data during the simulation and print the final statistics at the end of the simulation. In this model, customers enter the store by random inter-arrival times and then they start picking up the grocery items, which takes a random amount of time. After picking up the grocery items, a customer gets in the checkout line to pay for his/her itemsThe duration of the service time in the checkout line is also random, and the service order is FCFS.
Programming Notes:

1. All necessary values and definitions in your program are given in the header file
prog5.h. To use them in your program, insert the following line at the top of your
source file: #include “/home/onyuksel/courses/340/progs/12s/p5/prog5.h”.

2. All random numbers in simulation have integer values and the time unit for the
simulation clock is in minutes. Before starting to generate random numbers, call
srand ( SEED ) function to initialize the RNG, where SEED value is given in the header
file prog5.h. To get a random integer in the range [ MAX, MIN ], execute: rand ( ) % (
MAX – MIN + 1 ) + MIN. For inter-arrival times, the range is [ MIN_INT_ARR,
MAX_INT_ARR ], for the time to pick up grocery items, the range is [ MIN_PICK,
MAX_PICK ], and for the service time to pay for the grocery items, the range is [
MIN_SERV, MAX_SERV ]. All of these values are given in the header file. Of course, your program is supposed to work for any given values.

3. To capture the data values of a customer as a single unit, a data structure is defined
as typedef struct { int id; int atime, wtime, checkout } cust; where id refers to a
customer id with the first customer has id =1, the second customer has id = 2, and
so on; atime is the arriving time of a customer to the store, and the first customer
arrives at the clock time 0; wtime is the waiting time of a customer in the checkout
line before the customer starts paying for the grocery items; and checkout is the
time that a customer completes picking up the grocery items and enters in the
checkout line.

4. For customers who are in the process of picking up the grocery items, a multiset
container is defined of type multiset < cust, cmp >, where cmp is defined as a class to
compare the elements of the multiset. When a customer enters to the store, create a
structure object of type cust and insert it in the multiset by calling its member
function insert ( ). To compare the checkout values of two individual customers in
the multiset < >, implement and use the function object cmp ( ). Here, we’re using a
multiset container instead of a list container because of the reason that the
elements of a multiset is always kept in a sorted order with a giving sorting
criterion.
5. For customers in the checkout line, define a queue container of type queue < cust >.
To enter a customer in the queue < >, use the member function push ( ), and remove
a customer from the queue < >, use the member function front ( ) and then pop ( ).

6. To capture the time events for the simulation as a single unit, a data structure is
defined as typedef struct { int next_arr, next_dept, next_checkout } event; where
next_arr is the arrival time of the next customer to the store, next_dept is the time of the departure time of the next customer from the store, and next_checkout is the
time of completion of picking up the grocery items and entering the checkout line
for the next customer in the store.

7. To capture the statistical data values in simulation as a single unit, a data structure
is defined as typedef struct { int num_dept; int tot_shop, tot_wait, tot_serv } stat; where num_dept is the total number of customers departed from the store; tot_shop is the total amount of shopping time in the store for all num_dept customers; tot_wait is the total amount of waiting time for all num_dept customers waited in the checkout
line; and tot_serv is the total amount of time for all num_dept customers served
when they paid for their grocery items.

8. In addition to the main ( ) routine, implement the following subroutines in your
program:
• void init_vars ( event& e, stat& s ) : This routine initializes the values in
structures e and s.

• void Arrival ( event& e, const int& id, MS& ms ) : This routine is called when a new
customer arrives to the store. It creates an object for the arriving
customer with the id number id, initializes the arrival time, the waiting
time in the queue, and the time of starting to pick the grocery items for
that object, and then inserts the object in multiset ms. Finally, it updates
the timing values, next_arr and next_checkout, of structure e.

• void Checkout ( event& e, MS& ms, Q& q ) : This routine is called when a
customer completes picking up the grocery items in the store and ready to
enter the checkout line. It removes the object for that customer from
multiset ms and inserts the object in queue q, and updates the timing
values, next_dept and next_checkout, of structure e, but next_dept is
updated only if the object becomes the only object in the queue.

• void Departure ( event& e, Q& q, stat& s ) : This routine is called when a customer
departs from the store. It removes the object for the departing customer
from queue q, and if the queue contains more cust objects, it updates the
waiting time for the customer at the front of the queue and the timing
value next_dept in structure e. Finally, it updates the statistical values in
the structure s by calling the function update_find_stat ( ).

• int arr_time ( const int& clock ) : This routine generates a random integer for the
inter-arrival time for a customer and it returns the arrival time of the next
customer, where clock is the current time for the simulation clock.3

• int dept_time ( const int& clock ) : This routine generates a random integer for
the service time of the customer in front of the checkout line and it
returns the departure time of the customer from the store, where clock is
the current time of the simulation clock.

• int start_checkout ( const int& clock ) : This routine generates a random integer
for the total time of picking up the grocery items for a customer and it
returns the time of completion of picking up the items, where clock is the
current time for the simulation clock.

• int update_clock ( const event& e, const bool& f1, const bool& f2 ) : This routine
updates the simulation clock to the time of the earliest one of the three
possible events specified in the structure e using the conditions given by
the flag variables f1 and f2, where f1 is true if the multiset <> is not empty
and f2 is true if the queue <> is not empty.

• void update_fin_stat ( stat& s, const cust& c, const int& clock ) : At the completion
of shopping (at the clock time) of customer c, this routine computes the
shopping time, waiting time, and service time of that customer, updates
the values in structure s, and if the clock shows that the current
simulation time is a multiple of SAMPLE_INT (as given in the header file), it
prints out the following values: customer number, customer id,
customer’s shopping time, waiting time in the checkout line, and the
customer’s service time.

• void print_find_stat ( stat& s ) : At the end of the simulation, this routine prints
out the total number of customers departed from the store and the total
simulation time SIM_TIME (as given in the header file), which is the time
that the simulation stops. It also computes the average values in s over all
customers departed from the store at the time SIM_TIME and prints out
these statistical values on stdout.

• bool cmp :: operator ( ) ( const cust& c1, const cust& c2 ) const : This function
object compares the times of picking up the grocery items for customers
c1 and c2.

9. In the main ( ) routine, create objects for a multiset < > and a queue < >, initialize the simulation clock to 0, id number to 1, initialize the RNG with the seed value SEED, and call init_vals ( ) to initialize the data members in structures for time events and statistical values. Assume that the first customer arrives to the store at the time 0. After processing the earliest one (in time) of the following three possible events: (1) a customer arrives in the store; (2) a customer completes picking up the grocery
items and enters in the checkout line; and (3) a customer completes shopping and
departs from the store, update the simulation clock to the time of that event calling
the subroutine update_clock ( ). If the updated clock is greater than SIM_TIME, stop
the simulation. Finally, call the function print_fin_stat ( ) to print out the final
statistical values.4

10. If the simulation clock shows that the next event is an arrival of a customer, then
create a cust object for that customer, set the values of id, atime, wtime and checkout for the object. Insert the object in the multiset < >, compute the arrival time of the next customer, and find out the time of the customer who has the minimum amount of time to finish picking up the grocery items and the first one to enter in the checkout line among all customers in the multiset < >. To process this task, the main ( ) routines calls the subroutine Arrival ( ).

11. If the simulation clock shows that the next event is the time that a customer is
finished picking up the grocery items and ready to enter in the checkout line, then
create a cust object for that customer, remove the object from the multiset < >, and
insert it into the queue < >. After removing the object from the multiset < >, find out
the time of the next customer in the multiset < > who has the minimum amount of
time to finish picking up the grocery items and the first one to enter in the checkout
line among the remaining customers in the multiset < >. After inserting the object in
the queue < >, if the object is the only one in the queue < >, compute the departure
time of the customer for that object. To process this task, the main ( ) routine, calls
the subroutine Checkout ( ).

12. If the simulation clock shows that the next event is a departure of a customer, then remove the object for that customer from the queue < >. After the removal, if the queue < > contains more cust objects, compute the departure time of the next
customer for the object next in the queue < >, and update the wtime for that object.
Finally, call the function update_fin_stat ( ) to update the statistical values. To
process this task, the main ( ) routine calls the subroutine Departure ( ).
After compiling and linking the source file of your program, execute it as: prog5.exe &> prog5.out, where prog5.exe is the executable file of your program and prog5.out will contain the output of your program. You can find the correct output of this program in file prog5.out, which is in the same directory with the header file prog5.h.For your program, a proper documentation is required and no global variables are permitted, and for I/O operations, you’re not allowed to use the functions in the C library. If you want to use different data structures and/or variables, do not include the header file prog5.h in your program, and instead, include the header file 340.h and your own header file. And of course, you can always use additional data structures and variables in your program.

Explanation / Answer

#include "stdafx.h" #include using namespace std; class GroceryItem { private: int stockNum; double itemPrice; double quantity; double total; }; class dataEntry { public: void display(); void setStockNum(int); void setItemPrice(double); void setQuantity(double); void total(double); }; void dataEntry::display() { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote