Dev - C++ - Tengo un error en la la ultima fila la por que?

 
Vista:
Imágen de perfil de Seb

Tengo un error en la la ultima fila la por que?

Publicado por Seb (9 intervenciones) el 07/06/2022 03:47:07
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
#include<conio.h>
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<stack>
#include<locale.h>
 
using namespace std;
 
class Contacto{
    public :
        string nombre;
        string apellido;
        string telefono;
        string direccion;
        string habitacion;
        string fecha_ingreso;
        string fecha_salida;
 
        Contacto(){
 
        }
 
        Contacto agregar(){
            Contacto contacto;
            cout<<"==============SISTEMA DE ALQUILER==============="<<endl;
            cout<<"Nombre: ";
            fflush(stdin);
            getline(cin,contacto.nombre);
            cout<<"Apellido: ";
            fflush(stdin);
            getline(cin,contacto.apellido);
            cout<<"Telefono: ";
            fflush(stdin);
            getline(cin,contacto.telefono);
            cout<<"Dirección: ";
            fflush(stdin);
            getline(cin,contacto.direccion);
            cout<<"Habitacion: ";
            fflush(stdin);
            getline(cin,contacto.habitacion);
            cout<<"Fecha de Ingreso: ";
            fflush(stdin);
            getline(cin,contacto.fecha_ingreso);
            cout<<"Fecha de Salida: ";
            fflush(stdin);
            getline(cin,contacto.fecha_salida);
            cout<<"=============================================="<<endl;
 
            return contacto;
 
        }
 
