Necesito ayuda con un menú
Publicado por Albert (6 intervenciones) el 20/10/2020 18:00:51
La cosa es que soy nuevo en c++ y mi Profesor me pidió que convierta a función un programa y que le agregue un menú como el que anexaré a continuación:
El programa es este:
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
#include <iomanip>
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <stdlib.h>
using namespace std;
int insertar( float datoen, int *tope);
int extraer (float *datosal, int *tope);
/* DEFINICION DE VARIABLES */
#define limite 20
float pila [ limite];
int main(void)
{
int i, tope, exito;
char select = ' ';
float datoen, datosal;
tope = -1;
while (select != '4')
{
system("cls");
cout <<endl<< " PROGRAMA QUE SIMULA UNA PILA UTILIZANDO ARREGLOS "<<endl;
cout << " SELECCIONE LA OPERACION CON PILAS " << endl<< endl;
cout << " INSERTAR UN DATO EN LA PILA (1)" << endl;
cout << " EXTRAER UN DATO DE LA PILA (2)" << endl;
cout << " DESPLEGAR EL ESTADO DE LA PILA (3)" << endl;
cout << " SALIR DEL PROGRAMA (4)" << endl;
cout << " OPCION SELECCIONADA?? " ;
cin >> select ;
switch(select)
{
case '1': //inserción de un dato en la pila
cout << "\n \n TECLEA EL DATO QUE SERA INSERTADO EN LA PILA : ";
cin >> datoen;
exito =insertar(datoen, &tope);
if( exito == 0) cout <<" \n !!! LA INSERCCION FUE CORRECTA !!!";
system ("pause") ; break;
case '2': // extracción de un dato de la pila
exito = extraer (&datosal,&tope);
if(exito == 0){setprecision(14.5); cout << "DATO EXTRAIDO = " << datosal;}
cout << endl;
system ("pause");
break;
case '3': // desplega el arreglo que contiene la pila
system ("cls");
cout <<"\n EL ESTADO DE LA PILA ES EL SIGUIENTE ";
cout <<endl<< " POSICION VALOR"<< endl;
if (tope < 0)
{ cout <<"\n !!!! LA PILA ESTA VACIA !!!!"<<endl;
system("pause"); break;}
for(i = tope; i>=0 ; i--)printf("\n %4i %12.4f",i,pila[i]);
cout << endl; system ("pause");
break;
case '4': // opción de salida
cout << endl<< " !!! HASTA PRONTO !!!! " ;
goto fin;
default:
{cout << endl<< " *******ERROR LA OPCION: " << select
<< " no existe ****"; getch(); break; }
}
}
fin:
return 0; system("pause"); // termina función principal
}
int insertar (float dato, int *tope)
{
if(*tope >= (limite-1))
{
cout << "\n LA PILA ESTA LLENA, NO SE PUDO INSERTAR EL NUEVO DATO";
return -1;
}
(*tope)++;
pila[(*tope)]= dato;
return 0;
}
int extraer( float *dato, int *tope)
{
if(*tope < 0)
{
cout <<endl<< "\n LA PILA ESTA VACIA, NO SE PUEDEN EXTRAER ELEMENTOS ";
return -1;
}
(*dato) = pila[ (*tope)];
pila [(*tope)] = 0;
(*tope)--;
return 0;
}
Valora esta pregunta
0