Dev - C++ - AYUDA, LISTAS EN C++

 
Vista:
sin imagen de perfil
Val: 1
Ha aumentado su posición en 3 puestos en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

AYUDA, LISTAS EN C++

Publicado por mg (1 intervención) el 06/11/2018 16:06:43
HOLA BUENAS NECESITO UNA AYUDA EN ESTE PROGRAMA, QUIERO SABER POR QUE EN LOS MENÚS DE MATERIAS Y ESTUDIANTES , EN LA OPCIÓN 5 , HAY QUE MARCARLA VARIAS VECES PARA QUE SE DIRIJA AL MENÚ PRINCIPAL.. TAMBIÉN, SI ELIMINO UN ELEMENTO DE LA LISTA Y LUEGO AGREGO OTRO NO LO GUARDA... O A VECES NO LOS BORRA SINO EN EL ORDEN EN QUE FUERON INGRESADOS LOS DATOS... LES AGRADECERÍA MUCHO LA AYUDA, AQUÍ LES DEJO MI CÓDIGO EN DEV 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <conio.h>
#include <windows.h>
struct _Estudiante
    {
        char  nombre[20];
        char  codigomat[5];
        char  cd[10];
        int   nota;
        struct _Estudiante *siguiente;
     };
     void anadir_elemento();
     void mostrar_lista() ;
     void todoestudiante();
     void eliminar();
     int main();
     struct _Estudiante *primero, *ultimo;
 struct _Materia
    {   char codmat[5];
        char nommateria[20];
        char  profmat[20];
        struct _Materia *sig;
     };
     void anadir_materia();
     void todomaestro();
     void mostrar_materia();
     void eliminar_materia();
     int main();
     struct _Materia *prim, *ult;
 
 
