Necesito ayuda con un menú
Publicado por Blacky (6 intervenciones) el 20/10/2020 18:04:20
Necesito convertir este programa a función y agregarle un pequeño menú antes del menú que ya tiene que diga :
1._ Colas
2._ Salir del programa
El programa es este:
1._ Colas
2._ Salir del programa
El programa es este:
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
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <iomanip>
#include <string.h>
int insertar( float datoen, int *tope );
int extraer (float *datosal, int *frente, int *tope);
int depurar(int *tope, int *frente);
/* DEFINICION DE VARIABLES */
int i,n,m, limite;
#define limitet 30
float cola [ limitet];
using namespace std;
int main()
{
int i, posi, exito, frente;
char select;
float datoen, datosal;
posi = -1; frente = -1;
cout << " DE QUE TAMAÑO QUIERES EL ARREGLO EL DIA DE HOY (maximo 30)";
cin >> limite;
inicio:
cout.setf(ios::fixed);
system("CLS");
cout <<"\n PROGRAMA QUE SIMULA UNA COLA UTILIZANDO ARREGLOS \n ";
cout <<" SELECCIONE LA OPERACION QUE DESEA \n\n";
cout <<" INSERTAR UN DATO (1) \n";
cout <<" EXTRAER UN DATO (2) \n";
cout <<" DESPLEGAR LOS DATOS (3) \n";
cout <<" DEPURAR EL ARREGLO (4) \n";
cout <<" SALIR DEL PROGRAMA (5) \n";
cout <<" OPCION SELECCIONADA??";
select = getch();
switch(select)
{
case '1': //inserción de un dato en la cola
if(frente > 0 && posi==(limite-1)) depurar(&posi,&frente);
exito =insertar(datoen, &posi);
if( exito == 0) cout << " \n !!! LA INSERCCION FUE CORRECTA !!!";
if(frente==-1) frente =0;
getche();
break;
case '2': // extracción de un dato de la cola
exito = extraer (&datosal, &frente, &posi);
if(exito == 0)
{
cout<< "\n\n EL DATO EXTRAIDO ES: "
<< setprecision (4) <<datosal;
getche();
}
break;
case '3': // desplega el arreglo que contiene la cola
system ("cls");
cout << " ESTRUCTURA TIPO COLA "<<endl;
cout <<"\n EL ESTADO DEL ARREGLO ES EL SIGUIENTE \n ";
cout <<endl<< " POSICION" << " VALOR \n";
if (posi < frente || frente <0 )
{
cout << "\n !!!! LA COLA ESTA VACIA \n!!!!" ;
system("pause");
break;
}
for(i = posi; i>= frente ; i--)
cout <<"\n "<< i << " "
<<setprecision(4)<<cola[i];
getche();
break;
case '4': // opción para depurar el arreglo
depurar(&posi,&frente);
getche();
break;
case '5': // opción de salida
cout << " \n !!! HASTA PRONTO !!!! " ;
getche();
return 0; // salida del programa
default :
cout << " \n ******error en numero de opcion******"<<endl;
system ("pause"); break;
}
goto inicio;
} // termina función principal
int insertar (float dato, int *tope)
{
if(*tope >= (limite-1))
{
cout << "\n EL ARREGLO ESTA LLENO, NO SE PUEDE INSERTAR EL DATO";
return -1;
}
cout<< "\n \n TECLEA EL DATO QUE SERA INSERTADO : ";
cin >> dato;
(*tope)++;
cola[*tope]= dato;
return 0;
} // FIN DE FUNCION INSERTAR
int depurar(int *tope, int *frente)
{
int i,j;
j=0;
for (i=(*frente); i<= (*tope); i++ )
{ cola [j] = cola [i] ;
j++;
}
(*tope) = (*tope)- (*frente);
(*frente) = 0;
cout <<"\n EL ARREGLO HA SIDO DEPURADO; SE OCUPARON LOCALIDADES ";
cout <<"\n VACIAS POR LA EXTRACCIÒN DE DATOS DE LA COLA";
return 0;
} // FIN DE FUNCION DEPURAR
int extraer( float *dato, int *frente, int *tope)
{
if(*tope < (*frente) ||(*frente)<0 )
{
cout <<"\n EL ARREGLO ESTA VACIO, NO SE PUEDEN EXTRAER DATOS ";
getch(); return -1;
}
(*dato) = cola[ (*frente)];
cola [(*frente)] = 0;
(*frente)++;
return 0;
}
Valora esta pregunta


0