IN C++ CREATE 2 CLASSES and a BANK QUEUE simulation at each time interval. Outpu
ID: 3720676 • Letter: I
Question
IN C++ CREATE 2 CLASSES and a BANK QUEUE simulation at each time interval. Output the simulation at each interval.
The bank has N tellers servicing the customers. As an example, you may choose N = 4. Each teller has two states, free or busy. The program loops through discrete time steps t = 1, 2, . . . Tstop, where T stop is an input parameter. At each time step, either 0, 1 or 2 persons arrive at the bank, and get added to the back of the queue. This information can be read from an input data file. The customers at front of the queue get assigned a free teller. If there are two free tellers at a given time step, then two customers pop off the queue in that time step. Each customer conducts either 1, 2 or 3 tasks, as specified below: – Deposit a check – Withdraw some cash – Print recent transactions, from a list. A teller takes 1 time step to complete a task. So, if a customer wants to deposit a check, and withdraw some cash, the total service time is 2 time steps. The number of customers in the queue gets updated at each time step. Each arriving customer has an ID, account number, account balance and a list of recent transactions, as its data members.
SUGGESTED CLASSES: Teller class, with ID and status. Customer class with ID, account number, account balance and a list of recent transactions. For customer ID, use C1, C2, C3 . . .. This will make it easier to generate and track test input and output. The list of transactions can be in a map associated to each account. All accounts can have a default balance or as an input param
The example input text file for bank looks like this (without headers):
tarrival deposit 100 printrecent True False False True withdraw customer C1 C2 C3 C4 ntransact 2 2 4 50 200 10 2 50 100Explanation / Answer
//Application Program
#include <iostream>
using namespace std;
#include <vector>
#include <map>
#include <sstream>
#include <fstream>
#include <stdlib.h>
class Customer
{
int cid;
string accountno;
double balance;
public:
Customer(){
balance=500;
}
void withdraw(double);
void deposit(double);
void print();
};
void Customer :: withdraw(double amount)
{
if(balance < amount)
cout << "In sufficent funds "<<endl;
else
{
balance -= amount;
}
}
void Customer :: deposit(double amount)
{
balance += amount;
}
void Customer :: print()
{
cout << "Bank Book Details "<<endl;
//cout << "cid "<<cid;
//cout <<
}
struct book
{
int time;
string cust;
int trans;
double deposit;
double withdraw;
string printrec;
};
class Teller
{
int tellerCount;
int tstop;
map <string,bool> tid;
ifstream inputfile;
book b1;
vector <book> queuelist;
public:
Teller(int,int);
void Service();
void readCustomerFile();
void addCustomertoQueue();
void showAction(string,book);
};
Teller :: Teller(int tcount , int tstop)
{
this->tstop = tstop;
ostringstream os;
os<<"T";
tellerCount = tcount;
for(int i=0;i<tcount;i++)
{
os<<i+1;
tid[os.str()]=false;
}
inputfile.open("file.txt");
}
void Teller :: Service()
{
for(int i=0;i<tstop;i++)
{
cout << "Time "<< i+1 << " : ";
readCustomerFile();
}
addCustomertoQueue();
}
void Teller:: readCustomerFile()
{
string input;
//getline(inputfile,)
inputfile >> input;
b1.time = atoi(input.c_str());
inputfile >> input;
b1.cust = input;
inputfile >> input;
b1.trans = atoi(input.c_str());
inputfile >> input;
b1.deposit = atof(input.c_str());
inputfile >> input;
b1.withdraw = atof(input.c_str());
inputfile >> input;
b1.printrec = input;
queuelist.push_back(b1);
}
void Teller :: showAction(string queue,book tbook)
{
cout << "Teller1 assign Customer "<< tbook.cust <<endl;
if(tbook.deposit)
{
cout << tbook.cust << " is depositing $"<<tbook.deposit << endl;
tbook.deposit=0;
}
else if(tbook.withdraw)
{
cout << tbook.cust << " is withdrawing $"<<tbook.withdraw << endl;
tbook.withdraw=0;
}
else if(tbook.printrec == "True")
{
cout << tbook.cust << " is Printing transction test " << endl;
tbook.printreec="False";
}
tbook.trans -= 1;
if(tbook.trans == 0)
tid[queue] = false;
}
oid Teller :: addCustomertoQueue()
{
//book tbook= queuelist.front();
//queuelist.pop_back();
map <string, bool> :: iterator it;
book tbook;
for(it=tid.begin(); it != tid.end(); it++)
{
if(it->second == false)
{
tbook= queuelist.front();
queuelist.pop_back();
showAction(it->first,tbook);
}
else
{
cout << "Teller "<< it->first << " is Busy..";
showAction(it->first,tbook);
}
}
//cout << "Customer " <<queuelist.front().cust << endl;
}
int main()
{
Teller obj(3,5);
obj.Service()
}