-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
263 lines (217 loc) · 4.89 KB
/
main.cpp
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
#include "basicas.cpp"
#define MAXCOD 8
#define MAXSEXO 2
struct Alumno
{
char codigo[MAXCOD];
char nombre[LIM];
int edad;
int sexo; //campo categorizado
float prom;
};
char TSexo[MAXSEXO][LIM]={"Masculino", "Femenino"};
//operaciones basicas de ALumno
void iniciaAlumno(Alumno &A)
{
A.codigo[0]=NULL;
A.nombre[0]=NULL;
A.edad=0;
A.sexo=0;
A.prom=0.0;
}
void leeAlumno(Alumno &A)
{
do{
printf("\n Ingrese codigo (7 caracteres): ");
fflush(stdin);
gets(A.codigo);
}while(!(strlen(A.codigo)==MAXCOD-1));
printf("\nIngrese nombre: ");
gets(A.nombre);
A.edad=leeEntero("\n Ingrese edad: ", 15, 40);
A.sexo=validaTabla("\n Ingrese sexo: ", TSexo, MAXSEXO);
A.prom=leeReal("\n Ingrese promedio: ", 0.0, 20.0);
}
void mostrarAlumno(Alumno &A)
{
printf("\n Codigo: %s",A.codigo);
printf("\n Nombre: %s",A.nombre);
printf("\n Edad: %d",A.edad);
printf("\n Sexo: %s",TSexo[A.sexo-1]);
printf("\n Promedio: %.2f",A.prom);
}
struct listaAlumnos
{
Alumno *pA;
int N;
};
//Operaciones basicas listaALumnos
void iniciaListaAlumno(listaAlumnos &LA)
{
LA.pA= new Alumno [MAX];
LA.N=0;
}
void inserta(listaAlumnos &LA, Alumno &A){
if(LA.N<MAX){
LA.pA[LA.N]=A;
LA.N++;
}
else{
printf("\n No hay espacio.....");
}
}
void leerListaAlumno(listaAlumnos &LA)
{
Alumno A;
do{
iniciaAlumno(A);
leeAlumno(A);
inserta(LA,A);
}while(continuar("\n Desea continuar (S/N): ")=='S');
}
void mostrarListaAlumno(listaAlumnos &LA)
{
if(LA.N>0)
{
for(int i=0;i<LA.N;i++){
printf("\n\nAlumno Nro[%d]",i+1);
mostrarAlumno(LA.pA[i]);
}
}else
printf("\nNo hay Datos");
getch();
}
void liberarListaAlumnos(listaAlumnos &LA)
{
delete [] LA.pA;
}
//Reportes
//Promedio edad del Salon
void promedioEdad(listaAlumnos &LA)
{
int suma=0;
float prom;
if(LA.N>0)
{
for(int i=0; i<LA.N; i++)
suma+=LA.pA[i].edad;
prom=(float)suma/LA.N;
printf("\n El promedio de edad es: %.2f", prom);
}
else
printf("\n No hay datos");
getch();
}
//Alumno con Mayor promedio
void mayorPromedio(listaAlumnos &LA)
{
float mayor=0.0;
if(LA.N>0)
{
for(int i=0; i<LA.N; i++)
if(LA.pA[i].prom > mayor)
mayor = LA.pA[i].prom;
printf("\n El mayor promedio es: %.2f y corresponde a:", mayor);
for(int i=0; i<LA.N; i++)
if(LA.pA[i].prom == mayor)
printf("\nNombre: %s", LA.pA[i].nombre);
}
else
printf("\n No hay datos");
getch();
}
//Alumno con Menor promedio
void menorPromedio(listaAlumnos &LA)
{
float menor=20.0;
if(LA.N>0)
{
for(int i=0; i<LA.N; i++)
if(LA.pA[i].prom < menor)
menor = LA.pA[i].prom;
printf("\n El menor promedio es: %.2f y corresponde a:", menor);
for(int i=0; i<LA.N; i++)
if(LA.pA[i].prom == menor)
printf("\nNombre: %s", LA.pA[i].nombre);
}
else
printf("\n No hay datos");
getch();
}
//Ordenar por nombre ascendente
void OrdenarAsc(listaAlumnos &LA)
{
Alumno aux;
if(LA.N>0)
{
for(int i=0; i<LA.N-1; i++)
for(int j=i+1; j<LA.N; j++)
if(strcmp(LA.pA[i].nombre, LA.pA[j].nombre) > 0)
{
aux = LA.pA[i];
LA.pA[i] = LA.pA[j];
LA.pA[j] = aux;
}
printf("\n Lista ordenada ascendente por nombre \n");
mostrarListaAlumno(LA);
}
else
printf("\n No hay datos");
getch();
}
//Ordenar por nombre descendente
void OrdenarDesc(listaAlumnos &LA)
{
Alumno aux;
if(LA.N>0)
{
for(int i=0; i<LA.N-1; i++)
for(int j=i+1; j<LA.N; j++)
if(strcmp(LA.pA[i].nombre, LA.pA[j].nombre) < 0)
{
aux = LA.pA[i];
LA.pA[i] = LA.pA[j];
LA.pA[j] = aux;
}
printf("\n Lista ordenada descendente por nombre \n");
mostrarListaAlumno(LA);
}
else
printf("\n No hay datos");
getch();
}
void menu(listaAlumnos &LA)
{
int opc;
do{
//clrscr();
printf("\n\n\n *** MENU PRINCIPAL ***\n");
printf("\n 1. Lectura");
printf("\n 2. Mostrar");
printf("\n 3. Promedio edad del Salon");
printf("\n 4. Alumno con Mayor promedio");
printf("\n 5. Alumno con Menor promedio");
printf("\n 6. Ordenar por nombre ascendente");
printf("\n 7. Ordenar por nombre descendente");
printf("\n 8. Salir");
opc=leeEntero("\n Ingrese opcion: ", 1, 8);
switch(opc)
{
case 1: leerListaAlumno(LA); break;
case 2: mostrarListaAlumno(LA); break;
case 3: promedioEdad(LA); break;
case 4: mayorPromedio(LA); break;
case 5: menorPromedio(LA); break;
case 6: OrdenarAsc(LA); break;
case 7: OrdenarDesc(LA); break;
case 8: liberarListaAlumnos(LA); break;
}
}while(opc!=8);
}
int main()
{
listaAlumnos LA;
iniciaListaAlumno(LA);
menu(LA);
return 1;
}