Question: C + + Bank Simulation using Binary Search Tree Do not use any C + + STL libraries like . I will give thumbs up
CBank Simulation using Binary Search Tree
Do not use any C STL libraries like I will give thumbs up for any program sucessfully outputting the required objective. Please complete the Queue.h BinarySearchTree.h and driver.cpp Thank you.
Students will implement a bank Service system that simulates customers entering and leaving a bank. This program will read an input file that contains the number of tellers and the arrival time and service time of each customer. As you can see the input file below is not ordered by arrival time. An example input file is as follows:
inputtxt
numTellers
arrivalTime serviceTime
arrivalTime serviceTime
arrivalTime serviceTime
arrivalTime serviceTime
arrivalTime serviceTime
Three tellers are working. The arrival and service times for customers are as follows:
A customer arrives at and requires service for units of time.
A customer arrives at and requires service for units of time.
A customer arrives at and requires service for units of time.
A customer arrives at and requires service for units of time.
A customer arrives at and requires service for units of time.
Considering these, heres the scenario:
Customer arrives at Since no other customers are present, all tellers are available, and the customer is immediately serviced. The customers departure time is calculated as
Customer arrives at time and can be serviced immediately, scheduled for departure at time
Customer arrives at time and be serviced immediately, scheduled for departure at time
Customer arrives at time Unfortunately, all tellers are busy. At time Customer leaves, freeing a teller and Customer can be serviced. Customer s departure time is scheduled as
At time Customer arrives at time freeing a teller, and Customer can be serviced immediately. Customer s departure time is scheduled as
The picture below illustrates how tellers serve the customers: at the very bottom of the question
The first three customers are promptly served by three tellers without any wait. However, the fourth customer needs to wait for before being served by teller who finishes serving another customer at time Customer arrives at time and is immediately served because teller is available at that moment.
Queue:
Initialize a queue to store information about customers waiting in line, representing each customer arrival that hasnt been processed yet.
At program start, read the input file containing customer records. For each arrival, create a node with customer information arrivalTime and serviceTime and insert it into the queue, maintaining the firstinfirstout FIFO order.
In the given instance, the queue displays customers in the order of arrival, with the customer who arrived at being the first node and the one arriving at being the last.
The queue displays the following:
The Queue.h is shown below:
Queueh
struct Customer
int arrivalTime;
int serviceTime;
int waitTime;
int departureTime;
;
struct qNode
Customer customer;
qNode next;
;
class Queue
public:
Queue;
bool isEmpty; check if head is NULL
Customer peek; get the first customer from the queue
void enqueueCustomer;
void dequeue;
Customer peek; return first customer on the queue
private:
qNode head;
;
Next, process customer services using a binary search tree.
Binary Search Tree:
Create a BinarySearchTree that represents customers currently being serviced.
When adding a new customer to the tree, calculate customers departure time by adding the current time and service time. Insert the customer into the tree in ascending order sorted by departure time.
BinarySearchTree.h Implementation:
struct bstNode
Customer value;
bstNode left;
bstNode right;
;
class BinarySearchTree
public:
BinarySearchTree;
bool isEmpty ; check if root is NULL
void InsertCustomer int ; customer and current time
void deleteCustomer;
int smallestDepartTime; find the smallest departure time from the BST
private:
bstNode root;
void InsertNodebstNode& Customer, int; current time
void DeleteNodebstNode& Customer;
;
After inserting the first tree customers to tree, BinarySearchTree is shown below:
Each node represents customers arrivalTime, serviceTime, waitTime, and departureTime.
Main function:
Read input file, creating a customer node for each, and enqueue them into a queue. Continue to enqueue all customers into the queue.
Perform the following procedure until the queue is empty:
Dequeue a customer from the queue.
Remove customers who departed before this current customers arrival from a BST: delete customers with the lowest departure time and increase open tellers.
Set the current time to customers arrival time, which is used for calculating waiting and departure times in the BST
If no tellers are available, wait until one is: update the current time with the lowest departure time, remove the customer with smallest departure time from the BST and increase open teller by
Service current customer: insert this customer and current time into BST then decrease open tellers.
Note: The BST is sorted by customer's departure time, calculated by adding service time to current time.
You may use the following partial code:
int main
Queue q;
BinarySearchTree bst;
read input and enqueue cutomers into queue
service customer throught BST
int openTellers; assign with numTellers from input file.
int currentTime;
whileqisEmpty
get a customer from queue
whiledelete customers with the lowest departure time and increase open tellers.
Set the current time to customer's arrival time, used for calculating waiting and departure times in the bst
If there are no open tellers, wait until there is one
ifopenTellers
Insert this customer and current time into BST and decrease open tellers.
Grading Rubric:
Driver program
Reading data from the file.
Output result.
Binary Search Tree:
int smallestDepartureTime; find the smallest departure time.
void InsertCustomer c int currentTime; Insert a customer into BST
void deleteCustomer; remove the customer with smallest departure time
Queue Class:
void enqueueCustomer; add a new customer to the queue
void dequeue; delete the customer from the queue
Customer peek; get the first customer in the queue
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
