Problema programa
Publicado por francisco (2 intervenciones) el 28/06/2014 14:45:03
/* el programa es en 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
++
hacer un programa que genere votaciones aleatoriamente. si la votacion ya existe, sumarle 1 al nodo.
si no existe, crear un nuevo nodo. buscar al ganador y mostrar cuantos votos tiene.
el programa se compila y corre. pero no hace lo que quiero. probe poniendole un par de couts para ver
si al buscar si hay un nodo con el mismo nombre que sale random se esta ejecutando correctamente,
y parece que ahi esta el problema. creo que el dato que le paso a AGREGAVOTO o a BUSCAR es
incorrecto.
se que podria hacer el programa de otras formas mas sencillas, pero es un ejercicio `para la facultad
y tengo que usar las cosas q coloque en el programa
*/
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream.h>
class NODO {
public :
char NOMBRE[20];
int VOTOS ;
NODO * SIG ;
NODO ( char * );
};
NODO::NODO( char * S )
{
strcpy (NOMBRE , S );
VOTOS = 1 ;
}
getch();
class LISTA {
private :
NODO * INICIO ;
public :
LISTA() ;
void MIRAR() ;
NODO * BUSCAR (char *) ;
void AGREGAVOTO ( char * );
void GANADOR() ;
};
LISTA :: LISTA ()
{
INICIO = NULL ;
}
void LISTA :: MIRAR ()
{
NODO * P ;
P = INICIO ;
cout << "\n\n\n" ;
while ( P ) {
printf ( "\n %-15s%10d" , P->NOMBRE , P->VOTOS ) ;
P = P->SIG ;
}
getch();
}
void LISTA::AGREGAVOTO ( char * S)
{
NODO * P ;
if ( BUSCAR(S)!= NULL){
}
else {
cout << "No Encontro" ;
P = new NODO (S);
P->SIG = INICIO ;
INICIO = P;
}
getch ();
}
NODO * LISTA :: BUSCAR ( char * S ){
NODO * P ;
while (P){
if (! (strcmp( (P->NOMBRE) , S ) ) ){
cout << "Encontro" ;
P -> VOTOS = (P -> VOTOS) +1 ;
return P;
}
else{
P=P->SIG;
}
}
return NULL;
}
void LISTA :: GANADOR () {
NODO * P , * GAN ;
int G;
G = 0;
while (P) {
if ((P->VOTOS) > G){
GAN = P ;
G = P->VOTOS ;
}
P = P-> SIG ;
}
cout << "\n EL GANADOR ES .... " << GAN->NOMBRE << "CON " << GAN -> VOTOS << " VOTOS " ;
}
char * GENERAVOTO (); /* PROTOTIPO */
void main()
{
clrscr();
char NOMBRE[20] ;
int VOTOS;
LISTA L ;
int I ;
for ( I = 0 ; I < 80 ; I++ ) {
strcpy ( NOMBRE , GENERAVOTO() ) ;
L.AGREGAVOTO ( NOMBRE );
}
L.MIRAR() ;
L.GANADOR();
cout << "\n\n\nFIN DEL PROGRAMA " ;
getch();
}
char * GENERAVOTO ()
{
char NOM[][20] = { "PEPE" , "LOLA" , "LAURA" , "CACHO" ,
"ANSELMO" , "MARIANO" , "MONICA" , "ANA" ,
"EDELMIRO" , "JOSE" , "MIRTA" , "SUSANA" ,
"FELIPE" , "ENZO" , "BETO" , "PACO" } ;
return NOM [ random(16) ] ;
}
Valora esta pregunta


0