Currently I am working on a project to Simulate a Grocery Store with :
1 super express lane
2 express lanes
1 regular lane
The issue I have come across is trying to store my random generator for the # of items each customer holds into the array so that at the end I can add up all the values to calculate the max items that were bought in each lane.
I have the following files:
LinkedList.h
ListNode.h
Passenger.h
Queue.h
Random.h
I won't show every one of them but just the snippet of codes that matter/involve with my main code that calls the random generator.
In Random.h I have the following:
#ifndef RANDOM_H
#define RANDOM_H
#include <cstdlib>
#include <ctime>
class Random {
public:
Random() {
srand((unsigned)time(0));
}
Random(int value) {
srand(value);}
//Return random integer range 0 -> 1
double next_double() {
return double(rand()) / RAND_MAX;
}
int item_purchase(int n) {
//make a case using a number 1-100(100 is max number of items they can have)
n = (rand() % 100) + 1;
return int(next_double() * n);
}
The function that generates the items purchased function in Random.h is in my Checkout_Simulation.h file. The function I am working on is:
template <typename NODETYPE>
void Checkout_Simulation<NODETYPE> :: run_sim() {
int number = 0;
static int const SIZE = 0;
int super_items[SIZE] = {0};
int ex1_items[SIZE] = {0};
int ex2_items[SIZE] = {0};
int regular_items[SIZE] = {0};
for(clock_time = 0, clock_time <total_time; clock_time++){
item_obj.item_purchase(number);
if (number < 15) {
super_express.check_new_arrival(clock_time, display_all);
}
else if (number >15 && number <=20){
express_line1.check_new_arrival(clock_time, display_all);
express_line2.check_new_arrival(clock_time, display_all);
}
else {
regular_line.check_new_arrival(clock_time, display_all);
}
if (clock_time >= finish_time){
start_checkout();
}
}//end for loop
}
Queue.h check_new_arrival function so you can understand that this adds a customer
//See nitial_rate = new_rate;
template <typename NODETYPE>
void Queue :: check_new_arrival(int clock, bool display_all){
int number = 0;
if (simulation_obj.next_doubleValue < initial_rate) {
current_queue.push(Passenger(clock_time));
if(display_all) {
cout <<"Time is " << clock << ": " << queue_name
<< " arrival, new queue size is "
<< current.queue.size() <<endl;
}
}
}
So what I want is for example, the random number comes out as 10. It will go to the if statement of number <15 in run_sim()... following the other if nested statements and update the array. How do I implement this? I can't exactly make a for loop to add them since it Simulates and goes through this function once at a time. Please help explain and give me some direction. I would appreciate it!
Aucun commentaire:
Enregistrer un commentaire