void gotoxy(int x,int y)
{
      HANDLE hcon;
      hcon = GetStdHandle(STD_OUTPUT_HANDLE);
      COORD dwPos;
      dwPos.X = x;
      dwPos.Y= y;
      SetConsoleCursorPosition(hcon,dwPos);
}
void mostrar_menu()
 {    gotoxy(30,10);printf("...MENU PRINCIPAL...");
      gotoxy(30,12);printf("1.- Estudiante");
      gotoxy(30,14);printf("2.- Materias");
      gotoxy(30,16);printf("3.- Errores");
      gotoxy(30,18);printf("4.- Salir");
      gotoxy(40,22);printf("Elige una opcion: ");
      fflush(stdin);
 }
 void menuestudiante()
 {char opcion;
 system("cls");
  gotoxy(20,10);printf("...MENU ESTUDIANTES...");
      gotoxy(30,12);printf("1.- Añadir Estudiante ");
      gotoxy(30,14);printf("2.- Borrar Estudiante");
      gotoxy(30,16);printf("3.- Consultar Estudiante");
      gotoxy(30,18);printf("4.- Mostrar Estudiantes");
      gotoxy(30,20);printf("5.- Salir");
      gotoxy(30,22);printf("Elige una opción: ");
      fflush(stdin);
      do {
      	opcion=getch();
      	switch(opcion)
      	{       case '1': anadir_elemento();
            			  break;
                case '2': eliminar();
                          break;
                case '3': mostrar_lista();
                          break;
                case '4': todoestudiante();
                          break;
                case '5': int main();
                	      break;
                default:  gotoxy(30,24);printf( "Opcion no valida" );
               	 		  getch();
               	 		  system("cls");
                          menuestudiante();
                          break;
		  }
	  }while(opcion!='5');
 }
 void menudocente()
 {char opcion;
 system("cls");
  gotoxy(40,10);printf("...MENU ESTUDIANTES...");
      gotoxy(30,12);printf("1.- Añadir Materia ");
      gotoxy(30,14);printf("2.- Borrar Materia");
      gotoxy(30,16);printf("3.- Consultar Materia");
      gotoxy(30,18);printf("4.- Mostrar Materias");
      gotoxy(30,20);printf("5.- Salir");
      gotoxy(30,22);printf("Elige una opción: ");
      fflush(stdin);
      do {
      	opcion=getch();
      	switch(opcion)
      	{       case '1': anadir_materia();
            			  break;
                case '2': eliminar_materia();
                          break;
                case '3': mostrar_materia();
                          break;
                case '4': todomaestro();
                          break;
                case '5': int main();
                	      break;
                default:  gotoxy(30,24);printf( "Opcion no valida" );
               	 		  getch();
               	 		  system("cls");
                          menudocente();
                          break;
		  }
	  }while(opcion!='5');
 
 }
 void anadir_elemento()
 {
      struct _Estudiante *nuevo,*auxil;
      char fi[ ]= "q23w",qui[] = "r45t",ing[] = "y67u";
      char sp=' ';
      nuevo = (struct _Estudiante *) malloc (sizeof(struct _Estudiante));
      if (nuevo==NULL)
      {  gotoxy(40,24);printf( "No hay memoria disponible!\n");
      }
      else
      {
      	system("cls");
      	fflush(stdin);
      	auxil=primero;
      gotoxy(40,10);printf("Nuevo Registro:");fflush(stdin);
      gotoxy(30,14);printf("Cedula de Indentidad: "); fflush(stdout);
      gets(nuevo->cd);
      while (strchr(nuevo->cd,sp)!=NULL || strlen(nuevo->cd)==0){
      	system("cls");
      	gotoxy(10,10);printf("No debe colocar espacios en blanco, presione cualquier tecla e ingrese la cedula nuevamente");
      	getch();
      	system("cls");
      	gotoxy(30,14);printf("Cedula: ");
      	gets(nuevo->cd);fflush(stdout);
	  }
	  while(auxil!=NULL){
	  	do{
	  		if((strcmp(nuevo->cd,auxil->cd)==0)){
	  			strcpy(auxil->cd,nuevo->cd);
	  			gotoxy(30,14);printf("                                                      ");
	  			gotoxy(30,14);printf("Cedula repetida");
	  		getch();
	  		anadir_elemento();
			  }
		  }while((strcmp(nuevo->cd,auxil->cd)==0));
		  auxil=auxil->siguiente;
	  }
      gotoxy(30,16);printf("Nombre: "); fflush(stdout);
      gets(nuevo->nombre);fflush(stdin);
       while (strchr(nuevo->nombre,sp)!=NULL || strlen(nuevo->nombre)==0){
      	system("cls");
      	gotoxy(10,10);printf("No debe colocar espacios en blanco, presione cualquier tecla e ingrese el nombre nuevamente");
      	getch();
      	system("cls");
      	gotoxy(30,16);printf("Nombre: ");
      	gets(nuevo->nombre);fflush(stdout);
 
	  }
	  gotoxy(60,1);printf("Codigos disponibles:");
	  gotoxy(60,2);printf("Fisica: q23w");
	  gotoxy(60,3);printf("Quimica: r45t");
	  gotoxy(60,4);printf("Ingles: y67u");
      gotoxy(30,18);printf("Codigo de la materia: "); fflush(stdin);
      gets(nuevo->codigomat);
       while(strcmp(nuevo->codigomat,fi)!=0 && strcmp(nuevo->codigomat,qui)!=0  && strcmp(nuevo->codigomat,ing)!=0 )
      {gotoxy(30,18);printf("                                                          ");
	  gotoxy(30,18);printf("Codigo de materia invalido, ingreselo de nuevo: ");
	  gets(nuevo->codigomat);
	  }
      fflush(stdin);
      gotoxy(30,20);printf("Nota: "); fflush(stdout);
      scanf("%i",&nuevo->nota);
      while (nuevo->nota<0 || nuevo->nota>20){
      	gotoxy(30,20);printf("                                                          ");
      	gotoxy(30,20);printf("Error, la nota debe estar comprendida entre 0 y 20, por favor ingresela nuevamente:");
      	scanf("%i",&nuevo->nota);
	  }
 
      nuevo->siguiente = NULL;
 
      if (primero==NULL)
      {
         gotoxy(30,18);printf( "Primer elemento\n");
         primero = nuevo;
         ultimo = nuevo;
      }
      else
      {
           ultimo->siguiente = nuevo;
 
           ultimo = nuevo;
      }
      menuestudiante();
	  }
 
 }
 void todoestudiante()
 {struct _Estudiante *auxiliar, *nuevoo;
      int i;
      char ceed[10];
      i=0;
      auxiliar = primero;
      system("cls");
      nuevoo = (struct _Estudiante *) malloc (sizeof(struct _Estudiante));
      while(auxiliar!=NULL){
      	system("cls");
      	    gotoxy(15,6);printf("Nombre: %s",auxiliar->nombre);
	  		gotoxy(15,8);printf("Codigo de la materia: %s",auxiliar->codigomat);
	  		gotoxy(15,10);printf("Cedula: %s",auxiliar->cd);
	  		gotoxy(15,12);printf("Nota: %i",auxiliar->nota);
	  		i++;
	  		printf("\n");
	      	printf("\n");
	  		auxiliar = auxiliar->siguiente;
      	    system("pause");
 
	  }
	  if(i==0){
 
      	    	system("cls");
      	    	gotoxy(10,10);printf("\nLa lista esta vacia\n");
      	    	system("pause");
			  }
menuestudiante();
 
 }
 
