469,631 Members | 1,334 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

URGENT HELP NEEDED

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.mi nutes;

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!

Dec 1 '05 #1
5 1342
coinjo wrote:
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.
Please read the following:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.7
http://www.parashift.com/c++-faq-lit...t.html#faq-5.2
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

http://www.parashift.com/c++-faq-lite/containers.html
#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.mi nutes;

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!

Dec 1 '05 #2
coinjo wrote:

Please Help!


Help with what?

It seems you have a working program. That program,
produces some output. That output might or
might not be correct. I can't say because I don't
know the input data.

Where is your problem?

--
Karl Heinz Buchegger
kb******@gascad.at
Dec 1 '05 #3
Gabriel wrote:

[...}
Average Waiting Time for ID 3 is
41.25
Average Waiting Time for ID 4 is
45

Instead of
[...] Average Waiting Time for ID 3 is
41.25
Average Waiting Time for ID 4 is
60


Oh. I see.
You posted lots of text to figure just to let us
figure out that your numbers are not what they
should be in one place.

Add additional output statements to your program, to figure
out in which way the program came up with a value of 60.
*You* need to understand where that value 60 comes from.
Then you will know
* either: where to look further to figure the whole thing out
* or: how to fix it.

Sorry. But this is programming. Debuggin code is an integral
part of programming and you need to develop some skills in it.
As long as only 1 value as the result of some simple calculations
is not what it should, debugging is really not a big problem.
So go ahead and tackle that problem.

Note: Most newbies have some fear in introducing additional output
statements in their code. There is nothing to worr about. It is
just a normal process and can be undone easily when the program logic
is fixed.
If the average waiting time for some teller is wrong, I would start
with outputting the waiting times for tellers (in addition to the average).
Then compare that with the input file. What to do next depends on what
that comparison comes up with.

--
Karl Heinz Buchegger
kb******@gascad.at
Dec 1 '05 #4
Karl Heinz Buchegger wrote:

Note: Most newbies have some fear in introducing additional output
statements in their code. There is nothing to worr about. It is
just a normal process and can be undone easily when the program logic
is fixed.
If the average waiting time for some teller is wrong, I would start
with outputting the waiting times for tellers (in addition to the average).
Then compare that with the input file. What to do next depends on what
that comparison comes up with.


Another hint:
When reading input either from the user or from a file, it
is *always* a good idea to output immediatly what the program
has read and compare that with what it should read. You
are not the first one who spent lots of time in analysing
some calculations just to figure out after some hours, that
the calculation is correct, but the input fed to it is not.

--
Karl Heinz Buchegger
kb******@gascad.at
Dec 1 '05 #5
"coinjo" <co****@gmail.com> writes:
Problem Statement
[ long homework assignment snipped ]
Please Help!


It would be easier to help you if you tell us what you need help
with. What is your problem? You just posted a long text describing
your assignment, some code, and some output, but you didn't tell
us what you need help with. (Nobody here is going to do your
homework for you, but we will help you by pointing you in the
right direction if you can be a bit more specific.

/Niklas Norrthon
Dec 1 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by felix_william | last post: by
12 posts views Thread by Vibhajha | last post: by
4 posts views Thread by Random | last post: by
7 posts views Thread by meenasamy | last post: by
3 posts views Thread by N. Spiker | last post: by
reply views Thread by Christopher | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.