Question

build a bank simulator system using the C++ STL queue library. You are required to create your
own ADT for that system that:
First, Read from a file the data of incoming customers which includes
ArrivalID, StartTime, and ProcessTime.
You have one line in your Bank in which you will serve your customers as per to their arrival time.
For example if you read the following data from the file
A 1 5
B 2 5
C 4 5
D 20 5
E 22 5
F 24 5
G 26 5
H 28 5
I 30 5
J 88 3
At the beginning the queue in the bank is empty customer A will be arriving at time 1 and will be
served immediately. At time 2 customer B arrives he has to wait until customer 1 is served.
Customer A needs 5 time intervals to be served so he will finish at time 6.
At time 6 customer B will be served and in the queue customer C is waiting.
You are required to simulate this process and print out at the end the following:
Customer No, StartTime, EndTime, and Wait time:
• endTime represents the time the customer left the Bank (fully served). For the above
example the endTime for customer A is 6.
• The wait time is the time interval the customer waited in the queue to be served for
customer A he did not wait so the waitTime is 0 while for customer B the wait time is 4.
See below example of the final runtime for the above data:

Hello, Welcome to the Bank simulator System! No Start 2 20 End Wait 4 16 25 30 35 40 45 50 91 24 26 28 30 9 12 15 Final Stati

EXTRA CREDIT: You can get up to a 30/20 by completing simulating another prioryQueue
simulator where you will read a priority token form the user; the user with the highest priority will
be served first. Even though this is extra credit, you should at least look at it (as you are likely to
see it again very soon). The priority token has two categories VIP, Normal. If you have more than
one VIP customer so you will serve the one that arrives first. You cannot serve any Normal
customer until all the VIP customers are done.
Files: You must submit at least the following files: Bank.h, Bank.cpp, main.cpp, inputFile.txt,
Readme and makefile.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Bank.h

#include <string.h>
using namespace std;
class Customer{
public:
string arrivalId;
int no;
int start;
int process;
int turnAround;
int finish;
int wait;

Customer();
void display();
};

Bank.cpp

#include <iostream>
#include <fstream>
#include<string.h>
#include <vector>
#include <queue>
#include <stdlib.h>
#include "Bank.h"
using namespace std;

Customer::Customer()
{
no=start=finish=process=turnAround=wait=0;
}

void Customer:: display()
{
cout<<"\n"<<arrivalId<<"\t"<<start<<"\t"<<finish<<"\t"<<wait;
}

vector<string> getWords(char* line){
vector<string> v;
string word="";

for(int i=0;i<strlen(line);i++){

if(line[i]==' '){
v.push_back(word);
word="";
}
else {
word=word+line[i];
}

}
v.push_back(word);
return v;

} ///getWords

void printCustomers(Customer customer[100],int customerIndex){
cout<<"\nHello , Welcome to the Bank simulator System \n";
cout<<"\nNo\tStart\tEnd\tWait\n";
int time=0;
for(int i=0;i<customerIndex;i++)
{
time+=customer[i].wait;
customer[i].display();
}

cout<<"\nFinal Statistics:\n";
cout<<"\t Total no of peoples processed :"<<customerIndex;
cout<<"\n\t Average amount of time spent waiting :"<<time/(double)customerIndex<<"\n";

}
///sort based on arrival/start time
void sort(Customer customer[100],int customerIndex){

for (int i = 0; i < customerIndex; i++) {
for (int j = 1; j < (customerIndex - i); j++) {

if (customer[j - 1].start > customer[j].start) {
Customer temp = customer[j - 1];
customer[j - 1] = customer[j];
customer[j] = temp;
}

}
}

}