void mostrar_lista()
{     struct _Estudiante *auxiliar;
      int i,a=0;
      char ceed[10];
      i=0;
      auxiliar = primero;
      system("cls");
      gotoxy(40,10);printf("INGRESE LA CÉDULA DE LA PERSONA A CONSULTAR:");
      fflush(stdin);
      gets(ceed);fflush(stdin);
      while (auxiliar!=NULL)
      {
	  		if ((strcmp(ceed,auxiliar->cd) == 0)){
	  		strcpy(auxiliar->cd,ceed);
	  		system("cls");
	  		gotoxy(15,2);printf("Nombre encontrado;");
	  		gotoxy(15,6);printf("Nombre: %s",auxiliar->nombre);
	  		gotoxy(15,8);printf("Codigo de la materia: %s",auxiliar->codigomat);
	  		gotoxy(15,10);printf("Cedula: %s",auxiliar->cd);
	  		gotoxy(15,12);printf("Nota: %i",auxiliar->nota);
	  		a++;
        	}
			auxiliar = auxiliar->siguiente;
			i++;
      }
      if(a==0){
      	fflush(stdin);
      	printf("\nNombre no encontrado");
	  }
		getche();
      if (i==0)
      { gotoxy(40,24);printf( "\nLa lista está vacía!!\n" );
      }
      menuestudiante();
}
void eliminar()
{     char op[3],ced[10];
      struct _Estudiante *actual,*actual2;
      actual=primero;
      system("cls");
      if(actual!=NULL)
      {  gotoxy(40,10);printf("ELIMINAR UN REGISTRO...");
         gotoxy(20,14);printf("INTRODUZCA LA CEDULA DE LA PERSONA A ELIMINAR: ");
         fflush(stdout);
         scanf("%s",ced);
         if(strcmp(ced,actual->cd)==0)
         {   primero = primero->siguiente;
             free(actual);
         }
         else
         {   while (strcmp(ced,(actual->siguiente)->cd)!=0)
             {     actual=actual->siguiente;
             }
             actual2=actual2->siguiente;
             actual->siguiente=(actual->siguiente)->siguiente;
             free(actual2);
         }
      }
      else
      {   gotoxy(20,22);printf("LISTA NO ESTA CARGADA...");
          getche();
      }
      menuestudiante();
 
}
 void anadir_materia()
 {
      struct _Materia *nuev;
      char fi[]= "q23w",qui[] = "r45t",ing[] = "y67u", mate1[] = "fisica", mate2[] = "quimica", mate3[] = "ingles";
      char sp=' ';
      nuev = (struct _Materia *) malloc (sizeof(struct _Materia));
      if (nuev==NULL)
      {  gotoxy(40,24);printf( "No hay memoria disponible!\n");
      }
      system("cls");
      gotoxy(40,10);printf("Nuevo Registro:");fflush(stdin);
      gotoxy(60,1);printf("Codigos disponibles:");
	  gotoxy(60,2);printf("Fisica: q23w");
	  gotoxy(60,3);printf("Quimica: r45t");
	  gotoxy(60,4);printf("Ingles: y67u");
      gotoxy(30,14);printf("Codigo de la materia: "); fflush(stdout);
      gets(nuev->codmat);
       while(strcmp(nuev->codmat,fi)!=0 && strcmp(nuev->codmat,qui)!=0  && strcmp(nuev->codmat,ing)!=0 )
      {gotoxy(30,14);printf("                                                          ");
	  gotoxy(30,14);printf("Ese codigo no se encuentra en el sistema,por favor ingreselo de nuevo: ");
	  gets(nuev->codmat);
	  }
      if(strcmp(nuev->codmat,fi)==0){
      	gotoxy(30,16);printf("Nombre de la materia: Fisica");
        gotoxy(30,18);printf("Profesor: "); fflush(stdout);
        gets(nuev->profmat);
	  }
	  if(strcmp(nuev->codmat,qui)==0){
	  	gotoxy(30,16);printf("Nombre de la materia: Quimica");
        gotoxy(30,18);printf("Profesor: "); fflush(stdout);
        gets(nuev->profmat);
	  }
	   if(strcmp(nuev->codmat,ing)==0){
	  	gotoxy(30,16);printf("Nombre de la materia: Ingles");
        gotoxy(30,18);printf("Profesor: "); fflush(stdout);
        gets(nuev->profmat);
	  }
 
      //gotoxy(30,16);printf("Nombre de la materia: "); fflush(stdout);
      //gets(nuev->nommateria);fflush(stdin);
 
      nuev->sig = NULL;
 
      if (prim==NULL)
      {
         gotoxy(30,18);printf( "Primer elemento\n");
         prim = nuev;
         ult = nuev;
      }
      else
      {
           ult->sig = nuev;
 
           ult = nuev;
      }
      menudocente();
 }
 void todomaestro()
{struct _Materia *aux,*nuev;
      int b=0;
      char cdmat[9];
      char fi[ ]= "q23w",qui[] = "r45t",ing[] = "y67u";
      b=0;
      aux = prim;
      system("cls");
      nuev = (struct _Materia *) malloc (sizeof(struct _Materia));
      while(aux!=NULL){
      	system("cls");
      	gotoxy(15,6);printf("Codigo de la materia: %s",aux->codmat);
	  		if (strcmp(aux->codmat,fi)==0){
	  		gotoxy(15,8);printf("Nombre de la materia: Fisica");
	  		gotoxy(15,10);printf("Profesor: %s",aux->profmat);
	  		printf("\n");
	      	printf("\n");
	  		system("pause");
			  }
	  			if (strcmp(aux->codmat,qui)==0){
	  		gotoxy(15,8);printf("Nombre de la materia: Quimica");
	  		gotoxy(15,10);printf("Profesor: %s",aux->profmat);
	  		printf("\n");
	      	printf("\n");
	  		system("pause");
			  }
		if (strcmp(aux->codmat,ing)==0){
	  		gotoxy(15,8);printf("Nombre de la materia: Ingles");
	  		gotoxy(15,10);printf("Profesor: %s",aux->profmat);
	  	    printf("\n");
	      	printf("\n");
	  		system("pause");
			  }
			aux = aux->sig;
			b++;
        	}
 
	  if (b==0) {
	  gotoxy(40,24);printf( "\nLa lista está vacía!!\n" );
	  system("pause");
      }
	  menudocente();
}
 
