C
coinjo
Problem Statement
One of the local banks is gearing up for a big advertising campaign and
would like to see how long its customers are waiting for service by
teller/service provider at drive-up window. Several employees have been
asked to keep accurate records for the 24-hour drive-up service. The
collected information, which is read from a file, consists of ID number
of the teller; the time the customer arrived in hours and minutes
(arrival time); the time the customer actually was served in hours and
minutes (service time). There is one record in the file for each
customer. A teller can provide services to many customers. Write a
program that does the following:
a) Reads in the wait data from a file name Bank.txt.
b) Computes the Waiting Time for each customer, in minutes. Waiting
time for each customer is calculated by subtracting the service time by
the arrival time.
c) Compute the Average Service Delay Time for each teller. Average
service delay time is calculated for each teller by summing the waiting
time of all customers served by that teller and dividing that sum by
the total number of customers served by the teller.
d) Calculate Average Waiting Time of all customers. Average waiting
time is the sum of all waiting time divided by the number of customers.
e) Prints a summary showing the Average Waiting Time and Average
Service Delay.
Input
A file containing teller ID, arrival time, and service time. The times
are broken up into integer hours and minutes according to a 24-hour
clock.
Output
The program should print on the screen, the Mean Waiting Time and
Average Service delay time for each teller.
In sample input file, first column represents the teller's Id, second
and third columns represent the arrival time in hours and minutes
respectively. Fourth and fifth columns represent the service time in
hours and minutes respectively.
#include<iostream>
#include<fstream>
using namespace std;
struct Time
{
int hour, minutes;
};
struct Customer
{
int id, waiting_time;
Time arr_time, sr_time;
};
int wtime(Customer c)
{
int count=0;
int tame=0;
c.arr_time.minutes=(c.arr_time.hour*60)+c.arr_time.minutes;
c.sr_time.minutes=(c.sr_time.hour*60)+c.sr_time.minutes;
tame=c.sr_time.minutes-c.arr_time.minutes;
return tame;
}
int main()
{
Customer array[10]={0};
int count=0;
ifstream a;
ofstream b;
double ave=0;
a.open("bank.txt");
b.open("output.txt");
while(count<10)
{
a>>array[count].id;
a>>array[count].arr_time.hour;
a>>array[count].arr_time.minutes;
a>>array[count].sr_time.hour;
a>>array[count].sr_time.minutes;
count++;
}
count=0;
while(count<10)
{
b<<"Waiting Time is"<<endl;
b<<wtime(array[count]);
ave=ave+wtime(array[count]);
b<<endl;
count++;
}
b<<endl;
ave=ave/10;
b<<"AVerage Waiting Time is"<<endl;
b<<ave<<endl;
b<<endl;
count=0;
int count1=0;
ave=0;
int count2=0;
while(count<4)
{
ave=wtime(array[count]);
count1=count+1;
count2=0;
while(count1<10)
{
if(array[count].id==array[count1].id)
{
ave=ave+wtime(array[count1]);
array[count1].id=0;
count2++;
}
count1++;
}
b<<"Average Waiting Time for ID "<<count+1<<" is"<<endl;
b<<ave/(count2+1)<<endl;
count=count++;
count1=count;
}
return 0;
}
It outputs
Waiting Time is
120
Waiting Time is
90
Waiting Time is
30
Waiting Time is
60
Waiting Time is
30
Waiting Time is
30
Waiting Time is
60
Waiting Time is
30
Waiting Time is
45
Waiting Time is
34
AVerage Waiting Time is
52.9
Average Waiting Time for ID 1 is
75
Average Waiting Time for ID 2 is
50
Average Waiting Time for ID 3 is
41.25
Average Waiting Time for ID 4 is
45
Instead of
Waiting Time is
120
Waiting Time is
90
Waiting Time is
30
Waiting Time is
60
Waiting Time is
30
Waiting Time is
30
Waiting Time is
60
Waiting Time is
30
Waiting Time is
45
Waiting Time is
34
AVerage Waiting Time is
52.9
Average Waiting Time for ID 1 is
75
Average Waiting Time for ID 2 is
50
Average Waiting Time for ID 3 is
41.25
Average Waiting Time for ID 4 is
60
Please Help!
One of the local banks is gearing up for a big advertising campaign and
would like to see how long its customers are waiting for service by
teller/service provider at drive-up window. Several employees have been
asked to keep accurate records for the 24-hour drive-up service. The
collected information, which is read from a file, consists of ID number
of the teller; the time the customer arrived in hours and minutes
(arrival time); the time the customer actually was served in hours and
minutes (service time). There is one record in the file for each
customer. A teller can provide services to many customers. Write a
program that does the following:
a) Reads in the wait data from a file name Bank.txt.
b) Computes the Waiting Time for each customer, in minutes. Waiting
time for each customer is calculated by subtracting the service time by
the arrival time.
c) Compute the Average Service Delay Time for each teller. Average
service delay time is calculated for each teller by summing the waiting
time of all customers served by that teller and dividing that sum by
the total number of customers served by the teller.
d) Calculate Average Waiting Time of all customers. Average waiting
time is the sum of all waiting time divided by the number of customers.
e) Prints a summary showing the Average Waiting Time and Average
Service Delay.
Input
A file containing teller ID, arrival time, and service time. The times
are broken up into integer hours and minutes according to a 24-hour
clock.
Output
The program should print on the screen, the Mean Waiting Time and
Average Service delay time for each teller.
In sample input file, first column represents the teller's Id, second
and third columns represent the arrival time in hours and minutes
respectively. Fourth and fifth columns represent the service time in
hours and minutes respectively.
#include<iostream>
#include<fstream>
using namespace std;
struct Time
{
int hour, minutes;
};
struct Customer
{
int id, waiting_time;
Time arr_time, sr_time;
};
int wtime(Customer c)
{
int count=0;
int tame=0;
c.arr_time.minutes=(c.arr_time.hour*60)+c.arr_time.minutes;
c.sr_time.minutes=(c.sr_time.hour*60)+c.sr_time.minutes;
tame=c.sr_time.minutes-c.arr_time.minutes;
return tame;
}
int main()
{
Customer array[10]={0};
int count=0;
ifstream a;
ofstream b;
double ave=0;
a.open("bank.txt");
b.open("output.txt");
while(count<10)
{
a>>array[count].id;
a>>array[count].arr_time.hour;
a>>array[count].arr_time.minutes;
a>>array[count].sr_time.hour;
a>>array[count].sr_time.minutes;
count++;
}
count=0;
while(count<10)
{
b<<"Waiting Time is"<<endl;
b<<wtime(array[count]);
ave=ave+wtime(array[count]);
b<<endl;
count++;
}
b<<endl;
ave=ave/10;
b<<"AVerage Waiting Time is"<<endl;
b<<ave<<endl;
b<<endl;
count=0;
int count1=0;
ave=0;
int count2=0;
while(count<4)
{
ave=wtime(array[count]);
count1=count+1;
count2=0;
while(count1<10)
{
if(array[count].id==array[count1].id)
{
ave=ave+wtime(array[count1]);
array[count1].id=0;
count2++;
}
count1++;
}
b<<"Average Waiting Time for ID "<<count+1<<" is"<<endl;
b<<ave/(count2+1)<<endl;
count=count++;
count1=count;
}
return 0;
}
It outputs
Waiting Time is
120
Waiting Time is
90
Waiting Time is
30
Waiting Time is
60
Waiting Time is
30
Waiting Time is
30
Waiting Time is
60
Waiting Time is
30
Waiting Time is
45
Waiting Time is
34
AVerage Waiting Time is
52.9
Average Waiting Time for ID 1 is
75
Average Waiting Time for ID 2 is
50
Average Waiting Time for ID 3 is
41.25
Average Waiting Time for ID 4 is
45
Instead of
Waiting Time is
120
Waiting Time is
90
Waiting Time is
30
Waiting Time is
60
Waiting Time is
30
Waiting Time is
30
Waiting Time is
60
Waiting Time is
30
Waiting Time is
45
Waiting Time is
34
AVerage Waiting Time is
52.9
Average Waiting Time for ID 1 is
75
Average Waiting Time for ID 2 is
50
Average Waiting Time for ID 3 is
41.25
Average Waiting Time for ID 4 is
60
Please Help!