URGENT HELP NEEDED

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!
 
G

Gabriel

coinjo said:
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-lite/how-to-post.html#faq-5.7
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.2
http://www.parashift.com/c++-faq-lite/how-to-post.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.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!
 
K

Karl Heinz Buchegger

coinjo said:
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?
 
N

Niklas Norrthon

coinjo said:
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
 
K

Karl Heinz Buchegger

Gabriel said:
[...}
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.
 
K

Karl Heinz Buchegger

Karl said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top