void mostrar_materia()
{     struct _Materia *aux;
      int b,c=0;
      char cdmat[9];
      char fi[ ]= "q23w",qui[] = "r45t",ing[] = "y67u";
      b=0;
      aux = prim;
      system("cls");
      gotoxy(60,1);printf("Codigos disponibles:");
	  gotoxy(60,2);printf("Fisica: q23w");
	  gotoxy(60,3);printf("Quimica: r45t");
	  gotoxy(60,4);printf("Ingles: y67u");
      gotoxy(40,10);printf("CONSULTAR MATERIA:");
      gets(cdmat);
      while (aux!=NULL)
      {
	  		if ((strcmp(cdmat,aux->codmat) == 0)){
	  		strcpy(aux->codmat,cdmat);
	  		system("cls");
	  		gotoxy(15,2);printf("Materia encontrada;");
	  		gotoxy(15,6);printf("Codigo de la materia: %s",aux->codmat);
	  		if (strcmp(aux->codmat,fi)==0){
	  		gotoxy(15,8);printf("Nombre de la materia: Fisica");
	  		gotoxy(15,10);printf("Profesor: %s",aux->profmat);
			  }
	  			if (strcmp(aux->codmat,qui)==0){
	  		gotoxy(15,8);printf("Nombre de la materia: Quimica");
	  		gotoxy(15,10);printf("Profesor: %s",aux->profmat);
			  }
		if (strcmp(aux->codmat,ing)==0){
	  		gotoxy(15,8);printf("Nombre de la materia: Ingles");
	  		gotoxy(15,10);printf("Profesor: %s",aux->profmat);
			  }
	  		c++;
        	}
			aux = aux->sig;
			b++;
      }
      if(c==0){
      	fflush(stdin);
      	printf("\nDatos no encontrados");
	  }
		getche();
      if (b==0)
      { gotoxy(40,24);printf( "\nLa lista está vacía!!\n" );
      }
      menudocente();
}
void eliminar_materia()
{     char op[3],cdm[9];
      struct _Materia *act,*act2;
      act=prim;
      system("cls");
      if(act!=NULL)
      {  gotoxy(40,10);printf("ELIMINAR UN REGISTRO...");
      gotoxy(60,1);printf("Codigos disponibles:");
	  gotoxy(60,2);printf("Fisica: q23w");
	  gotoxy(60,3);printf("Quimica: r45t");
	  gotoxy(60,4);printf("Ingles: y67u");
         gotoxy(20,14);printf("Materia a eliminar: ");
         fflush(stdout);
         gets(cdm);
         if(strcmp(cdm,act->codmat)==0)
         {   prim = prim->sig;
             free(act);
         }
         else
         {   while ( strcmp(cdm,(act->sig)->codmat)!=0)
             {     act=act->sig;
             }
             act2=act2->sig;
             act->sig=(act->sig)->sig;
             free(act2);
         }
      }
      else
      {   gotoxy(20,22);printf("LISTA NO ESTA CARGADA...");
          getche();
      }
      menudocente();
}
int main()
{    char opcion;
     do
     {
       system("cls");
       mostrar_menu();
       opcion = getch();
       switch ( opcion )
            {   case '1': menuestudiante();
            			  break;
                case '2': menudocente();
                          break;
                case '3':
                          break;
                case '4': exit( 1 );
                default:  gotoxy(30,24);printf( "Opcion no valida" );
               	 		  getch();
                          break;
             }
     } while (opcion!='4');
 }
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder