-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.c
204 lines (166 loc) · 5.79 KB
/
menu.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
#include <stdio.h>
#include "menu.h"
#include "lotes.h"
void menu_principal(FILE *arq_cursos, FILE *arq_disciplinas, FILE *arq_professores, FILE *arq_professores_disciplinas) {
int i = -1;
while(i != 5) {
printf("\n1 - Fazer um cadastro\n"
"2 - Fazer uma impressao\n"
"3 - Remover cadastro de distribuicao de disciplina\n"
"4 - Carregar arquivo em lote\n"
"5 - Finalizar o programa\n"
"> ");
scanf("%d%*c", &i);
if(i == 1)
cadastrar(arq_cursos, arq_disciplinas, arq_professores, arq_professores_disciplinas);
if(i == 2)
imprimir(arq_cursos, arq_disciplinas, arq_professores, arq_professores_disciplinas);
if(i == 3)
remover(arq_professores_disciplinas);
if(i == 4)
carregar_lote(arq_cursos, arq_disciplinas, arq_professores, arq_professores_disciplinas);
if(i != 1 && i != 2 && i != 3 && i != 4 && i != 5)
printf("(Digito invalido)\n");
}
}
void cadastrar(FILE *arq_cursos, FILE *arq_disciplinas, FILE *arq_professores, FILE *arq_professores_disciplinas) {
int i = -1;
while (i != 5)
{
printf("\n1 - Cadastrar curso\n"
"2 - Cadastrar disciplina\n"
"3 - Cadastrar professor\n"
"4 - Cadastrar distribuicao de disciplina\n"
"5 - Voltar\n"
"> ");
scanf("%d%*c", &i);
if(i == 1)
cadastrar_curso(arq_cursos);
if(i == 2)
cadastrar_disciplina(arq_disciplinas);
if(i == 3)
cadastrar_professor(arq_professores);
if(i == 4)
cadastrar_distribuicao(arq_professores_disciplinas, arq_disciplinas);
if(i != 1 && i != 2 && i != 3 && i != 4 && i != 5)
printf("(Digito invalido)\n");
}
}
void cadastrar_curso(FILE *arq_cursos) {
Curso *c = NULL;
int codigo;
char nome[100];
char area;
printf("\nDigite o codigo do curso\n"
"> ");
scanf("%d%*c", &codigo);
printf("Digite o nome do curso\n"
"> ");
scanf("%s%*c", &nome);
printf("Digite a area do curso\n"
"> ");
scanf("%c%*c", &area);
c = criar_curso(codigo, nome, area);
inserir_curso(arq_cursos, c);
printf("(Curso inserido)\n");
}
void cadastrar_disciplina(FILE *arq_disciplinas) {
Disciplina *d = NULL;
int codigo;
char nome[100];
int codcurso;
int serie;
printf("\nDigite o codigo da disciplina\n"
"> ");
scanf("%d%*c", &codigo);
printf("Digite o nome da disciplina\n"
"> ");
scanf("%s%*c", &nome);
printf("Digite o codigo do curso da disciplina\n"
"> ");
scanf("%d%*c", &codcurso);
printf("Digite a serie da disciplina\n"
"> ");
scanf("%d%*c", &serie);
d = criar_disciplina(codigo, nome, codcurso, serie);
inserir_disciplina(arq_disciplinas, d);
printf("(Disciplina inserida)\n");
}
void cadastrar_professor(FILE* arq_professores) {
CadastroProfessor *cp = NULL;
int codigo;
char nome[1000];
printf("\nDigite o codigo do professor\n"
"> ");
scanf("%d%*c", &codigo);
printf("Digite o nome do professor\n"
"> ");
scanf("%s%*c", &nome);
cp = criar_cadastro_professor(codigo, nome);
inserir_cadastro_professor(arq_professores, cp);
printf("(Professor inserido)\n");
}
void cadastrar_distribuicao(FILE *arq_professores_disciplinas, FILE *arq_disciplinas) {
CadastroProfessorDisciplina *cpd = NULL;
int codigo;
int coddisciplina;
int anoletivo;
int codprofessor;
printf("\nDigite o codigo\n"
"> ");
scanf("%d%*c", &codigo);
printf("Digite o codigo da disciplina\n"
"> ");
scanf("%d%*c", &coddisciplina);
printf("Digite o ano letivo\n"
"> ");
scanf("%d%*c", &anoletivo);
printf("Digite o codigo do professor\n"
"> ");
scanf("%d%*c", &codprofessor);
cpd = criar_cadastro_professor_disciplina(codigo, coddisciplina, anoletivo, codprofessor);
inserir_cadastro_professor_disciplina(arq_professores_disciplinas, arq_disciplinas, cpd);
printf("(Distribuicao inserida)\n");
}
void imprimir(FILE *arq_cursos, FILE *arq_disciplinas, FILE *arq_professores, FILE *arq_professores_disciplinas) {
int i = -1;
while(i != 5) {
printf("\n1 - Imprimir cursos\n"
"2 - Imprimir disciplinas\n"
"3 - Imprimir professores\n"
"4 - Imprimir distribuicoes de disciplinas\n"
"5 - Voltar\n"
"> ");
scanf("%d%*c", &i);
if(i == 1)
imprimir_cursos(arq_cursos);
if(i == 2)
imprimir_disciplinas(arq_disciplinas);
if(i == 3)
imprimir_cadastros_professor(arq_professores);
if(i == 4)
imprimir_distribuicao_ordenada(arq_professores_disciplinas, arq_cursos);
if(i != 1 && i != 2 && i != 3 && i != 4 && i != 5)
printf("(Digito invalido)\n");
}
}
void remover(FILE *arq_professores_disciplinas) {
int codigo;
int anoletivo;
printf("\nDigite o codigo da distribuicao de disciplina\n"
"> ");
scanf("%d%*c", &codigo);
printf("Digite o ano letivo\n"
"> ");
scanf("%d%*c", &anoletivo);
remover_distribuicao_disciplina(arq_professores_disciplinas, codigo, anoletivo);
printf("(Distribuicao removida)\n");
}
void carregar_lote(FILE *arq_cursos, FILE *arq_disciplinas, FILE *arq_professores, FILE *arq_professores_disciplinas) {
char arquivo[100];
printf("\nDigite o nome do arquivo\n"
"> ");
scanf("%s%*c", &arquivo);
ler_arq_txt(arquivo, arq_disciplinas, arq_cursos, arq_professores, arq_professores_disciplinas);
printf("Arquivo lido\n");
}