        void imprimir(){
            cout<<"================INFORMACION DEL HUESPED=================="<<endl;
            cout<<"Nombre: "<<nombre<<endl;
            cout<<"Apellido: "<<apellido<<endl;
            cout<<"Teléfono: "<<telefono<<endl;
            cout<<"Direccion: "<<direccion<<endl;
            cout<<"Habitacion: "<<habitacion<<endl;
            cout<<"Fecha de Ingreso: "<<fecha_ingreso<<endl;
            cout<<"Fecha de Salida: "<<fecha_salida<<endl;
        }
 };
 class Nodo{
    public:
        Contacto dato;
        Nodo *SigPtr;
        Nodo (Contacto n){
            dato = n;
            SigPtr = 0;
        }
 };
 
 class Lista{
    public:
        Nodo *PrimeroPtr;
        Nodo *UltimoPtr;
        stack<Contacto> papelera;
 
        Lista(){
            PrimeroPtr = UltimoPtr = 0;
        }
 
        ~Lista(){
            while (!estaVacia()){
            }
        }
 
        bool estaVacia(){
                return PrimeroPtr == 0;
        }
 
        void insertarFrentePrimera(Contacto c){
            Nodo *newPtr = new Nodo(c);
 
            if (estaVacia()){
                PrimeroPtr = UltimoPtr = newPtr;
            }else{
                newPtr->SigPtr = PrimeroPtr;
                PrimeroPtr = newPtr;
            }
        }
 
        void insertarFrente (Contacto c){
            if (validar(c) == true){
                getch();
            }else{
                Nodo *newPtr = new Nodo(c);
 
            if (estaVacia()){
                PrimeroPtr = UltimoPtr = newPtr;
            }else{
                newPtr->SigPtr = PrimeroPtr;
                PrimeroPtr = newPtr;
            }
            }
        }
 
        Contacto editarContacto(string nombre){
            Nodo *actualPtr;
            Contacto c =PrimeroPtr->dato;
            Contacto val, b;
            int cont = 0;
            actualPtr = PrimeroPtr;
 
            while(actualPtr != 0&& cont == 0){
                if(actualPtr->dato.nombre == nombre){
                    b = actualPtr ->dato;
                    PrimeroPtr->dato = b;
                    actualPtr->dato = c;
                    cont = 1;
                    return b;
                }else{
                    actualPtr = actualPtr->SigPtr;
                }
                actualPtr == 0;
            }
            if(cont > 0){
 
            }else{
                cout<<"El contacto no fue encontrado"<<endl;
            }
        }
 
        Contacto buscarContacto (){
            Nodo *actualPtr;
            Contacto val;
            string nom;
            string nombre,apellido,telefono, direccion,habitacion,fecha_ingreso,fecha_salida;
            int cont = 0;
            actualPtr = PrimeroPtr;
 
            cout<<"Nombre del contacto que desea buscar: ";
            fflush(stdin);
            getline (cin,nom);
 
            while(actualPtr != 0&& cont == 0){
                if (actualPtr->dato.nombre == nom){
 
                nombre = actualPtr ->dato.nombre;
                apellido = actualPtr->dato.apellido;
                telefono = actualPtr->dato.telefono;
                direccion = actualPtr->dato.direccion;
                habitacion = actualPtr->dato.habitacion;
                fecha_ingreso = actualPtr->dato.fecha_ingreso;
                fecha_salida = actualPtr->dato.fecha_salida;
 
                val.nombre=nombre;
                val.apellido=apellido;
                val.telefono=telefono;
                val.direccion=direccion;
                val.habitacion=habitacion;
                val.fecha_ingreso=fecha_ingreso;
                val.fecha_salida=fecha_salida;
 
                return val;
                cont = 1;
                }else{
                    actualPtr = actualPtr->SigPtr;
                }
                actualPtr == 0;
            }
            if(cont > 0){
 
            }else{
                cout<<"El contacto no fue encontrado"<<endl;
            }
        }
 
 
        bool validar(Contacto val){
            Nodo *actualPtr;
            int cont = 0;
            actualPtr = PrimeroPtr;
 
            while(actualPtr != 0&& cont == 0){
                if (actualPtr->dato.nombre == val.nombre){
                    cout<<"El contacto ya existe, por lo tanto no se agrego"<<endl;
                    cont = 1;
                    return true;
                }else{
                    actualPtr = actualPtr->SigPtr;
                }
                actualPtr == 0;
            }
            if(cont > 0){
 
            }else{
                return false;
            }
        }
 
 void insertarFrente (Lista &list){
    system("cls");
    cout<<"--Ingresando--"<<endl;
    Contacto c;
    list.insertarFrente(c.agregar());
    getch();
 }
 void editarContacto(Lista &list){
    string nom;
    Contacto aux;
    int cont=0;
    int opc = 0;
    string nombre,apellido,telefono,direccion,habitacion,fecha_ingreso,fecha_salida;
    std :: ofstream PrimerArchivo("RegistroContacto.txt", std :: ios :: out);
 
    system("cls");
 
    cout<<"\t\nNombre del contacto a editar: ";
    cin.ignore();
    getline (cin,nom);
    aux = list.editarContacto(nom);
    cout<<endl;
 
            cout<<"==========DATOS DEL CONTACTO============="<<endl;
            cout<<"===================================="<<endl;
            cout<<"1.Nombre: "<<aux.nombre<<endl;
            cout<<"2.Apellido: "<<aux.apellido<<endl;
            cout<<"3.telefono: "<<aux.telefono<<endl;
            cout<<"4.direccion: "<<aux.direccion<<endl;
            cout<<"5.habitacion: "<<aux.habitacion<<endl;
            cout<<"6.fecha de ingreso: "<<aux.fecha_ingreso<<endl;
            cout<<"7.fecha de salida: "<<aux.fecha_salida<<endl;
            cout<<"====================================="<<endl;
            cout<<endl;
            cout<<"Opción a editar: ";
            cin>>opc;
            cout<<endl;
        if (opc == 1){
            cout<<"Ingrese el nuevo nombre: ";
            cin.ignore();
            getline (cin,nombre);
            aux.nombre.clear();
            aux.nombre=nombre;
        }
        if(opc == 2){
            cout<<"Ingrese el nuevo apellido: ";
            cin.ignore();
            getline (cin,nombre);
            aux.nombre.clear();
            aux.nombre=nombre;
        }
        if(opc == 3){
            cout<<"Ingrese el nuevo telefono: ";
            cin.ignore();
            getline (cin,telefono);
            aux.telefono.clear();
            aux.telefono=telefono;
        }
        if(opc == 4){
            cout<<"Ingrese la nueva direccion: ";
            cin.ignore();
            getline (cin,direccion);
            aux.direccion.clear();
            aux.direccion=direccion;
        }
        if(opc == 5){
            cout<<"Ingrese la nueva habitacion: ";
            cin.ignore();
            getline (cin,habitacion);
            aux.habitacion.clear();
            aux.habitacion=habitacion;
        }
        if(opc == 6){
            cout<<"Ingrese la nueva fecha de ingreso: ";
            cin.ignore();
            getline (cin,fecha_ingreso);
            aux.fecha_ingreso.clear();
            aux.fecha_ingreso=fecha_ingreso;
        }
        if(opc == 7){
            cout<<"Ingrese la nueva fecha de salida: ";
            cin.ignore();
            getline (cin,fecha_salida);
            aux.fecha_salida.clear();
            aux.fecha_salida=fecha_salida;
        }
 
 }
 
 void buscarContacto(Lista &list){
     system("cls");
     list.buscarContacto().imprimir();
     getch();
     getch();
 }
 
 
 void actualizar(Lista &list){
     Contacto c;
     ifstream archivo("RegistroContacto.txt");
 
     int aux=0;
     while (archivo) {
         string Lineadetexto;
         if (!getline(archivo, Lineadetexto)) break;
         istringstream StreamLineadetexto( Lineadetexto);
 
         while (StreamLineadetexto)
         {
             string cadena;
             if (!getline(StreamLineadetexto, cadena, ','))
                break;
 
                if(aux==0){
                    c.nombre=cadena;
                }
                if(aux==1){
                    c.apellido=cadena;
                }
                if(aux==2){
                    c.telefono=cadena;
                }
                if(aux==3){
                    c.direccion=cadena;
                }
                if(aux==4){
                    c.habitacion=cadena;
                }
                if(aux==5){
                    c.fecha_ingreso=cadena;
                }
                if(aux==6){
                    c.fecha_salida=cadena;
                }
                aux++;
         }
         list.insertarFrentePrimera(c);
         aux=0;
     }
     if (!archivo.eof())
     {
         cout<<"El contacto no fue encontrado"<<endl;
     }
 }
 
 void mostrarDirectorio(Lista &list){
     system("cls");
     cout<<"=========ELEMENTOS DE LA LISTA=========="<<endl;
     if(list.PrimeroPtr==0){
         cout<<"No hay contacto en la agenda!"<<endl;
     }
     getch();
 }
 
int main(){//Aqui se hace el llamado a todas las funciones
 //se coloca un login común
 
 
        Lista lista = Lista();
        actualizar(lista);
 
    system("cls");
    setlocale(LC_ALL,"");
    int op;
 
            cout<<"--------------------------------------------------"<<endl;
            cout<<"============INICIO SECCION CON EXITO=============="<<endl;
            cout<<"--------------------------------------------------"<<endl;
 
                cin.get();
                    do{
            system("cls");
            cout<<"==============SISTEMA DE ALQUILER==============="<<endl;
            cout<<"------------------------------------------------"<<endl;
            cout<<"=============MENU PRINCIPAL====================="<<endl;
            cout<<"1.agregar cliente"<<endl;
            cout<<"2.Editar Cliente"<<endl;
            cout<<"3.Buscar cliente"<<endl;
            cout<<"4.Mostrar Directorio en general"<<endl;
            cout<<"5.Salir"<<endl;
            cout<<"--------------------------------------------------"<<endl;
            cout<<"Opción: ";
            cin>>op;
 
            switch(op){//swith de las funciones
                case 1:
                insertarFrente(lista);
                system("pause");
                break;
                case 2:
                editarContacto(lista);
                system("pause");
                break;
                case 3:
                buscarContacto(lista);
                system("pause");
                break;
                case 4:
                mostrarDirectorio(lista);
                system("pause");
                case 5:
                exit(1);
                break;
            }
            system("cls");
                 }while(op!=6);
 
            }
return 0;
};
error
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