Question

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 to simulate. For example, somebody might be simulating a hospital: it has doctors (servers) processing patients (transactions) waiting in the waiting room (queue).

Some things are common to all types of servers and transactions and queues, no matter what types of systems they’re simulating.

  • Transactions have a unique identifier, and have some amount of work associated with them. The amount of work varies from transaction to transaction.

  • Servers are the entities capable of performing work. Some servers are faster than others (they can process more work in the same amount of time). Any given server is either performing work (busy) or is free, waiting for a transaction to arrive.

  • Queues are data structures in which new elements are added to the back, and removed from the front. A queue can grow and shrink in size, as elements can be added and removed at different rates.

    Simulations are driven by a clock. Each time the clock ticks, something happens. For example, on tick one, a transaction may enter the system. Let’s say that transaction requires 10 units of work to complete. The transaction is picked up by a free server. The server is capable of performing two units of work per clock tick. The server can therefore determine that the transaction will require 5 clock ticks to complete. It the server knows what the time is now, it can deduce when the transaction will finish. After five clock ticks, the server removes the transaction, and looks in the queue for the next one. One may not exist, in which case the server waits.

    Part 1 - Definition for a Transaction ADT

    Use a struct to define the data members of a Transaction. Transactions are stored in the queue. A transaction has a transaction ID and some number of work units needed to process it. The data members are:

    transaction ID - string
    work units - int

    Part 2 – Definition for a Server ADT

Use a struct to define the data members of a Server. A server has a flag telling whether it’s free or busy, and its speed in processing units per clock tick. When a transaction is started by a server, the time that transaction will end is recorded. The data members are:

free or busy - bool
transaction ID, if busy - string
the speed of the server, in work units per clock tick - int
time that the current transaction will end - int

Part 3 - Class definition for the Queue ADT

Create a class named Queue. A queue will contain some number of elements, each element representing one transaction. Your queue should be templated to allow for any data type.

Use Malik’s queue logic for implementing a queue using an array. See the summary sheet and chapter 8. The user will instantiate a queue object via:

Queue queueName (n);

where queueName is the name the user chose for the object, and n is the number of elements in the array used to hold the queue.

Part 4 – Test your queue

Code up your own main to test your queue functions before you go on to part 5. Use a data type of Transaction. Your main should test all possibilities. Add some elements, delete some elements, dump out the queue and make sure the data structure matches what it should be. Try filling the queue, then overfilling it. Try emptying it, and then try getting another element. Keep your testing main in case you run into problems later on. As I grade your code, I will run my own queue testing program with your queue, so make sure your testing is thorough!

Part 5 - The Simulation

Code an event simulator, using one server. There are countless ways to design an event processing simulator. For a system with one server, try the following:

read from user:

number of clock ticks
probability of a transaction arriving on a clock tick
low and high ranges for processing units per transaction
number of work units per clock tick for the server

clock = 0
server busy = false
while (clock < clock ticks)
  if we’re adding a transaction to queue
   generate transaction
  add to queue
     endif
if server not busy
   if available transaction
   put transaction into server
   put ending time into server
   mark server busy
     endif
   endif
   if server busy and ending time = now
   remove transaction, record statistics
   create transaction log record
mark server free
   endif
   clock ++
end while

display
number of completed transactions
number of processing units used
was there a transaction in progress when clock expired?
number of unprocessed transactions in queue
total processing time required by those unprocessed transactions

Your transaction log is a file that details the transactions that were fully processed by your simulation. Each time a transaction finishes, create a log record containing the following information:

transaction ID
time transaction started
time transaction ended
work units consumed

Name the file a6log.txt and store it someplace on your hard drive. You’ll find that the transaction log will provide valuable information for debugging purposes.

When I run your code, I will look in your transaction log to make sure that the log matches the simulation activity and statistics I see on the console.

