-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoficinaCarros.c
265 lines (239 loc) · 6.7 KB
/
oficinaCarros.c
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#include<stdio.h>
#include<stdlib.h>
#define SIZE 8
//data of the car
typedef struct
{
int id;
int typeCar;
int typeService;
float hours;
}Car;
//data of the queue
typedef struct
{
int head, end;
float hours;
Car array[SIZE];
}Queue;
//prototype of functions
Queue *new();
int empty(Queue *q);
int full(Queue *q);
void enqueue(Queue *q, Car x);
Car dequeue(Queue *q);
void show(Queue *q);
void waitInd(Queue *q1, Queue *q2, Queue *q3, Queue *q4);
void waitForType(Queue *q);
int main()
{
Car x;
int cond, answer, answerRemove, answerShow, answerView; //get the answers
//creation of queues for each type of service
Queue *oilChange = new();
Queue *alignment = new();
Queue *balancing = new();
Queue *tireChange = new();
printf("\nDigite 0 para iniciar:\n");
scanf("%d",&cond);
while(cond == 0)
{
printf("\nO que você deseja fazer:\n1)Adicionar um carro\n2)Remover um carro da fila\n");
printf("3)Imprimir uma fila de serviço\n4)Visualizar carros em espera INDEPENDENTE DO SERVIÇO\n");
printf("5)Visualizar carros em espera POR TIPO DE SERVIÇO\n");
scanf("%d",&answer);
if (answer == 1) //chose add a car to queue
{
printf("\nDigite o número da ordem do seu serviço:\n");
scanf("%d",&x.id);
printf("\nDigite o tipo do seu carro:\n\n1)Passeio\n2)Utilitário\n");
scanf("%d",&x.typeCar);
printf("\nDigite o tipo de serviço que você deseja fazer:\n\n1)Troca de Oléo\n");
printf("2)Alinhamento\n3)Balanceamento\n4)Troca de Pneus\n");
scanf("%d",&x.typeService);
if (x.typeService == 1)//chose oil change
{
x.hours = 1.0;
enqueue(oilChange, x);
}
if (x.typeService == 2)//chose alignment
{
if(x.typeCar == 1)//passenger car
{
x.hours = 0.5;
enqueue(alignment, x);
}
else //utility car
{
x.hours = 1.0;
enqueue(alignment, x);
}
}
if (x.typeService == 3)//chose balancing
{
if(x.typeCar == 1)//passenger car
{
x.hours = 0.5;
enqueue(balancing,x);
}
else //utility car
{
x.hours = 1.0;
enqueue(balancing,x);
}
}
if (x.typeService == 4)//chose tire change
{
x.hours = 0.5;
enqueue(tireChange, x);
}
}
if (answer == 2)//chose remove a car to queue
{
printf("\nEscolha o serviço do qual você quer REMOVER um carro:\n1)Troca de Oléo\n");
printf("2)Alinhamento\n3)Balanceamento\n4)Troca de Pneus\n");
scanf("%d",&answerRemove);
if (answerRemove == 1)//chose oil change
dequeue(oilChange);
if (answerRemove == 2)//chose alignment
dequeue(alignment);
if (answerRemove == 3)//chose balancing
dequeue(balancing);
if (answerRemove == 4)//chose tire change
dequeue(tireChange);
}
if (answer == 3)//chose display a queue
{
printf("\nEscolha o serviço do qual você deseja IMPRIMIR:\n1)Troca de Oléo\n2)alignment\n3)balancing\n4)Troca de Pneus\n");
scanf("%d",&answerShow);
if (answerShow == 1)//chose oil change
show(oilChange);
if (answerShow == 2)//chose alignment
show(alignment);
if (answerShow == 3)//chose balancing
show(balancing);
if (answerShow == 4)//chose tire change
show(tireChange);
}
if (answer == 4)//chose see the wait independent of type of service
waitInd(oilChange, alignment, balancing, tireChange);
if (answer == 5)//chose see the wait for type of service
{
printf("\nEscolha o serviço do qual você quer visualizar:\n1)Troca de Oléo\n");
printf("2)Alinhamento\n3)Balanceamento\n4)Troca de Pneus\n");
scanf("%d",&answerView);
if (answerView == 1)//chose see the wait from oil change
waitForType(oilChange);
if (answerView == 2)//chose see the wait from alignment
waitForType(alignment);
if (answerView == 3)//chose see the wait from balancing
waitForType(balancing);
if (answerView == 4)//chose see the wait from tire change
waitForType(tireChange);
}
printf("\nDigite 0 para continuar:\n");
scanf("%d",&cond);
}
return 0;
}
Queue *new()//create a new queue
{
Queue *q = (Queue *) malloc(sizeof(Queue));
q->head = 0;
q->end = 0;
}
int empty(Queue *q)//check if the queue it's empty
{
return q->head == q->end;
}
int full(Queue *q)//check if the queue it's full
{
return q->end - q->head == SIZE;
}
void enqueue(Queue *q, Car x)//add a car to queue
{
int i;
float sum = 0.0;
if (full(q))
printf("\nFila cheia! Sinto muito, volte depois.\n");
else
{
q->array[q->end % SIZE] = x;
q->end++;
printf("\nCarro Adicionado à fila!\n");
for (i=q->head; i<q->end; i++)
sum += q->array[i%SIZE].hours;
printf("\nSeu tempo máximo factível para a execução do serviço é de: %.2f hora(s)\n",sum);
}
}
Car dequeue(Queue *q)//remove a car to queue
{
Car aux;
if (empty(q))
{
printf("\nEssa fila de serviço já está vazia. Não há o que remover!\n");
}
else
{
printf("\nCarro removido com sucesso!\n");
aux = q->array[q->head % SIZE];
q->head++;
return aux;
}
}
void show(Queue *q)//display a queue
{
int i;
if (empty(q))
printf("\nEsta fila está vazia!\n");
else
printf("\nFila: \n");
for (i=q->head; i<q->end; i++)
printf("\n Carro de número --> [%2d] ",q->array[i%SIZE].id);
printf("\n");
}
void waitInd(Queue *q1, Queue *q2, Queue *q3, Queue *q4)//show wait INDEPENDENT the type of service
{
int a, b, c, d, passengerCars = 0, utilityCars = 0;
for (a=q1->head; a<q1->end; a++)//q1 represent oil change's queue
{
if (q1->array[a%SIZE].typeCar == 1)//means that type of the car is passenger
passengerCars++;
else //means that type of car is utility
utilityCars++;
}
for (b=q2->head; b<q2->end; b++)//q2 represent alignment's queue
{
if (q2->array[b%SIZE].typeCar == 1)
passengerCars++;
else
utilityCars++;
}
for (c=q3->head; c<q3->end; c++)//q3 represent balancing's queue
{
if (q3->array[c%SIZE].typeCar == 1)
passengerCars++;
else
utilityCars++;
}
for (d=q4->head; d<q4->end; d++)//q4 represent tire change's queue
{
if (q4->array[d%SIZE].typeCar == 1)
passengerCars++;
else
utilityCars++;
}
printf("\nHá %d carro(s) de passeio e %d carro(s) utilitários em espera independente do serviço\n",passengerCars,utilityCars);
}
void waitForType(Queue *q)//show wait FOR type of service
{
int i, passengerCars = 0, utilityCars = 0;
for (i=q->head; i<q->end; i++)//q represent the chosen queue
{
if (q->array[i%SIZE].typeCar == 1)//means that type of the car is passenger
passengerCars++;
else //means that type of the car is utility
utilityCars++;
}
printf("\nHá %d carro(s) de passeio e %d carro(s) utilitários em espera nesta fila!\n",passengerCars,utilityCars);
}