-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_cad_struct.c
186 lines (147 loc) · 4.62 KB
/
04_cad_struct.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <string.h>
#define TAM 10
/*
Desenvolva um programa para vendas de passagens de ônibus. Defina uma
STRUCT, crie o menu de opções e todas as funções necessárias para manipular
esta STRUCT;
Cadastrar pessoa;
Vender passagem;
Imprimir comprovante;
*/
typedef struct
{
char nome[20];
int id;
char tel[11];
char ori[20];
char des[20];
} Cliente;
void menu(int opc)
{
setlocale(LC_ALL,"portuguese");
Cliente c[TAM];
char nome[20];
int i,n,p,pos,aux;
i = aux = p=0;
for(int i = 0 ; i < TAM; i++)
{
strcpy(c[i].nome,"VAZIO");
strcpy(c[i].tel,"VAZIO");
strcpy(c[i].ori,"VAZIO");
strcpy(c[i].des,"VAZIO");
c[i].id = 0;
}
do
{
printf("\n 01 - |CADASTRO|");
printf("\n 02 - |VENDAS DE PASSAGEM|");
printf("\n 03 - |IMPRIMIR COMPROVANTE|");
printf("\n DIGITE UMA DAS OPCOES OU [ZERO]PARA SAIR:");
fflush(stdin);
scanf("%d",&opc);
while(opc < 0 || opc > 3)
{
system("cls");
printf("\n COLOCA UMA DAS OPCOES [1-3],REDIGITE OU [ZERO] PARA SAIR:");
fflush(stdin);
scanf("%d",&opc);
}
if(opc != 0)
{
switch(opc)
{
case 1:
printf("\n Quantos clientes deseja cadastrar:");
fflush(stdin);
scanf("%d",&n);
aux = p;
for(i = p; i < aux + n; i++)
{
system("cls");
printf("\n ---------------");
printf("\n [%d°] Nome:",(i+1));
fflush(stdin);
gets(c[i].nome);
printf("\n [%d°] Telefone:",(i+1));
fflush(stdin);
gets(c[i].tel);
p++;
}
printf("-----------------------");
printf("\n CADASTRO FEITO COM SUCESSO");
printf("\n");
printf("\n APERTE QUALQUER TECLA");
getch();
system("cls");
break;
case 2:
printf("\n --- E NECESSARIO TER CADASTRO PARA COMPRAR PASSAGEM ---");
printf("\n --------------------------------------------------------");
printf(" \n Digite um nome: ");
fflush(stdin);
gets(nome);
for(i=0; i<TAM; i++)
{
if(strcmp(nome,c[i].nome)== 0)
{
pos = i;
printf("\n REGISTRO ENCONTRADO");
printf("\n Idade:");
fflush(stdin);
scanf("%d",&c[pos].id);
printf("\n Origem:");
fflush(stdin);
gets(c[pos].ori);
printf("\n Destino:");
fflush(stdin);
gets(c[pos].des);
printf("\n -\-\-\-\-\-\-APERTE QUALQUER BOTAO PARA CONTINUAR O PROCEDIMENTO");
getch();
}
}
printf("\n -- FINALIZADO --");
printf("\n APERTE QUALQUER TECLA");
getch();
system("cls");
break;
case 3:
printf("\n --- E NECESSARIO TER CADASTRO PARA IMPRIMIR COMPROVANTE---");
printf("\n --------------------------------------------------------");
printf(" \n Digite um nome: ");
fflush(stdin);
gets(nome);
for(i=0; i<TAM; i++)
{
if(strcmp(nome,c[i].nome)== 0)
{
pos = i;
printf("\n REGISTRO ENCONTRADO");
printf("\n Nome: %s",c[pos].nome);
printf("\n Origem: %s",c[pos].ori);
printf("\n Destino: %s",c[pos].des);
printf("\n -\-\-\-\-\-\-APERTE QUALQUER BOTAO PARA CONTINUAR O PROCEDIMENTO");
getch();
}
}
printf("\n -- FINALIZADO --");
printf("\n APERTE QUALQUER TECLA");
getch();
system("cls");
break;
default:
break;
}
}
}
while(opc != 0);
}
int main()
{
int x;
menu(x);
return 0;
}