that is it.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
 #include <cstdlib> #include <iostream> #include <iomanip> #include "queue.h" using namespace std; int shortest_queue(Queue q[], int queuecount) { int shortest = 0; for (int i = 1; i < queuecount; ++i) { if(q[i].size() < q[shortest].size()) shortest = i; } return shortest; } int queue_total(Queue q[], int queuecount) { int custcount = 0; for (int i = 0; i < queuecount; ++i) custcount += q[i].size(); return custcount; } int main() { int trans_time = 0; int count = 0; int entry_time; int wait_sum = 0; int wait_time = 0; int seed; int ARV_PROB; int MAX_TRANS_TIME; int DURATION; int queuecount; int shortline; int temp; cout << "Enter these parameters of the simulation:" << endl; cout << " The number of queue/server pairs: "; cin >> queuecount; Queue line[queuecount]; cout << " The probability that a customer arrives in one tick (%): "; cin >> ARV_PROB; cout << " The maximum duration of a transaction in ticks: "; cin >> MAX_TRANS_TIME; cout << " The duration of the simulation in ticks: "; cin >> DURATION; cout << "Enter a random number seed: "; cin >> seed; srand(seed); for (int time = 0; time < DURATION; ++time) { if ( rand() % 100 < ARV_PROB ) { shortline = shortest_queue(line, queuecount); line[shortline].enqueue(time); } if ( trans_time == 0 ) { if ( !line.empty() ) { entry_time = line.dequeue(); temp = (time - entry_time); if(temp > wait_time) wait_time = temp; wait_sum += (time - entry_time); ++count; trans_time = (rand() % MAX_TRANS_TIME) + 1; } } else { --trans_time; } cout << setw(4) << time << setw(4) << trans_time << " " << line << endl; } cout << count << " customers waited an average of "; cout << wait_sum / count << " ticks." << endl; cout << "The longest time a customer waited was " << wait_time << " ticks." << endl; cout << queue_total(line, queuecount) << " customers remain in the lines." << endl; return 0; }

As you did not mention how much queue you want to handle at a time , i have written a code for one queue stimulation at a time. Hope you will get your answer.

Add a comment
Know the answer?
Add Answer to:
Hi! it is c++ queue simulation please read the instructions, write codes, and explain the code...
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
  • 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...

  • In this assignment, you will write a simulator to determine maximum, minimum and average queue length....

    In this assignment, you will write a simulator to determine maximum, minimum and average queue length. Important: You can implement with the linked list classes described in Chapter 20 or the queueing structures described in Chapter 21. The user inputs the following information a. The relative weight of arrivals. This is an integer between 1-100. b. The number of servers. This is an integer between 1-25. c. The relative weight of a server. This is an integer between 1-100. d....

  • Implement the event-driven simulation of a bank that this chapter described. A queue of arrival events...

    Implement the event-driven simulation of a bank that this chapter described. A queue of arrival events will represent the line of customers in the bank. Maintain the arrival events and departure events in an ADT event list, sorted by the time of the event. Use a reference-based implementation for the ADT event list The input is a text file of arrival and transaction times. Each line of the file contains tiie arrival time and required transaction time for a customer....

  • Consider a single-server queueing system with arrival and service details as: Interarrival times: 3, 2, 6,...

    Consider a single-server queueing system with arrival and service details as: Interarrival times: 3, 2, 6, 2, 4, 5 Service times: 2, 5, 5, 8, 4, 5 Prepare a table show below for the given data. Stop simulation when the clock reaches 20. Write a Java program, to implement this single-server queueing system, print out the table shown below: You should create a future event list in your Java code, and print out the contents of FE list in each...

  • // =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations // ...

    // =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations //   - (i.e. queue_t* create_queue(unsigned int _capacity) should not have additional arguments) // - You should not have any 'printf' statements in your queue functions. //   - (You may consider using these printf statements to debug, but they should be removed from your final version) // ==================================================...

  • C Programming - Please Help us! Implementing Load Balancing, the 3 Base Code files are at the bot...

    C Programming - Please Help us! Implementing Load Balancing, the 3 Base Code files are at the bottom: Implementing Load Balancing Summary: In this homework, you will be implementing the main muti-threaded logic for doing batch based server load balancing using mutexes Background In this assignment you will write a batch-based load balancer. Consider a server which handles data proces- sing based on user requests. In general, a server has only a fixed set of hardware resources that it can...

  • 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...

  • Hi I need a fix in my program. The program needs to finish after serving the...

    Hi I need a fix in my program. The program needs to finish after serving the customers from the queue list. Requeriments: Headers: DynamicArray.h #ifndef DynamicArray_h #define DynamicArray_h #include using namespace std; template class DynamicArray { V* values; int cap; V dummy; public: DynamicArray(int = 2); DynamicArray(const DynamicArray&); ~DynamicArray() { delete[] values; } int capacity() const { return cap; } void capacity(int); V operator[](int) const; V& operator[](int); DynamicArray& operator=(const DynamicArray&); }; template DynamicArray::DynamicArray(int cap) { this->cap = cap; values =...

  • 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...

  • In C++: Please help me correct this code .... All parts with (FIX ME) #include <algorithm> #include <climits&gt...

    In C++: Please help me correct this code .... All parts with (FIX ME) #include <algorithm> #include <climits> #include <iostream> #include <string> // atoi #include <time.h> #include "CSVparser.hpp" using namespace std; //============================================================================ // Global definitions visible to all methods and classes //============================================================================ const unsigned int DEFAULT_SIZE = 179; // forward declarations double strToDouble(string str, char ch); // define a structure to hold bid information struct Bid { string bidId; // unique identifier string title; string fund; double amount; Bid() {...

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