Question

Programming Assignment Description For this assignment, you will write a program that simulates people checking out at a groc

C++

Sample run might look like this:

How many minutes should the simulation run? 10
Running simulation for 10 minutes.
minute 1: nothing happens
minute 2: customer 1 arrives and will need 3 minutes to check out
minute 3: nothing happens
minute 4: customer 2 arrives and will need 1 minute to check out
minute 5: customer 3 arrives and will need 1 minute to check out
minute 5: customer 1 has checked out
minute 6: customer 2 has checked out
minute 7: customer 4 arrives and will need 4 minutes to check out
minute 7: customer 3 has checked out
minute 8: nothing happens
minute 9: nothing happens
minute 10: nothing happens
The were 4 customers.
3 customers successfully checked out.
The maximum queue size was 2.

Your main program might start like this:

#include <iostream>
#include <queue>
#include <cstdlib>
#include <ctime>
using namespace std;
struct nodeType
{

int person;

    int timeNeeded;
}

int main() {

    queue<nodeType> checkoutLine;
    NodeType customer;
    srand(time(0));

...

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Code in text form as well as screenshots of code and output are put below. Kindly rate if you find it helpful. Thanks.
#include <iostream>
#include <queue>
#include <cstdlib>
#include <ctime>

using namespace std;
struct nodeType
{
        int person;
        int timeNeeded;
};
 
 
 
int main() {
 
        queue<nodeType> checkoutLine;
        srand(time(0));
        int count = 1;  //count of no. of customers
 
        int time, max_queue_size = 0;
        int time_spent = 0;
        int total_checked = 0;
        cout << "How many minutes should the simulation run? : ";
        cin >> time;
        int happens;  //keep track of something happening every minute
        for (int i = 1; i <= time; i++) {
                happens = 0;
                int r = (rand() % 100) + 1;
                if (r > 75) {
                        nodeType *customer = new nodeType;    //allocate memory for a new nodeType
                        customer->person = count;
                        customer->timeNeeded = (rand() % 4) + 1;
                        cout << "minute " << i << ": Customer " << count << " arrives and will take " << customer->timeNeeded << " minutes to check out.\n";
                        checkoutLine.push(*customer);  //makes a copy of the allocated nodeType struct and pushes it into the queue.
                        free(customer);   //free memory temporarily allocated
                        count++;           //increment customer number.
                        happens = 1;
 
                }
 
                if (!checkoutLine.empty()) {
                        if (time_spent >= checkoutLine.front().timeNeeded) {
                                cout << "minute " << i << ": Customer "  << checkoutLine.front().person << " has checked out\n";
                                checkoutLine.pop();
                                total_checked++;
                                time_spent = 0;
                                happens = 1;
 
                        }
                        
                }
 
                if (!checkoutLine.empty()) 
                        time_spent++;
                
                if (happens == 0)   //if nothing happens print message
                        cout <<"minute "<< i<<": nothing happens\n";  
 
                if (checkoutLine.size() > max_queue_size) {
                        max_queue_size = checkoutLine.size();
                }
 
        }
 
        cout << "\nThere were " << count - 1 << " customers" << endl;
        cout << total_checked << " customers sucessfully checked out"<<endl;
        cout << "The maximum queue size was " << max_queue_size <<endl;
 
        
        
        return 0;
}

Code Screenshots

Iliue queue> #include <cstdlib> #include <ctime> using namespace std; Estruct node Type int person; int timeNeeded; Dint mainfree(customer); count++; happens = 1; ULLS . LUPY OT the allocated node Type struct and pushes it into the queue. //free memo

Code output

How many minutes should the simulation run? : 40 minute 1: nothing happens minute 2: Customer 1 arrives and will take 2 minut

Add a comment
Know the answer?
Add Answer to:
C++ Sample run might look like this: How many minutes should the simulation run? 10 Running...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Queues This programming exercise introduces the Queue data structure. The students must create all the necessary...

    Queues This programming exercise introduces the Queue data structure. The students must create all the necessary methods for the queue and use the queue in a Java program. Step 1 - Create a new project in Netbeans Use the following naming convention: “Module4_Lastname_Assignment1”. Step 2 - Build a solution You have been asked to create a customer service program for a new phone store that will be opening soon. Since this company anticipates being the agent for a rising new...

  • Hello, I am having some trouble with a supermarket checkout simulation program in C++. What I...

    Hello, I am having some trouble with a supermarket checkout simulation program in C++. What I have so far just basically adds customers to the queue and prints when they arrive. I am struggling with how to implement a way of keeping track of when a given customer finishes(I will attach what I have so far). I had already created queue and node classes (with headers and cpp files) that I modified in my attempt. I would be very grateful...

  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

  • Consider a simple queuing system in which customers arrive randomly such that the time between successive...

    Consider a simple queuing system in which customers arrive randomly such that the time between successive arrivals is exponentially distributed with a rate parameter l = 2.8 per minute. The service time, that is the time it takes to serve each customer is also Exponentially distributed with a rate parameter m = 3 per minute. Create a Matlab simulation to model the above queuing system by randomly sampling time between arrivals and service times from the Exponential Distribution. If a...

  • C++ Lists, and a little queuing theory The MegaMicroMart (a subsidiary of Fly-By-Night Industries) is planning...

    C++ Lists, and a little queuing theory The MegaMicroMart (a subsidiary of Fly-By-Night Industries) is planning their next Big Small-Box Store. They want to ensure good customer service, and you've been hired to do some simulations to advise them on how to set up their checkout lines. This is a discrete-time simulation. This means that for our purposes, time advances in discrete 'ticks'. Each tick, everyone who's going to arrive arrives all at once, while at the same time everyone...

  • C++ -- Event processing simulation using a transaction queue Hi! it is queue simulation please read...

    C++ -- Event processing simulation using a transaction queue Hi! it is queue simulation please read the instructions, write codes, and explain the code with comments. Thank you Transactions enter the system and are stored in a queue. Each transaction represents some work that needs to be accomplished. Servers exist which process transactions. Servers take transactions off the queue and process them. you’re building the simulation framework. The idea is that somebody would take your framework, and add the specifics...

  • please explain all the steps. I need it ASAP. i will give u good ratings. Do...

    please explain all the steps. I need it ASAP. i will give u good ratings. Do in java file Queues are often used to simulate the flow of people, cars, airplanes, transactions, and so on. Write a program that models checkout lines at a supermarket, using the Queue class from the queue.java program (Listing 4.4). Several lines of customers should be displayed; you can use the display, insertſ), and remove() method. You can add a new customer by pressing a...

  • Hi! it is c++ queue simulation please read the instructions, write codes, and explain the code...

    Hi! it is c++ queue simulation please read the instructions, write codes, and explain the code with comments. Thank you Transactions enter the system and are stored in a queue. Each transaction represents some work that needs to be accomplished. Servers exist which process transactions. Servers take transactions off the queue and process them. you’re building the simulation framework. The idea is that somebody would take your framework, and add the specifics for whatever type of system it was going...

  • This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to...

    This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example listed below) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked...

  • Write a C++ program to display workers schedule for a company. To accomplish this (1) Write...

    Write a C++ program to display workers schedule for a company. To accomplish this (1) Write a struct Time with attributes (at least) : hours, minutes and seconds. Add other functions or attributes you need to get the job done (2) Write a class Schedule with attributes : Day of week, start_time, end_time and activity. Schedule should have at least (a) Display to display the schedule (b) Length to return the duration of the schedule (ie end_time - start_time), (c)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT