[ Foro de C++ ]

Ayuda con mis llaves

19-Oct-2020 00:57
Albert Núñez
0 Respuestas

// PROGRAMA NUM. DE LA MATERIA ESTRUCTURAS Y BASES DE DATOS
  // ACTUALIZADO A AGOSTO DE 2019
  // ELABORADO POR EL PROFESOR ING. IGNACIO MONROY OSTRIA
  // PARA SIMULAR EL COMPORTAMIENTO DE LA ESTRUCTURA DE UNA  PILA
  // SE UTILIZA UN ARREGLO DE DATOS FLOTANTES
  // DOS FUNCIONES UNA PARA INSERTAR Y OTRA PARA EXTRAER UN DATO DE LA PILA
  #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 poop;
  int main(void)
  {
     int i, tope, exito;
     int poop;
     char select = ' ';
     float datoen, datosal;
     tope = -1;
     
     while(poop != '2')
 {
      cout<<"*-*-*-*-*-*-*-*-*-* Menu de programas *-*-*-*-*-*-*"<<endl;
      cout<<"1._ Programa de pilas"<<endl;
      cout<<"2._Salir"<<endl;
      cout<<"Presione un numero:";
      cin>>poop;
     
      switch (poop){

     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;
         
          }
        }





(No se puede continuar esta discusión porque tiene más de dos meses de antigüedad. Si tienes dudas parecidas, abre un nuevo hilo.)