int main()
{
Customer customer[100];
int customerIndex=0;
char* inputFile="input.txt";
char line[100]; /// read line of file ans store int line char-array

ifstream myfile (inputFile); ///open inputFile for read
int linecount=0; /// no of lines read to 0

if (myfile.is_open()){ ///check whether file is opened for read && write successfully or not
while ( myfile.getline (line,100)){
vector<string> v;
v=getWords(line);
int cnt=0;
for(vector<string>::iterator i = v.begin(); i != v.end(); i++)
{
string value=*i; ///get value
///for ID
if(cnt==0)
{
customer[customerIndex].arrivalId=*i;
cnt++;
continue;
}
char char_array[value.size()+1];
strcpy(char_array, value.c_str()); ///convert string to char* array
int number=atoi(char_array); ///convert char* to int
///start
if(cnt==1)
{
customer[customerIndex].start=number;
}
///process
if(cnt==2)
{
customer[customerIndex].process=number;
}
cnt++;
} ///end for

///increment customer count
customerIndex++;
} ///while line
}//if

///print customers
//cout<<"\n**INITIAL**\n";
//printCustomers(customer,customerIndex);

///if input file contains customer with start tie not sorted then
///sort based on start time
sort(customer,customerIndex);

///set time to 0
int time=0;
//for all customers
for(int i=0;i<customerIndex;i++){
///if time is less/equal to start time of customer
///then wait=0 & time=start
if(time<=customer[i].start)
{
customer[i].wait=0;
time=customer[i].start;
}
///if time is greater than start time of customer
///then wait=time-start
else
{
customer[i].wait=time-customer[i].start;

}
/// finish = time+ process
customer[i].finish=time+customer[i].process;
/// turnAround = finish -start
customer[i].turnAround=customer[i].finish-customer[i].start;
///set time to finish
time =customer[i].finish;
}

//cout<<"\n**FINAL**\n";
printCustomers(customer,customerIndex);
return 0;
}

input.txt

A 1 5
B 2 5
C 4 5
D 20 5
E 22 5
F 24 5
G 26 5
H 28 5
I 30 5
J 88 3

Output

Priority Queue is not implemented as input file does not contain priority information

Add a comment
Know the answer?
Add Answer to:
Build a bank simulator system using the C++ STL queue library. You are required to create your ow...
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
  • Build a bank simulator system using the C++ STL queue library. You are required to create your ow...

    build a bank simulator system using the C++ STL queue library. You are required to create your own ADT for that system that: First, Read from a file the data of incoming customers which includes ArrivalID, StartTime, and ProcessTime. You have one line in your Bank in which you will serve your customers as per to their arrival time. For example if you read the following data from the file A 1 5 B 2 5 C 4 5 D...

  • C PROGRAM: In this assignment, you will use the concept of POSIX threads, semaphores and mutex...

    C PROGRAM: In this assignment, you will use the concept of POSIX threads, semaphores and mutex locks. Consider a very small bank: XYZ. This bank has only one cashier (aka bank teller or customer representative) and a small waiting room for any incoming customers while the cashier is busy with other customer. There is a sofa which can only hold 5 people at maximum. The cashier can only serve one customer at any time. When the cashier is serving one...

  • Q1. Write a program to simulate a grocery waiting queue. Your program should ask the user...

    Q1. Write a program to simulate a grocery waiting queue. Your program should ask the user if they want to add a customer to the queue, serve the next customer in the queue, or exit. When a customer is served or added to the queue, the program should print out the name of that customer and the remaining customers in the queue. The store has two queues: one is for normal customers, another is for VIP customers. Normal customers can...

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

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

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

  • This assignment requires you to create simulations for different scheduling algorithms commonly employed by operating systems...

    This assignment requires you to create simulations for different scheduling algorithms commonly employed by operating systems to achieve multiprogramming. All problems in this assignment assume the following: The simulations you will be creating are for a uniprocessor system (single CPU). Processes in these simulations will require CPU bursts of one or more time units followed by I/O bursts of one or more time units. For simplicity’s sake, when more than one process is executing its I/O burst at the same...

  • QUESTION 1 Customers arrive at a hair salon according to a Poisson process with an average of 1...

    QUESTION 1 Customers arrive at a hair salon according to a Poisson process with an average of 16 customers per hour. Which of the following is most likely true, based on this information: a. The hair salon serves customers on a walk-in basis (rather than by appointment times) b. If 10 customers arrive in the first hour, it is likely that 22 customers will arrive in the next hour. c. If the salon can serve an average of 20 customers...

  • Consider a bank branch that has three distinct customer arrival patterns throughout the day, as measured...

    Consider a bank branch that has three distinct customer arrival patterns throughout the day, as measured by average arrival rates (below) Morning (8:30 11:30): 40/hour Lunch (1:30-1:30): 60/hour Afternoon (1:30 4:00): 3 35/hour. Regardless of the time of day, the average time it takes for a teller to serve customers is 2 minutes, 52 seconds Because of competition with other banks in the area, management has determined that they want to keep the average customer wait before service to be...

  • A critically important aspect of customer service in a supermarket is the waiting time at the...

    A critically important aspect of customer service in a supermarket is the waiting time at the checkout (defined as the time the customer enters the line until he or she is served). Data were collected during time periods in which a constant number of checkout counters were open. The total number of customers in the store and the waiting time (in minutes) were recorded. . Determine the coefficient of determination, r 2 , and interpret its meaning. 6. How useful...

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