# c++ problem

Discussion in 'C++' started by preetimomi, Jun 25, 2008.

1. ### preetimomiNew Member

Joined:
Jun 25, 2008
Messages:
1
0
Trophy Points:
0
can you solve this c++ program...............
..................................................................
*Waiting In Line
write a bank ATM simulation program in C++. The simulation's purpose is to determine the average waiting time for customers using the ATMs.

Problem Description

There are three inputs to the program:

M - the number of minutes to run the simulation for,
P - the probability of a customer arriving in each minute, and
N - the number of ATMs in the bank.
For example, if M = 60, P = 0.5, and N = 4, then we are simulating 4 ATMs over a 60 minute period where in each minute there is a 50% chance that a customer arrives.

Whenever a customer arrives, randomly determine their transaction time which should be between 1 and 5 9 minutes (inclusive). If an ATM is available the customer will go to that ATM, otherwise enter the customer in the shortest queue.

Treat each minute as a discrete event (i.e. minutes should not be further divided into seconds).

Top level Simulation Loop
The simulation control loop can be written as a while loop like this:

while (min < M or there are customers to process) // Process new customer if (min < M and a new customer arrives - based on P) assign customer (i.e. transaction time and arrival minute) to shortest queue increment customer count // Process ATMs for (i = 0 to N) if (ATM is in use) decrement transaction time of its customer by 1 if (ATM transaction time == 0) //customer is done set ATM status to available if (ATM is available) //take the next customer from the ATM's queue if (ATM has a customer in its queue) remove the customer at the front of the queue increment the total waiting time by the appropriate amount assign the customer's transaction time to ATM increment minSimulation Components
Here are some thoughts about what data you will need to keep track and where:

Top Level (the main program file)
The top level program needs to contain the main simulation loop (described above). It also needs variables for M, P and N. In addition you will need to record the following:

A count of the number of customers
The total wait time for all customers
An array of ATMs
Note that the main program should use functions to break the program into easily manageable pieces

ATMs
Each ATM needs to keep track of data related to it, that is:

Remaining transaction time for the current customer
Availability (a boolean value, or a method that returns a boolean value based on the remaining transcation time)
Customer queue - let's call the class ATMqueue

You should create an ATM class with the member variables noted above, and appropriate methods to set and retrieve values for those variables. The class methods will probably include the following:

Constructor
Destructor
Assign customer (which will call the queue's insert method). It should take a single int parameter that represents the current minute.
Process customer (which will call the queue's remove method, and set the ATM's remaining transaction time) - this method should return an int that represents the time that the customer waited. It should take a single int parameter that represents the current minute.

Decrement transaction time (for the passage of time)
Return the length of the ATM's queue
Return the remaining transaction time for the current customer

Customer Queue (ATMQueue class)

You should create a customer queue class to record data required for waiting customers. This data consists of:

A Customer i.e.

Customer transaction time (determined when the customer arrives)
The time (in minutes since the start of the simulation) that the customer arrives - this is necessary to determine how long the customer has been waiting when they leave the queue
The queue should keep track of the number of people in the queue (so that you can determine the shortest queue)

Your queue must be implemented using a linked list, and the insert and remove methods must run in constant (O(1)) time

You can create a struct for Nodes like so (or you may create a Node class if you wish):

struct Node{ Customer cust; Node* next;}You should create a very simple Customer class with attributes for transaction time and arrival time.

Simulation Output
During the Simulation
For each minute of that the simulation runs you should print the contents of each ATM queue, that is:

The number of people in the ATM queue (including the person actually using the ATM)
The number of minutes remaining for the person using the ATM
Simulation End

When the simulation ends you should calculate the average waiting time. The time should be displayed along with the input values, and you should test your simulation with different values for P, M, and N to see the effect.
When your outer loop (that processes the minutes) ends, the ATM queues may still contain customers. You should continue the simulation loop until all the queues are empty, except that no new customers should be generated once M minutes have passed.

Sample Run
I've the function that runs my simulation, runSimulation (imaginatively!). Here is an example of running it, with values for N (2), M (10), and p (0.9).

runSimulation(2, 10, 0.9); //2 ATMs, 10 minutes, p = 0.9 for a customer arriving Output

Sample runs, the first number after each ATM is the number of customers in the queue (including the person using the ATM), the second is the number of minutes remaining for the person using the queue.

Note that if you use more than 3 ATMs that you are not likely to have many people waiting. This is particularly true if the maximum transaction time is 5 minutes (as used to be the case before I changed it).

Here is another example:

runSimulation(3, 10, 0.9); //3 ATMs, 10 minutes, p = 0.9 for a customer arriving

2. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,009
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
Yes, but I guess that's not the answer you want.
We're not going to do your homework for you. If you want to hire a programmer then you have to pay the going rate and not treat us like idiots.
Why are you doing a programming course if you don't want to learn how to program? Assignments are not about getting 100%, they are about the teacher being able to identify students who are struggling with the subject so that they can give extra help.

The above program won't be difficult to write but you need to make some effort and we will help you. How far have you got (apart from posting the whole project onto a forum in the hope that someone won't spot it's an assignment) and where are you stuck?