-
Notifications
You must be signed in to change notification settings - Fork 0
/
programa.c
208 lines (206 loc) · 5.53 KB
/
programa.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_ALUNOS 50;
typedef struct
{
char nome[50];
float notas[4];
int ativo;
} Aluno;
Aluno alunos[MAX_ALUNOS];
void menu();
void cadastrar();
void remover();
void aprovados();
void reprovados();
void pesquisar();
void listar();
int main(int argc, char const *argv[])
{
menu();
return 0;
}
void menu()
{
int op;
do
{
system("clear"); //linux
//system("cls"); //windows
printf("\n1 - Cadastrar aluno\n2 - Remover aluno");
printf("\n3 - Alunos reprovados\n4 - Pesquisar aluno\n");
printf("\n5 - Listar alunos\n6 - Alunos Aprovados\n0 - Sair\n");
scanf("%d", &op);
getchar();
switch (op)
{
case 1:
cadastrar();
break;
case 2:
remover();
break;
case 3:
reprovados();
break;
case 4:
pesquisar();
break;
case 5:
listar();
break;
case 6:
aprovados();
break;
}
getchar();
} while (op != 0);
}
void cadastrar()
{
char nome[50];
float notas[4];
int op;
do
{
system("clear"); //linux
//system("cls"); //windows
printf("\nNome: ");
fgets(nome, sizeof(nome), stdin);
printf("\n1 Bimestre:");
scanf("%f", notas[0]);
printf("\n2 Bimestre:");
scanf("%f", notas[1]);
printf("\n3 Bimestre:");
scanf("%f", notas[2]);
printf("\n4 Bimestre:");
scanf("%f", notas[3]);
for (int i = 0; i < MAX_ALUNOS; i++)
{
if (alunos[i].ativo == 0)
{
alunos[i].notas[0] = notas[0];
alunos[i].notas[1] = notas[1];
alunos[i].notas[2] = notas[2];
alunos[i].notas[3] = notas[3];
strcpy(alunos[i].nome, nome);
alunos[i].ativo = 1;
break;
}
}
printf("\n1 - Continuar\n0 - Sair");
scanf("%d", &op);
getchar();
} while (op != 0);
}
void remover()
{
int matricula;
listar();
printf("\n Digite a matricula do aluno a ser removido: ");
scanf("%d", &matricula);
--matricula;
alunos[matricula].ativo = 0;
printf("\n Aluno foi excluido com sucesso\n");
getchar();
}
void reprovados()
{
system("clear"); //linux
//system("cls"); //windows
float media;
printf("\n LISTA DE ALUNOS REPROVADOS\n");
for (int i = 0; i < MAX_ALUNOS; i++)
{
if (alunos[i].ativo == 1)
{
media = 0;
media = alunos[i].notas[0] + alunos[i].notas[1] + alunos[i].notas[2] + alunos[i].notas[3];
media = media / 4;
if (media < 7.0)
{
printf("Matricula: %d\n", i + 1);
printf("Nome: %s\n", alunos[i].nome);
printf("1 Bim: %0.2f\n", alunos[i].notas[0]);
printf("2 Bim: %0.2f\n", alunos[i].notas[1]);
printf("3 Bim: %0.2f\n", alunos[i].notas[2]);
printf("4 Bim: %0.2f\n", alunos[i].notas[3]);
printf("-----------\n");
}
}
}
}
void aprovados()
{
system("clear"); //linux
//system("cls"); //windows
float media;
printf("\n LISTA DE ALUNOS APROVADOS\n");
for (int i = 0; i < MAX_ALUNOS; i++)
{
if (alunos[i].ativo == 1)
{
media = 0;
media = alunos[i].notas[0] + alunos[i].notas[1] + alunos[i].notas[2] + alunos[i].notas[3];
media = media / 4;
if (media >= 7.0)
{
printf("Matricula: %d\n", i + 1);
printf("Nome: %s\n", alunos[i].nome);
printf("1 Bim: %0.2f\n", alunos[i].notas[0]);
printf("2 Bim: %0.2f\n", alunos[i].notas[1]);
printf("3 Bim: %0.2f\n", alunos[i].notas[2]);
printf("4 Bim: %0.2f\n", alunos[i].notas[3]);
printf("-----------\n");
}
}
}
}
void pesquisar()
{
char nome[50];
int op;
do
{
system("clear"); //linux
//system("cls"); //windows
printf("\nDigite o nome do aluno para pesquisar: ");
fgets(nome, sizeof(nome), stdin);
for (int i = 0; i < MAX_ALUNOS; i++)
{
if (strstr(alunos[i].nome, nome) != NULL)
{
printf("Matricula: %d\n", i + 1);
printf("Nome: %s\n", alunos[i].nome);
printf("1 Bim: %0.2f\n", alunos[i].notas[0]);
printf("2 Bim: %0.2f\n", alunos[i].notas[1]);
printf("3 Bim: %0.2f\n", alunos[i].notas[2]);
printf("4 Bim: %0.2f\n", alunos[i].notas[3]);
printf("-----------\n");
}
}
printf("\nDigite 0 para sair ou 1 para nova pesquisa: ");
scanf("%d", &op);
getchar();
} while (op != 0);
}
void listar()
{
system("clear"); //linux
//system("cls"); //windows
printf("\n LISTA DE ALUNOS\n");
for (int i = 0; i < MAX_ALUNOS; i++)
{
if (alunos[i].ativo == 1)
{
printf("Matricula: %d\n", i + 1);
printf("Nome: %s\n", alunos[i].nome);
printf("1 Bim: %0.2f\n", alunos[i].notas[0]);
printf("2 Bim: %0.2f\n", alunos[i].notas[1]);
printf("3 Bim: %0.2f\n", alunos[i].notas[2]);
printf("4 Bim: %0.2f\n", alunos[i].notas[3]);
printf("-----------\n");
}
}
}