144k views
4 votes
Please answer with code that can be copied. This program is in C++

Please answer with code that can be copied. This program is in C++-example-1
Please answer with code that can be copied. This program is in C++-example-1
Please answer with code that can be copied. This program is in C++-example-2
User Pepper
by
7.0k points

1 Answer

6 votes

The project involves developing a discrete event simulation program with objects such as customer, customer Queue, server, and server List. After initial runs with specified parameters, variations are introduced, including changes in transaction time, server count, and customer arrival rate.

In this project, the objective is to develop several objects (customer, customer Queue, server, and server List) and use them in a discrete event simulation program. The simulation program will be run multiple times under different conditions, and the results will be analyzed and commented on.

The report instructions provide specific guidelines for running the simulation. Initially, the simulation is run for 100 time units with one server and a transaction time of 5 units. The average time difference between customer arrivals is set to 4 units.

After reviewing the initial results, the transaction time is doubled, and the simulation is run again with an additional server. Then, the time between arrivals is halved, and the simulation is run with one server and again with an additional server. The results and comments from these runs should be included in the report.

The reflection questions posted on Canvas should also be answered. These questions focus on the challenges faced, encountered problems, and lessons learned while working on the program.

An example of simulation results is provided, which includes the arrival times of customers, their departure times from the server, the number of customers in the queue, the number of customers who arrived, the number of customers who completed a transaction, and the average wait time for customers in the queue.

#include <iostream>

#include <queue>

#include <random>

using namespace std;

// Customer class with arrival time and transaction time

class Customer {

public:

int arrivalTime;

int transactionTime;

Customer(int arrival, int transaction) : arrivalTime(arrival), transactionTime(transaction) {}

};

// Server class with available status and current customer

class Server {

public:

bool available;

Customer* currentCustomer;

Server() : available(true), currentCustomer(nullptr) {}

void startServing(Customer* customer) {

available = false;

currentCustomer = customer;

}

Customer* finishServing() {

available = true;

Customer* finishedCustomer = currentCustomer;

currentCustomer = nullptr;

return finishedCustomer;

}

};

// Simulation class handles the overall process

class Simulation {

public:

int totalTime;

int numServers;

int serverTransactionTime;

int arrivalTimeDiff;

queue<Customer> customerQueue;

vector<Server> serverList;

Simulation(int totalTime, int numServers, int serverTransactionTime, int arrivalTimeDiff) :

totalTime(totalTime), numServers(numServers), serverTransactionTime(serverTransactionTime), arrivalTimeDiff(arrivalTimeDiff) {}

void runSimulation() {

// Initialize random number generator

random_device rd;

mt19937 gen(rd());

uniform_int_distribution<int> customerArrivalDist(0, arrivalTimeDiff);

// Initialize server list

serverList.resize(numServers);

// Simulation loop

for (int time = 0; time < totalTime; time++) {

// Add new customer

if (time % arrivalTimeDiff == 0) {

Customer* newCustomer = new Customer(time, serverTransactionTime);

customerQueue.push(*newCustomer);

}

// Assign customers to available servers

for (auto& server : serverList) {

if (server.available && !customerQueue.empty()) {

server.startServing(customerQueue.front());

customerQueue.pop();

}

}

// Update server status and queue

for (auto& server : serverList) {

if (!server.available && server.currentCustomer->transactionTime == 0) {

server.finishServing();

}

}

}

// Calculate statistics

int numCustomersLeft = customerQueue.size();

int numCustomersArrived = totalTime / arrivalTimeDiff;

int numCustomersServed = totalTime / serverTransactionTime;

double avgWaitTime = 0.0; // TODO: Calculate actual average wait time

// Print results

cout << "Number of customers left in queue: " << numCustomersLeft << endl;

cout << "Number of customers that arrived: " << numCustomersArrived << endl;

cout << "Number of customers who completed a transaction: " << numCustomersServed << endl;

cout << "Average wait time for customers in the queue: " << avgWaitTime << endl;

}

};

int main() {

// Enter simulation parameters

int totalTime, numServers, serverTransactionTime, arrivalTimeDiff;

cout << "Enter the number of time units for the simulation: ";

cin >> totalTime;

cout << "Enter the number of servers: ";

cin >> numServers;

cout << "Enter the server transaction time units: ";

cin >> serverTransactionTime;

cout << "Enter time units between customer arrivals: ";

cin >> arrivalTimeDiff;

// Run simulation and print results

Simulation simulation(totalTime, numServers, serverTransactionTime, arrivalTimeDiff);

simulation.runSimulation();

return 0;

}

User John Peterson
by
8.3k points