Ampersand doesn't work!

Good evening guys.
So this project is about the timing of the customers' served in the first 30 minutes on a Thursday morning in a bank.
there is a new customer arrives every 3 minutes.
However the ampersand doesn't work at the "Timing" function.
Could you guys help me with it?
Thanks


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include<iostream>
using namespace std;
class queue {
public:
	void queue_init(int size);
	void push(char x);
	void pop();
	int size();
	char front();
	char back();
	int Empty();
	int full();
	int timing(int&, int);

private:
	char* queue_ptr;
	int max_len;
	int rear_cnt;
	int front_cnt;
};

int queue::size() {
	return (rear_cnt - front_cnt);
}

void queue::queue_init(int arr_size) {
	queue_ptr = new char[arr_size];
	max_len = arr_size - 1;
	front_cnt = 0;
	rear_cnt = 0;
}

int queue::Empty() {
	return (rear_cnt == front_cnt);
}

int queue::full() {
	return (rear_cnt == max_len + 1);
}
char queue::front() {
	return (queue_ptr[front_cnt]);
}

char queue::back() {
	return (queue_ptr[rear_cnt - 1]);
}

void queue::push(char X) {
	if (rear_cnt == max_len + 1)
		cout << "Error queue is full \n";
	else
	{
		queue_ptr[rear_cnt] = X;


		rear_cnt++;
	}
}

void queue::pop() {

	if (Empty())
		cout << "Error queue is empty\n";
	else
	{
		queue_ptr[front_cnt] = 0;
		front_cnt++;
	}
}
	int queue::timing(int& time_arrive,int current)
	{
		return (time_arrive + current);
	}


int main(){
	queue Q;
	int time_arrive = 810;
	int time_finish = 810;
	char customers[10] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k' };
	std::cout << "This program will calculate the customer service throughout the next 30 minutes.\n"
		"Since a customer enters the Bank every 3 minutes, therefore the size of the queue should be 10." << endl;
	std::cout << "The customer service opens at 8:10 am" << endl;
	Q.queue_init(10);
	for (int i = 1; i <= 10; i++)
	{
		Q.push(customers[10]);
		Q.front();
		std::cout << "the current time is " << Q.timing(time_arrive, 3) << "am" << endl;
	}



	return 0;
}
Last edited on
You never modify time_arrive anywhere inside the timing function.
what do you mean? and how can I implement that?

Knowing that the time should increase (in int main) by 3 minutes everytime....sadly it continue to show as "813" 10 times
Calling Q.timing(time_arrive, 3) returns the value of time_arrive+3. You print this value, but nowhere are you changing the value of the variable time_arrive. If you want the value of time_arrive to change you have to write the code for that to happen (e.g. time_arrive += 3;).
Topic archived. No new replies allowed.