Dev - C++ - Cola con cadena y espacios

 
Vista:

Cola con cadena y espacios

Publicado por Angela Parra (1 intervención) el 14/08/2016 06:52:13
Buenas noches!!

Tengo todo el dia atorada en esto, en la escuela me pidieron que trabajara con queue y stacks, el problema es que no he avanzado siquiera de poder meter una cadena de texto con espacios como el nombre de una persona en una variable... el programa me salta el guardar los datos...

Lo anexo.. ya esta un poco destruido el codigo de tantas pruebas que he hecho y no logro sacar que esta mal!!

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
#include <iostream>
#include <string>
#include <stdio.h>																					/*Librerias*/
#include <stdlib.h>
#include <string>
#include <conio.h>
#include <queue>
//*****************************************
 
 
using namespace std;    // para que funcione iostream
 
//*****************************************
 
 
int main  () 							//FUNCION PRINCIPAL
{//parentesis del main
	int op,op1;
//	queue <char> c;
	std::string cola;
	//string paciente;
 
system ("color 80");  // CAMBIO DE APARIENCIA FONDO Y LETRA
 
do {//1er do
	//Menu principal
	system ("cls");
	printf("\n\t\t MENU PRINCIPAL\n\n");
    printf("\n\tElija la opcion deseada .\n\n");
    printf("\n\t\t1.MEDICINA FAMILIAR");
    printf("\n\t\t2.LABORATORIO");
    printf("\n\t\t3.ECONOMIA DEL HOGAR");
    printf("\n\t\t4.SALIR");
    printf("\n\n\t Elige una opcion:   ");
    scanf("%d",&op);
 
    switch (op)
    	{//1er switch
 
    			case 1:
 
				do {
 
				system ("cls");
				printf("\n\t\tSISTEMA DE FICHAS\n\n");
			    printf("\n\t 1. INGRESAR DATOS DEL PACIENTE");
			    printf("\n\t 2. ELIMINAR PACIENTE");
			    printf("\n\t 3. MOSTRAR LISTA DE PACIENTES");
			    printf("\n\t 4. VERIFICAR SI HAY LISTA DE PACIENTES");
			    printf("\n\t 5. SALIR	");
			 	printf("\n\n INGRESE OPCION: ");
    			scanf("%d",&op1);
 
    			switch (op1)
    				{ //de 2 do switch
    					case 1:
 
						std::cout << " Ingrese el nombre del paciente: ";
						std::getline(std::cin, cola);
 
 
						std::cout << "\n Ingresaste: " << cola;
 
    					getch();
						break;
 
					} //de 2switch
 
	 		} 	while (op1<1); //do medicina
	 		break;
		//case 1
		} //1er switch
 
	}while (op<5);	//1er do general 
} // Main
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

Cola con cadena y espacios

Publicado por dario (44 intervenciones) el 14/08/2016 15:56:21
Es tu mismo codigo pero tiene algunos arreglos, y esta mas ordenado :)
Pruebalo y me avisas. Saludos.

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
#include <iostream>
#include <string>
#include <stdio.h>																					/*Librerias*/
#include <stdlib.h>
#include <string>
#include <conio.h>
#include <queue>
//*****************************************
using namespace std;    // para que funcione iostream
//*****************************************
int main  () 							//FUNCION PRINCIPAL
{//parentesis del main
	int op,op1;
//	queue <char> c;
	string cola;
	//string paciente;
    system ("color 80");  // CAMBIO DE APARIENCIA FONDO Y LETRA
    do {//1er do
        system ("cls");
        printf("\n\t\t MENU PRINCIPAL\n\n");
        printf("\n\tElija la opcion deseada .\n\n");
        printf("\n\t\t1.MEDICINA FAMILIAR");
        printf("\n\t\t2.LABORATORIO");
        printf("\n\t\t3.ECONOMIA DEL HOGAR");
        printf("\n\t\t4.SALIR");
        printf("\n\n\t Elige una opcion:   ");
        scanf("%d",&op);
 
        switch (op)
    	{//1er switch
            case 1:
            do {
                system ("cls");
                printf("\n\t\tSISTEMA DE FICHAS\n\n");
                printf("\n\t 1. INGRESAR DATOS DEL PACIENTE");
                printf("\n\t 2. ELIMINAR PACIENTE");
                printf("\n\t 3. MOSTRAR LISTA DE PACIENTES");
                printf("\n\t 4. VERIFICAR SI HAY LISTA DE PACIENTES");
                printf("\n\t 5. SALIR	");
                printf("\n\n INGRESE OPCION: ");
                scanf("%d",&op1);
 
                switch (op1)
                { //de 2 do switch
                    case 1:
                        cout << " Ingrese el nombre del paciente: ";
                        cin >> cola; //primera correccion
						cout << "\n Ingresaste: " << cola;
    					//getch();
                        break;
				} //de 2switch
	 		} 	while (op1<1); //do medicina
	 		break;
            //case 1
        } //1er switch
    }while (op > 4);	//1er do general. Segunda correccion
} // Main
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar