Herramientas Informaticas

Mes: junio 2012 Página 1 de 2

Simulación en C++

SIMULACION EN C++

DESCARGAR CODIGO FUENTE COMPLETO

DESCARGAR CABECERA
Este archivo va en la carpeta INCLUDE

 
SIMULA.CPP
 
   1: #include 

   2: #include 

   3: #include 

   4:  

   5: typedef struct simulacion

   6: {

   7: int tiemposimulacion;

   8: int tiemposervicio;

   9: int probabilidad;

  10:  

  11: int relog;

  12:  

  13: int cajero;

  14:  

  15: int tiemposerviciototal;

  16: int clientesatendidos;

  17: };

  18:  

  19: void parametros(simulacion *p);

  20: int aleatorio(simulacion *a)

  21: {

  22: int x;

  23: float y;

  24: randomize();

  25: y=random(100);

  26: y=y*3.1416;

  27: x=y;

  28: y=y-x;

  29: y=y*100;

  30: if(a->probabilidad<=y)

  31:     {

  32:     return(1);

  33:     }

  34: else

  35:     {

  36:     return(0);

  37:     }

  38: }

  39:  

  40:  

  41: void llegacliente(cola *c)

  42: {

  43: if(aleatorio<=aleatorio)

  44:     {

  45:     push(c);

  46:     }

  47: }

  48:  

  49: void enmarcha(simulacion *e, cola *c)

  50: {

  51: inicializarcola(c);

  52: e->relog=0;

  53: e->cajero=0;

  54: e->clientesatendidos=0;

  55: e->tiemposerviciototal=0;

  56: int v=0;

  57: clrscr();

  58:  

  59: while(e->relog!=e->tiemposimulacion+1)

  60:     {

  61:     clrscr();

  62:     for(int v=0; v<max; v++)

  63:         {

  64:         *(c->cola+v)=*(c->cola+v)+1;

  65:         }

  66:     gotoxy(1,1);    cout<<"Minutos trancurridos: "<relog;

  67:     (e->relog)++;

  68:  

  69:     gotoxy(40,1);    cout<<"Probabilidad "<probabilidad;

  70:  

  71:     gotoxy(1,20);    cout<<"Clientes atendidos "<clientesatendidos;

  72:  

  73:     gotoxy(40,20);    cout<<"Tiempo de espera total "<tiemposerviciototal;

  74:     if(aleatorio(e)==0)

  75:         {

  76:         insertar(c);

  77:         for(int v=0; v<30; v++)

  78:             {

  79:             gotoxy(1,3);    cout<<"Ha llegado un cliente";

  80:             }

  81:         }

  82:  

  83:     if(e->cajero==0)

  84:         {

  85:         gotoxy(1,4);    borrar(c);

  86:         e->cajero=e->tiemposervicio;

  87:         }

  88:     (e->cajero)--;

  89:  

  90:  

  91:     if(e->cajero==0 && colavacia(c)==0)

  92:         {

  93:         (e->clientesatendidos)++;

  94:         e->tiemposerviciototal=e->tiemposerviciototal+*(c->cola+c->frente);

  95:         }

  96:  

  97:     getch();

  98:     }

  99: }

 100:  

 101:  

 102:  

 103: main()

 104: {

 105: clrscr();

 106: cola fila;

 107: tipodatocola colas[max];

 108: fila.cola=&colas[0];

 109:  

 110: simulacion simula;

 111: parametros(&simula);

 112: enmarcha(&simula, &fila);

 113: }

 114:  

 115:  

 116:  

 117:  

 118: void parametros(simulacion *p)

 119: {

 120: cout<<"Tiempo de duracion de la simulacion: ";            cin>>p->tiemposimulacion;

 121: cout<<"Tiempo limite del servicio del servidor: ";        cin>>p->tiemposervicio;

 122: cout<<"probabilidad de llegada de un cliente en un minuto ";    cin>>p->probabilidad;

 123: }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

 

COLAS.H

   1: //COLAS

   2: //JULIO CESAR LEYVA RODRIGUEZ

   3: #include 

   4: #include 

   5: #define max 100

   6: typedef int tipodatocola;

   7: typedef struct cola

   8: {

   9: tipodatocola *cola;                             

  10: int frente;

  11: int final;

  12: int contador;

  13: };

  14:  

  15: //INICIALIZAR COLA

  16: void inicializarcola(cola *inicializar)

  17: {

  18: inicializar->frente=max-1;

  19: inicializar->final=-1;

  20: gotoxy(40,5);    cout<<"SE HA INICIALIZADO LA COLA";

  21: }

  22:  

  23: //COLA LLENA

  24: int colallena(cola *llena)

  25: {

  26: if(llena->final==llena->frente-1)

  27:     {

  28:     return(1);

  29:     }

  30: else

  31:     {

  32:     return(0);

  33:     }

  34: }

  35:  

  36: //COLA VACIA

  37: int colavacia(cola *v)

  38: {

  39: if((v->frente==v->final) || (v->final==-1 && v->frente==max-1))

  40:     {

  41:         return(1);

  42:     }

  43: else

  44:     {

  45:     return(0);

  46:         }

  47: }

  48:  

  49: void push(cola *z)

  50: {

  51: if(z->final==max-1)

  52:     {                       

  53:     (z->final)=-1;

  54:     *(z->cola+z->final+1)=0;

  55:     }          

  56: else

  57:     {                                                                      

  58:     (z->final)++;

  59:         *(z->cola+z->final)=0;

  60:         }

  61: }

  62:  

  63: void insertar(cola *i)

  64: {

  65: tipodatocola cliente;

  66: if(colallena(i)==1)

  67:     {            

  68:     cout<<"La cola esta llena";

  69:     }

  70: else

  71:     {

  72:     push(i);

  73:     }

  74: }        

  75:  

  76: tipodatocola pop(cola *c)

  77: {

  78: tipodatocola dato;

  79: if(c->frente==max-1 && c->final>-1)

  80:     {       

  81:     c->frente=0;

  82:     dato=*(c->cola+c->frente);

  83:     return(dato);

  84:     }

  85: else                             

  86:     {

  87:     c->frente=c->frente+1;

  88:     dato=*(c->frente+c->cola);

  89:     return(dato);

  90:         }

  91: }

  92:  

  93: void borrar(cola *borrar)

  94: {

  95: if(colavacia(borrar)==1)

  96:     {

  97:     cout<<"La cola esta vacia";

  98:     }

  99: else

 100:     {

 101:     cout<<"El cliente a pasado al cajero con "<<pop(borrar)<<" minutos de espera";

 102:     }

 103: }

 104:  

 105: void visualizarcola(cola *v)

 106: {

 107: if(colavacia(v)==1)

 108:     {

 109:     cout<<"No hay datos";

 110:     }

 111: else

 112:     {

 113:     for(int x=v->frente; xfinal; x++)

 114:         {

 115:         if(x==max-1)

 116:             {

 117:             x=0;

 118:                         }

 119:         gotoxy(x+20,25);    cout<cola+1;

 120:         }

 121:         }

 122:  

 123: }    

 124:       

 125:  

 126:  

 127:  

 128: //MENU

 129: void menu(cola *menu) 

 130: {                                                      

 131: int op;

 132: do

 133:  

 134:     {

 135:     clrscr();

 136:     cout<<"Frente "<frente;

 137:         cout<<"nFinal "<final;

 138:         cout<<"nCola "<cola+menu->frente);

 139:      gotoxy(1,5);    cout<<"MENU";

 140:     gotoxy(1,6);    cout<<"1. INICIALIZAR";

 141:     gotoxy(1,7);    cout<<"2. INSERTAR";

 142:     gotoxy(1,8);    cout<<"3. BORRAR";

 143:     gotoxy(1,9);    cout<<"ELIGA UNA OPCION [   ]";

 144:     gotoxy(20,9);    cin>>op;

 145:     switch(op)

 146:         {

 147:         case 1:

 148:             inicializarcola(menu);

 149:             getch();

 150:             break;

 151:         case 2:

 152:             insertar(menu);

 153:             getch();

 154:             break;

 155:         case 3:

 156:                 borrar(menu);

 157:             getch();

 158:                         break;

 159:         case 4:

 160:             visualizarcola(menu);

 161:             getch();

 162:                         break;

 163:         }

 164:     }

 165:     while(op!=5);

 166: }

 167:  

Pilas en C++

   1: //PILAS

   2:  

   3: #include 

   4: #include 

   5: #include 

   6: #define max 5

   7:  

   8: typedef int tipodatopila;

   9:                          

  10: tipodatopila pila[max];

  11: int tope;

  12:  

  13: void visualizarpila(tipodatopila *pila);

  14: void inicializarpila(int *tope);

  15: void menu(int *tope, tipodatopila *pila);

  16: int pilavacia(int *tope);

  17: int pilallena(int *tope);

  18: void push(int *tope, tipodatopila *pila, tipodatopila *dato);

  19: void alta(int *tope);

  20: tipodatopila pop(int *tope, tipodatopila *pila)

  21: {

  22: tipodatopila b=*(tope)+*(pila);

  23: *(tope)=*(tope)-1;

  24: return(b);

  25:  

  26: }

  27: void baja(int *tope, tipodatopila *pila)

  28: {

  29: if(pilavacia(tope)==1)

  30:     {

  31:     gotoxy(40,4);    cout<<"LA PILA ESTA VACIA";

  32:     }                              

  33: else

  34:     {

  35:     gotoxy(40,4);    cout<<"EL DATO ELIMINADO FUE "<<pop(tope,pila);

  36:     }

  37: }

  38:                   

  39:  

  40: main()

  41: {

  42: menu(&tope,&pila[0]);

  43: }

  44:  

  45: void menu(int *tope, tipodatopila *pila)

  46: {

  47: int op;

  48:  

  49: do

  50:     {

  51:         clrscr();

  52:         gotoxy(10,10);    visualizarpila(pila);

  53:     gotoxy(30,2);     cout<<"PILAS";

  54:     gotoxy(10,4);     cout<<"1. INICIALIZAR PILA";

  55:     gotoxy(10,5);     cout<<"2. ALTA";

  56:     gotoxy(10,6);     cout<<"3. BAJA";

  57:     gotoxy(10,7);     cout<<"4. SALIR";

  58:     gotoxy(10,8);     cout<<"ELIGA UNA OPCION [   ]";

  59:     gotoxy(29,8);    cin>>op;

  60:     switch(op)

  61:         {

  62:         case 1:

  63:             inicializarpila(tope);

  64:             break;

  65:            case 2:

  66:             alta(tope);

  67:                         getch();

  68:             break;

  69:         case 3:

  70:                         baja(tope,pila);

  71:             getch();

  72:             break;

  73:         case 4:

  74:                         clrscr();

  75:             cout<<"ADIOS ;D";

  76:             getch;

  77:             break;                      

  78:  

  79:         default:

  80:             cout<<"HAZ TECLADO UNA LETRA";

  81:                         break;   

  82:  

  83:         }

  84:                 

  85:     }while(op!=4); 

  86:  

  87: }

  88:  

  89:  

  90:  

  91:  

  92:  

  93:  

  94:  

  95:  

  96:  

  97:  

  98:  

  99:  

 100:  

 101:  

 102:  

 103:  

 104:  

 105:  

 106:  

 107:  

 108:  

 109: int pilallena(int *tope)

 110: {

 111: if(*(tope)==max-1)

 112:     {

 113:     return(1);

 114:     }

 115: else

 116:     {

 117:     return(0);

 118:     }

 119: }

 120:  

 121: //Pila vacia

 122: int pilavacia(int *tope)

 123: {

 124: if(*(tope)==-1)

 125:     {

 126:     return(1);

 127:     }

 128: else

 129:     {

 130:     return(0);

 131:     }

 132: }

 133:  

 134:  

 135:  

 136:  

 137:  

 138:  

 139:  

 140: //Funcion inicializar pila

 141: void inicializarpila(int *tope)

 142: {

 143: *(tope)=-1;

 144: }

 145:  

 146: //Visualizar pila

 147: void visualizarpila(tipodatopila *pila)

 148: {

 149: for(int f=0; f<max; f++)

 150:     {

 151:     cout<<"n"<<*(pila+f);

 152:     }

 153: }

 154:  

 155: void push(int *tope, tipodatopila *pila, tipodatopila *dato)

 156: {

 157: *(tope)=*(tope)+1;

 158: *(pila+*tope)=*dato;

 159: }

 160:  

 161: void alta(int *tope)

 162: {

 163: tipodatopila dato;

 164: if(pilallena(tope)==1)

 165:     {

 166:     gotoxy(40,4);    cout<<"LA PILA ESTA LLENA";

 167:     }

 168: else

 169:     {

 170:     gotoxy(40,5);    cout<<"INSERTE EL DATO ";    cin>>dato;

 171:     gotoxy(40,6);    push(tope,pila,&dato);

 172:     }

 173: }

 

Segundo examen C++

DESCARGAR CODIGO PRINCIPAL

DESCARGAR CABECERA DE CODIGO
Este archivo lo colocaras en la carpeta include, se necesita para correr el programa

EXAMEN2.CPP

   1: //EXAMEN 2 JULIO CESAR LEYVA RODRIGUEZ

   2:  

   3: #include 

   4: #include 

   5: #include 

   6:  

   7: #define renglones 5

   8: #define columnas 5

   9:  

  10: int arreglo[renglones][columnas];

  11: #include 

  12:  

  13:  

  14: void main()

  15: {

  16: inicializar(&arreglo[0][0]);

  17: numerosaleatorios(&arreglo[0][0]);

  18: mostrararreglo();

  19: sumardiagonales(&arreglo[0][0]);

  20: sumardiagonalesinvertida(&arreglo[0][0]);

  21: }

  22:  

FJULIO.H

   1: //FUNCIONES JULIO CESAR LEYVA RODRIGUEZ

   2: //MARTES 29 DE SEPTIEMBRE DEL 2009

   3:  

   4:  

   5: //SUMAR DIAGONALES DE UN ARREGLO

   6:  

   7: void sumardiagonales(int *d)

   8: {

   9: int c=0;

  10: for(int x=0; x<renglones; x++)

  11:     {

  12:     cout<<"n"<<*(d+x+c);

  13:     c=c+columnas;

  14:  

  15:     }

  16: }                                                     

  17:      

  18:  

  19: //SUMAR DIAGONALES DE UN ARREGLO INVERTIDO

  20:  

  21: void sumardiagonalesinvertida(int *d)

  22: {

  23: int c=columnas-1;

  24: for(int x=0; x<renglones; x++)

  25:     {

  26:     cout<<"n t"<<*(d+c);

  27:     c=c+columnas-1;

  28:                       

  29:     }              

  30: } 

  31:  

  32: //MUESTRAR EN PANTALLA EL ARREGLO

  33:  

  34: void mostrararreglo()

  35: {

  36: for(int x=0; x<renglones; x++)

  37:     {

  38:     for(int y=0; y<columnas; y++)

  39:         {

  40:         gotoxy(5+y,5+x); cout<<arreglo[x][y];

  41:         }

  42:     }

  43: }                                                      

  44:  

  45: //GENERAR NUMEROS ALEATORIOS EN UN ARREGLO

  46:  

  47: void numerosaleatorios(int *n)

  48: {

  49: randomize();

  50: for(int x=0; x<renglones*columnas; x++)

  51:     {

  52:     *(n+x)=random(9);

  53:     }

  54: }

  55:  

  56: //INICIALIZA UN ARREGLO

  57:  

  58: void inicializar(int *i)

  59: {

  60: for(int x=0; x<renglones*columnas; x++)

  61:     {

  62:     *(i+x)=0;

  63:     }

  64: }

Primer examen C++ Apuntadores

 
   1: //EXAMEN PRIMER SEMESTRE

   2:  

   3: //JULIO CESAR LEYVA RODRIGUEZ

   4:  

   5: #include 

   6: #include 

   7: #include 

   8: #include 

   9: #include 

  10:  

  11: #define max 10

  12: int arreglo[max];

  13: int x;

  14: int *p;

  15:  

  16: void i(int *p);           

  17:  

  18: void buscar(int *p)

  19: {

  20: int n;

  21: int z;

  22: int c;

  23: cout<<"INGRESE EL NUMERO QUE DESEA BUSCAR: ";    cin>>n;

  24: c=0;

  25: for(z=0; z<max; z++)

  26:     {       

  27:  

  28:     if(*(p+z)==n)

  29:         {

  30:                 c=0;

  31:         cout<<"n EL NUMERO SE REPITE EN LA POSICION: "<<z+1;

  32:                 c++;

  33:         }

  34:  

  35:  

  36:     }

  37: if(c==0)

  38:         {

  39:         cout<<"EL NUMERO NO SE REPITE";

  40:         }

  41: }

  42:  

  43:  

  44:  

  45: main()

  46: {

  47: i(&arreglo[0]);

  48: for(x=0; x<max; x++)

  49:     {

  50:     cout<<arreglo[x]<<"n";

  51:         }

  52: buscar(&arreglo[0]);

  53: }

  54:  

  55:  

  56:  

  57:  

  58:  

  59: void i(int *p)

  60: {

  61: randomize();

  62: for(x=0; x<max; x++)

  63:     {           

  64:  

  65:         *(p+x)=random(100);

  66:  

  67:     }

  68: }

Generar numeros aleatorios C++

 
   1: //GENERAR NUMEROS ALEATORIOS SIN DUPLICADOS

   2: #include 

   3: #include 

   4: #include 

   5:  

   6: int x;               

   7: int y;

   8: int na;                                

   9: int a[10];

  10: int z;

  11:  

  12: main()

  13: {

  14: randomize();

  15: while(x<10)

  16:     {

  17:         int c=0;

  18:     na=random(10);

  19:     for(y=0; y<10; y++)

  20:         {

  21:         if(na==a[x])

  22:             {

  23:             c++;

  24:             }

  25:         }

  26:     if(c==0)

  27:         {

  28:         a[x]=na;

  29:         x++;

  30:                 }

  31:     else

  32:         {

  33:         na=random(10);

  34:                 }

  35:     }

  36: for(z=0; z<10; z++)

  37:     {

  38:         cout<<"n"<<a[z];

  39:         }

  40: }

Apuntadores con funciones en C++

Les dejo el archivo para descargar.

APUNTADO.CPP
   1:

   2:

   3: //JULIO CESAR LEYVA RODRIGUEZ

   4:

   5: //APUNTADORES CON FUNCIONES

   6:

   7:

   8:

   9: #include

  10: #include

  11: #include

  12: #include

  13:

  14: #define max 5

  15: int arreglo[max];

  16: int x;

  17: int *p;

  18:

  19: void i(int *p)

  20: {

  21:

  22: for(x=0; x<max; x++)

  23:     {

  24:

  25:         *(p+x)=random(9);

  26:

  27:     }

  28: }

  29:

  30:

  31: main()

  32: {

  33: i(&arreglo[0]);

  34: for(x=0; x<max; x++)

  35:     {

  36:     cout<<arreglo[x]<<"n";

  37:         }

  38: }

 

 

Guardar archivos en C++ ejemplo

   1: /************************************************************************************************************

   2:  *                                                                                                          *

   3:  *                                              25 DE MARZO DE 2010                                         *

   4:  *                                                                                                            *

   5:  *  Programa que almacena los datos de los diferentes tipos de carros y los guarda en un archivo binario    *

   6:  *                                                                                                          *

   7:  *  Programador Julio Cesar Leyva Rodriguez            Instituto Tecnologico de Los Mochis                     *

   8:  *                                                                                                          *

   9:  ************************************************************************************************************/

  10:                                           

  11: #include 

  12: #include 

  13: #include  

  14: #include 

  15:  

  16: /** Estructura de los datos de los datos */

  17: struct reg

  18: {

  19: int numeroV;

  20: char marca[10];

  21: int anio;

  22: char color[10];

  23: int matricula;

  24: char activo;

  25: }automoviles;

  26:  

  27: void noExiste()

  28: {

  29: cout<<"nEl Registro no existe";

  30: }

  31:  

  32: void espacioOcupado()

  33: {

  34: cout<<"nEspacio ocupado";

  35: }

  36:  

  37: void eliminado()

  38: {

  39: cout<<"nEliminado correctamente";

  40: }

  41:  

  42: void registrado()

  43: {

  44: cout<<"nRegistrado correctamente";

  45: }

  46:  

  47: void registrando()

  48: {

  49: printf("ntt REGISTRO DE AUTOS n");

  50: cout<<"Marca ";                    gets(automoviles.marca);

  51: cout<<"Año ";                cin>>automoviles.anio;

  52: cout<<"Matricula ";                     cin>>automoviles.matricula;

  53: cout<<"Color ";                gets(automoviles.color);

  54: automoviles.activo='a';

  55: }

  56:  

  57:  

  58:  

  59: /** Funcion para registrar los datos en el archivo */

  60: void registrar()                                                        

  61: {

  62: clrscr();

  63:  

  64: FILE *ra;

  65:  

  66: ra=fopen("automoviles.dat","rb+");

  67:  

  68: if(ra==NULL)     //Si no existe

  69:     {

  70:     FILE *n;

  71:         fclose(ra);

  72:     n=fopen("automoviles.dat","ab+");

  73:  

  74:     cout<<"ntINSERTE LOS DATOS DEL PRIMER AUTOn";

  75:         automoviles.numeroV=1;

  76:  

  77:     registrando();

  78:     fwrite(&automoviles,sizeof(automoviles),1,n);

  79:     fclose(n);

  80:         registrado();

  81:     getch();

  82:     }

  83: else

  84:     {

  85:         fclose(ra);

  86:     FILE *c;

  87:  

  88:         c=fopen("automoviles.dat","rb+");

  89:  

  90:         int k;

  91:     cout<<"nInserte el numero de auto que desee insertar ";    cin>>k;

  92:  

  93:     fseek(c,(k-1)*sizeof(automoviles),SEEK_SET);

  94:     fread(&automoviles,sizeof(automoviles),1,c);

  95:  

  96:     if(automoviles.activo==NULL)

  97:         {

  98:         automoviles.numeroV=k;

  99:         registrando();

 100:         fseek(c,(k-1)*sizeof(automoviles),SEEK_SET);

 101:         fwrite(&automoviles,sizeof(automoviles),1,c);

 102:         fclose(c);

 103:         registrado();

 104:         getch();

 105:         }

 106:     else

 107:         {

 108:         espacioOcupado();

 109:                 getch();

 110:         }

 111:         }

 112:  

 113: }

 114:  

 115:  

 116:  

 117:  

 118:  

 119: /** Muestra todos los registros del archivo en forma de reporte */

 120: void reporte()

 121: {

 122: clrscr();

 123: FILE *rep;

 124:  

 125: rep=fopen("automoviles.dat","rb+");

 126: fread(&automoviles,sizeof(automoviles),1,rep);

 127: printf("# VEHICULO tt MARCA tt AÑO t MATRICULA t COLOR");

 128:  

 129:     do

 130:     {

 131:     if(automoviles.activo=='a')

 132:         {

 133:         cout<<"n "<<automoviles.numeroV<<"t tt "<<automoviles.marca<<"tt "<<automoviles.anio<<"t "<<automoviles.matricula<<"tt "<<automoviles.color;

 134:         }

 135:     fread(&automoviles,sizeof(automoviles),1,rep);

 136:     }while(!feof(rep));

 137: fclose(rep);

 138: getch();

 139: }

 140:  

 141: /** Consulta un solo registro en el archivo */

 142: void consultaVehiculo(int n)

 143: {

 144: FILE *rep;

 145:  

 146:  

 147:  

 148: rep=fopen("automoviles.dat","rb");

 149:  

 150: fseek(rep,(n-1)*(sizeof(automoviles)),SEEK_SET);

 151: fread(&automoviles,sizeof(automoviles),1,rep);

 152:  

 153: if(automoviles.activo!=NULL)

 154:     {

 155:     printf("n # VEHICULO tt MARCA tt AÑO t MATRICULA t COLOR");

 156:     if(automoviles.activo=='a')

 157:         {

 158:         cout<<"n "<<automoviles.numeroV<<"t tt "<<automoviles.marca<<"tt "<<automoviles.anio<<"t "<<automoviles.matricula<<"tt "<<automoviles.color;

 159:         }

 160:     else

 161:         {

 162:         noExiste();

 163:                 getch();

 164:         }

 165:     }

 166: else

 167:     {

 168:     noExiste();

 169:     getch();

 170:         }

 171: fclose(rep);

 172: }

 173:  

 174: /* Modifica un registro señalado */

 175: void modificar()

 176: {

 177: clrscr();

 178: FILE *reg;

 179: int d;

 180:  

 181: cout<<"Inserte el dato que desee modificar: ";    cin>>d;

 182:  

 183: reg=fopen("automoviles.dat","rb+");

 184:  

 185: printf("tt REGISTRO DE AUTOS n");

 186: cout<<"Numero de vehiculo ";     cin>>automoviles.numeroV;

 187: cout<<"Marca ";                gets(automoviles.marca);

 188: cout<<"Año ";            cin>>automoviles.anio;

 189: cout<<"Matricula ";        cin>>automoviles.matricula;

 190: cout<<"Color ";            gets(automoviles.color);

 191:  

 192: automoviles.activo='a';

 193:  

 194: fseek(reg,(d-1)*(sizeof(automoviles)),SEEK_SET);

 195:  

 196: fwrite(&automoviles,sizeof(automoviles),1,reg);

 197: fclose(reg);

 198: }

 199:  

 200: /* Elimina el registro seleccionado "logicamente" */

 201: void eliminar()

 202: {

 203: FILE *reg;

 204: int d;

 205:  

 206: cout<<"Inserte el registro que desee Eliminar: ";    cin>>d;

 207:  

 208: reg=fopen("automoviles.dat","rb+");

 209:  

 210: fseek(reg,(d-1)*(sizeof(automoviles)),SEEK_SET);

 211: fread(&automoviles,(d)*(sizeof(automoviles)),1,reg);

 212: if(automoviles.activo!=NULL)

 213:         {

 214:     fread(&automoviles,(d)*(sizeof(automoviles)),1,reg);

 215:  

 216:  

 217:  

 218:  

 219:     automoviles.activo='b';

 220:  

 221:     fseek(reg,(d-1)*(sizeof(automoviles)),SEEK_SET);

 222:     fwrite(&automoviles,sizeof(automoviles),1,reg);

 223:     fclose(reg);

 224:     eliminado();

 225:         getch();

 226:         }

 227: else

 228:     {

 229:     noExiste();

 230:         getch();

 231:         }

 232: }

 233:  

 234:  

 235: /* Menu de opciones */

 236: void menuA()

 237: {

 238: int a;

 239: int op;

 240: while(op!=5)

 241:         {

 242:     automoviles.activo=NULL;

 243:         clrscr();

 244:     gotoxy(25,1);    cout<<"REGISTRO DE AUTOMOTORES";

 245:     gotoxy(1,3);    cout<<"1.- Registrar automotor";

 246:     gotoxy(1,5);    cout<<"2.- Reporte";

 247:     gotoxy(1,7);    cout<<"3.- Consultar";

 248:     gotoxy(1,9);    cout<<"4.- Eliminar";

 249:         gotoxy(1,11);    cout<<"5.- Regresar";

 250:     gotoxy(1,14);    cout<<"t Eliga una opcion [   ]";

 251:     gotoxy(29,14);    cin>>op;

 252:     cout<<"n";

 253:         eslogan();

 254:  

 255:     switch(op)

 256:                 {

 257:         case 1:

 258:             registrar();

 259:                         

 260:             break;

 261:         case 2:

 262:             reporte();                        

 263:                         break;

 264:         case 3:               

 265:             clrscr();

 266:                  cout<<"Inserte el numero de automovil que desee consultar";    cin>>a;    

 267:             consultaVehiculo(a);                      

 268:                         getch();

 269:             break;

 270:         case 4:

 271:             clrscr();

 272:                         eliminar();

 273:                 break;

 274:  

 275:         }

 276:     }

 277: }

 278:  

 279:  

 280:  

 281: struct registro4

 282: {

 283: int     numeroC;

 284: char     nombre[10];

 285: char     domicilio[10];

 286: float     estatura;

 287: float     peso;

 288: char     activo;

 289: }conductores;

 290:  

 291: void registrandoC()

 292: {

 293:  

 294: printf("ntt REGISTRO DE CONDUCTORES n");

 295: cout<<"Nombre ";                gets(conductores.nombre);

 296: cout<<"Domicilio ";            gets(conductores.domicilio);

 297: cout<<"Estatura ";            cin>>conductores.estatura;

 298: cout<<"Peso ";                cin>>conductores.peso;

 299: conductores.activo='a';

 300: }

 301:  

 302: void registrarConductor()

 303: {

 304: clrscr();

 305:  

 306: FILE *ra;

 307:  

 308: ra=fopen("conductores.dat","rb+");

 309:  

 310: if(ra==NULL)     //Si no existe

 311:     {

 312:     FILE *n;

 313:     fclose(ra);

 314:     n=fopen("conductores.dat","ab");

 315:  

 316:     cout<<"ntINSERTE LOS DATOS DEL PRIMER CONDUCTORn";

 317:     conductores.numeroC=1;

 318:  

 319:     registrandoC();

 320:     fwrite(&conductores,sizeof(conductores),1,n);

 321:     fclose(n);

 322:  

 323:     getch();

 324:     }

 325: else

 326:     {

 327:     fclose(ra);

 328:     FILE *c;

 329:  

 330:     c=fopen("conductores.dat","rb+");

 331:  

 332:     int k;

 333:     cout<<"nInserte el numero de auto que desee insertar ";    cin>>k;

 334:  

 335:     fseek(c,(k-1)*sizeof(conductores),SEEK_SET);

 336:     fread(&conductores,sizeof(conductores),1,c);

 337:  

 338:     if(conductores.domicilio==NULL)

 339:         {

 340:         conductores.numeroC=k;

 341:         fseek(c,(k-1)*sizeof(conductores),SEEK_SET);

 342:         fwrite(&conductores,sizeof(conductores),1,c);

 343:         fclose(c);

 344:  

 345:         getch();

 346:         }

 347:     else

 348:         {

 349:  

 350:         getch();

 351:         }

 352:     }

 353:  

 354: }

 355:  

 356:  

 357:  

 358: void reporteConductores()

 359: {

 360: clrscr();

 361: FILE *rep;

 362:  

 363: rep=fopen("conductores.dat","rb");

 364: fread(&conductores,sizeof(conductores),1,rep);

 365: printf("# CONDUCTOR  t NOMBRE t DOMICILIO t ESTATURAtPESO");

 366:  

 367:     do

 368:     {

 369:     if(conductores.activo=='a')

 370:             {

 371:         cout<<"n"<<conductores.numeroC<<"tt "<<conductores.nombre<<"tt "<<conductores.domicilio<<"tt "<<conductores.estatura<<"tt"<<conductores.peso;

 372:             }

 373:     fread(&conductores,sizeof(conductores),1,rep);

 374:     }while(!feof(rep));

 375: fclose(rep);

 376: getch();

 377: }

 378:  

 379: void consultaC(int n)

 380: {

 381:  

 382: FILE *rep;

 383:  

 384:  

 385: rep=fopen("conductores.dat","rb+");

 386:  

 387: fseek(rep,(n-1)*(sizeof(conductores)),SEEK_SET);

 388: fread(&conductores,sizeof(conductores),1,rep);

 389:  

 390: if(conductores.activo!=NULL)

 391:     {

 392:     printf("# CONDUCTOR  tt NOMBRE tt DOMICILIO t ESTATURA");

 393:     if(conductores.activo=='a')

 394:         {

 395:         cout<<"n"<<conductores.numeroC<<"ttt "<<conductores.nombre<<"ttt "<<conductores.domicilio<<"tt "<<conductores.estatura;

 396:             }

 397:     else

 398:         {

 399:         cout<<"n El conductor no exite";

 400:                 getch();

 401:         }

 402:         

 403:     

 404:     }

 405: else

 406:     {

 407:     cout<<"nEl registro no existe";

 408:     getch();

 409:     }

 410: fclose(rep);  

 411: }

 412:  

 413:  

 414:  

 415: void eliminarC()

 416: {

 417: FILE *reg;

 418: int d;

 419:  

 420: cout<<"Inserte el conductor que desee dar de baja: ";    cin>>d;

 421:  

 422: reg=fopen("conductor.dat","rb+");

 423:  

 424: fseek(reg,(d-1)*(sizeof(conductores)),SEEK_SET);

 425: fread(&conductores,sizeof(conductores),1,reg);

 426:  

 427: if(conductores.activo!=NULL)

 428:     {

 429:     conductores.activo='b';

 430:  

 431:     fseek(reg,(d-1)*(sizeof(conductores)),SEEK_SET);

 432:     fwrite(&conductores,sizeof(conductores),1,reg);

 433:     fclose(reg);

 434:     }

 435: else

 436:     {

 437:     cout<<"nEl archivo no esta";

 438:     getch();

 439:         }

 440: }

 441:  

 442:  

 443: void menuC()

 444: {

 445: conductores.activo=NULL;

 446: int op;

 447: int b;

 448: while(op!=5)

 449:     {

 450:     clrscr();

 451:     gotoxy(25,1);    cout<<"REGISTRO DE CONDUCTORES";

 452:     gotoxy(1,3);    cout<<"1.- Registrar conductor";

 453:     gotoxy(1,5);    cout<<"2.- Reporte";

 454:     gotoxy(1,7);    cout<<"3.- Consulta";

 455:     gotoxy(1,9);    cout<<"4.- Eliminar";

 456:     gotoxy(1,11);    cout<<"5.- Regresar";

 457:     gotoxy(1,14);    cout<<"t Eliga una opcion [   ]";

 458:     gotoxy(29,14);    cin>>op;

 459:  

 460:     switch(op)

 461:                 {

 462:         case 1:

 463:             registrarConductor();

 464:                         

 465:             break;

 466:         case 2:        

 467:             reporteConductores();

 468:                         break;

 469:         case 3:               

 470:             clrscr();

 471:             cout<<"Inserte el numero de conductor que desee consultar ";    cin>>b;

 472:             consultaC(b);

 473:             getch();

 474:             break;

 475:         case 4:

 476:             clrscr();

 477:                         eliminarC();

 478:                 break;

 479:  

 480:         }

 481:     }

 482: }

 483: void eslogan()

 484: {

 485: cout<<"   ******      **     *******   *******   ******** *******       **    ";

 486: cout<<"n  **////**    ****   /**////** /**////** /**///// /**////**     ****   ";

 487: cout<<"n **    //    **//**  /**   /** /**   /** /**      /**   /**    **//**  ";

 488: cout<<"n/**         **  //** /*******  /*******  /******* /*******    **  //** ";

 489: cout<<"n/**        **********/**///**  /**///**  /**////  /**///**   **********";

 490: cout<<"n//**    **/**//////**/**  //** /**  //** /**      /**  //** /**//////**";

 491: cout<<"n //****** /**     /**/**   //**/**   //**/********/**   //**/**     /**";

 492: cout<<"n  //////  //      // //     // //     // //////// //     // //      // ";

 493: }

 494:  

 495:  

 496:  

 497: struct evento

 498: {

 499: int folio;

 500: int nC;

 501: int nV;

 502: int tiempo;

 503: }carrera;

 504:  

 505:  

 506:  

 507: void ultimo();

 508:  

 509:  

 510: void borrar()

 511: {

 512: carrera.folio=NULL;

 513: carrera.nC=NULL;

 514: carrera.nV=NULL;

 515: carrera.tiempo=NULL;

 516: }

 517: //REGISTRAR AUTO Y CONDUCTOR

 518:  

 519: void registrarParticipante()

 520: {

 521:  

 522: borrar();

 523: FILE *e;

 524: FILE *a;

 525: int size;

 526:  

 527: borrar();

 528: e=fopen("evento.dat","ab+");

 529: a=fopen("evento.dat","rb+");

 530:  

 531:  

 532: size=sizeof(carrera);

 533:  

 534: fseek(a,-size,SEEK_END);

 535: fread(&carrera,size,1,a);

 536:  

 537: carrera.tiempo=NULL;

 538: carrera.folio=(carrera.folio)+1;

 539:  

 540: cout<<"nINSERTE EL NUMERO DEL PILOTO ";    cin>>carrera.nC;

 541:  

 542: cout<<"nINSERTE EL NUMERO DEL VEHICULO ";    cin>>carrera.nV;

 543:  

 544: fwrite(&carrera,sizeof(carrera),1,e);

 545:  

 546: fclose(e);

 547: fclose(a);

 548:  

 549: }

 550: //REPORTE

 551:  

 552: void reporteEvento()

 553: {

 554: borrar();

 555: FILE *reporte1;

 556:  

 557: reporte1=fopen("evento.dat","rb+");

 558:  

 559: do

 560:     {

 561:         if(carrera.folio!=NULL)

 562:             {

 563:             consultaVehiculo(carrera.nV);

 564:             consultaC(carrera.nC);

 565:                         }

 566:     fread(&carrera,sizeof(carrera),1,reporte1);

 567:     }while(!feof(reporte1));

 568: }

 569:  

 570:  

 571:  

 572: void registrarTiempo()

 573: {

 574: FILE *tiempo;

 575: tiempo=fopen("evento.dat","rb+");

 576: int folio;

 577:  

 578: borrar();

 579: cout<<"nnINSERTE EL FOLIO DEL PILOTO QUE DESEE INGRESAR EL TIEMPO ";

 580: cin>>folio;

 581:  

 582: fseek(tiempo,(folio-1)*(sizeof(carrera)),SEEK_SET);

 583: fread(&carrera,sizeof(carrera),1,tiempo);

 584:  

 585: cout<<"nnINGRESE EL TIEMPO ";cin>>carrera.tiempo;

 586:  

 587: fseek(tiempo,(folio-1)*(sizeof(carrera)),SEEK_SET);

 588: fwrite(&carrera,sizeof(carrera),1,tiempo);

 589: fclose(tiempo);

 590: }

 591:  

 592:  

 593: /* Menu de opciones */

 594: void menuE()

 595: {

 596: int a;

 597: int op;

 598: while(op!=5)

 599:     {

 600:     automoviles.activo=NULL;

 601:     clrscr();

 602:     gotoxy(25,1);    cout<<"EVENTO";

 603:     gotoxy(1,3);    cout<<"1.- Registrar participante";

 604:     gotoxy(1,5);    cout<<"2.- Reporte";

 605:     gotoxy(1,7);    cout<<"3.- Modificar tiempo";

 606:     gotoxy(1,9);    cout<<"4.- Consulta participante";

 607:     gotoxy(1,11);    cout<<"5.- Regresar";

 608:     gotoxy(1,13);    cout<<"t Eliga una opcion [   ]";

 609:     gotoxy(29,13);    cin>>op;

 610:  

 611:     switch(op)

 612:         {

 613:         case 1:

 614:             clrscr();

 615:             registrarParticipante();

 616:             getch();

 617:             break;

 618:         case 2:

 619:             reporteEvento();

 620:             getch();

 621:             break;

 622:         case 3:

 623:             clrscr();

 624:             registrarTiempo();

 625:             getch();

 626:             break;

 627:  

 628:         case 4:

 629:             cout<<"n INSERTE EL NUMERO DEL PARTICIPANTE QUE DESEE CONSULTAR ";     cin>>a;

 630:             consultaVehiculo(a);

 631:             cout<<"n";

 632:             getch();

 633:             consultaC(a);

 634:             cout<<"nPresione cualquier tecla para continuar";

 635:             getch();

 636:             break;

 637:         case 5:

 638:                     break;

 639:         default:

 640:             cout<<"OPCION NO VALIDA";

 641:             getch();

 642:             break;

 643:         }

 644:     }

 645: }

 646:  

 647:  

 648:  

 649: void main()

 650: {

 651: int op;

 652: while(op!=5)

 653:     {

 654:     clrscr();

 655:     eslogan();

 656:     gotoxy(25,10);    cout<<"PRINCIPAL";

 657:     gotoxy(1,13);    cout<<"1.- Vehiculos";

 658:     gotoxy(1,15);    cout<<"2.- Conductores";

 659:     gotoxy(1,17);    cout<<"3.- Evento";

 660:     gotoxy(1,19);    cout<<"4.- Reporte";

 661:     gotoxy(1,21);    cout<<"t Eliga una opcion [   ]";

 662:     gotoxy(29,21);    cin>>op;

 663:  

 664:     switch(op)

 665:         {

 666:         case 1:

 667:             clrscr();

 668:             menuA();

 669:  

 670:             break;

 671:         case 2:

 672:             menuC();                        

 673:                         break;

 674:         case 3:               

 675:             clrscr();

 676:             menuE();

 677:             break;

 678:         case 4:

 679:             clrscr();

 680:                         reporteEvento();

 681:             getch();

 682:             break;

 683:         case 5:

 684:                         clrscr();

 685:             cout<<"Salir";

 686:                         break;

 687:  

 688:         default:

 689:             cout<<"nOPCION INCORRECTA";

 690:             break;

 691:  

 692:         }

 693:     }

 694: }

Arboles binarios en C++

Les dejo un viejo apunte de la universidad
Para descargar de clic en descargar
 
ARBOLES.CPP
 
   1: #include 

   2: #include 

   3: #include 

   4: #include 

   5:  

   6: typedef int tipodatoarbol;

   7: typedef struct nodo {

   8:    tipodatoarbol dato;

   9:    struct nodo *izq;

  10:     struct nodo *der;

  11: } tipoNodo;

  12: typedef tipoNodo *pNodo;

  13:  

  14: void insertar(pNodo *l,tipodatoarbol Dato);

  15: void inicializar(pNodo *l);

  16: void eliminar(pNodo *l, tipodatoarbol d);

  17: void preorden(pNodo *l);

  18: void inorden(pNodo *l);

  19: void postorden(pNodo *l);

  20:  void menu(pNodo *l);

  21: void inicio(pNodo *l);

  22: void agregar(pNodo *l);

  23: void quitar(pNodo *l);

  24:  

  25: void main()

  26: {

  27:   pNodo arbol;

  28:   menu(&arbol);

  29: }

  30:  

  31: void menu(pNodo *l)

  32: {  int op;

  33:    clrscr();

  34:    gotoxy(33,7);cout<<"ARBOL BINARIO";

  35:    gotoxy(32,9);cout<<"1) Inicializar";

  36:    gotoxy(32,11);cout<<"2) Insertar";

  37:    gotoxy(32,13);cout<<"3) Eliminar";

  38:    gotoxy(32,15);cout<<"4) Imprimir";

  39:    gotoxy(32,17);cout<<"5) Salir";

  40:    do{

  41:      gotoxy(33,19);cout<<"Opcion [ ] ";

  42:      gotoxy(41,19);cin>>op;

  43:    }while (op>5 || op<1);

  44:  

  45:    switch(op)

  46:    {

  47:      case 1:

  48:       inicio(l);

  49:       break;

  50:      case 2:

  51:       agregar(l);

  52:       break;

  53:      case 3:

  54:       quitar(l);

  55:       break;

  56:      case 4:

  57:       clrscr();

  58:       gotoxy(10,16);cout<<" Inorden: ";inorden(l);

  59:       gotoxy(10,17);cout<<" Preorden: ";preorden(l);

  60:       gotoxy(10,18);cout<<" Postorden: ";postorden(l);

  61:       getch();

  62:       menu(l);

  63:       break;

  64:      case 5:

  65:       exit(0);

  66:    }

  67:    getch();

  68: }

  69:  

  70: void inicio(pNodo *l)

  71: { clrscr();

  72:   inicializar(l);

  73:   menu(l);

  74: }

  75:  

  76: void agregar(pNodo *l)

  77: { clrscr();

  78:   int D;

  79:   //char opc='s';

  80:   gotoxy(30,20);cout<<"Insertar numero: "; cin>>D;

  81:     insertar(l,D);

  82:    // cout<>opc;

  83:  // }while(opc=='s' ||opc=='S');

  84:   menu(l);

  85: }

  86: void quitar(pNodo *l)

  87: { clrscr();

  88:   int D;

  89:   //char opc='s';

  90:   //do{

  91:     gotoxy(30,20);cout<<"Numero a eliminar: "; cin>>D;

  92:     eliminar(l,D);

  93:     //gotoxy(12,8);cprintf("nDesea Eliminar otro dato (S/N): "); cin>>opc;

  94:   //}while(opc=='s' ||opc=='S');

  95:   menu(l);

  96: }

  97:  

  98: // FUNCIONES BASICAS

  99: void inicializar(pNodo *l)

 100: {

 101:  *l=NULL;

 102: }

 103:  

 104: //insertar

 105: void insertar(pNodo *l,tipodatoarbol Dato){

 106:     pNodo Nuevo, Aux;

 107:     int b;

 108:     Nuevo=(pNodo)malloc(sizeof(tipoNodo));

 109:     Nuevo->dato= Dato;

 110:     Nuevo->der=NULL;

 111:     Nuevo->izq=NULL;

 112:     Aux=*l;

 113:      if (*l==NULL){

 114:      *l=Nuevo;

 115:     }

 116:     else if (*l!=NULL)

 117:     {

 118:      b=0;

 119:      while(b==0)

 120:     {

 121:     if(Nuevo->datodato)

 122:      {

 123:      while(Aux->izq!=NULL&&Nuevo->datodato)

 124:         { Aux=Aux->izq;}

 125:        if(Nuevo->datodato&&Aux->izq==NULL)

 126:         {Aux->izq=Nuevo;

 127:         b=1;

 128:         }

 129:       else {if(Nuevo->dato>Aux->dato&&Aux->der==NULL)

 130:       {Aux->der=Nuevo;

 131:       b=1;

 132:         } }

 133:      }

 134:      else

 135:        if(Nuevo->dato>Aux->dato)

 136:      {

 137:  

 138:      while(Aux->der!=NULL&&Nuevo->dato>Aux->dato)

 139:         { Aux=Aux->der;}

 140:        if(Nuevo->datodato&&Aux->izq==NULL)

 141:         {Aux->izq=Nuevo;

 142:         b=1;

 143:         }

 144:       else if(Nuevo->dato>Aux->dato&&Aux->der==NULL)

 145:       {Aux->der=Nuevo;

 146:       b=1;

 147:          }

 148:      } }

 149:       }

 150:  

 151: }

 152:  

 153: void eliminar(pNodo *l,tipodatoarbol d)

 154: {

 155:  if(*l==NULL)

 156:  {

 157:   gotoxy(30,20);cout<<"Arbol vacio";

 158:   getch();

 159:  }

 160:  else

 161:  {

 162:   pNodo aux,ant;

 163:   aux=*l;

 164:    while(aux->dato!=d&&(aux->izq!=NULL||aux->der!=NULL))

 165:    {

 166:    if(ddato)

 167:    {

 168:     ant=aux;

 169:     aux=aux->izq;

 170:    }

 171:    else

 172:    {

 173:     ant=aux;

 174:     aux=aux->der;

 175:    }

 176:   }

 177:   if(aux->dato==d)

 178:   {

 179:    if(aux==*l&&aux->izq==NULL&&aux->der==NULL)

 180:    {

 181:     inicializar(l);

 182:    }

 183:    else

 184:    {

 185:     if(aux->izq!=NULL&&aux->der!=NULL)

 186:     {

 187:      ant=aux;

 188:      aux=aux->izq;

 189:      if(aux->der==NULL)

 190:      {

 191:       ant->dato=aux->dato;

 192:       ant->izq=aux->izq;

 193:      }

 194:      else

 195:      {

 196:       pNodo ant2;

 197:       while(aux->der!=NULL)

 198:       {

 199:        ant2=aux;

 200:        aux=aux->der;

 201:       }

 202:       ant->dato=aux->dato;

 203:       if(aux->izq==NULL)

 204:       {

 205:        ant2->der=NULL;

 206:       }

 207:       else

 208:       {

 209:        ant2->der=aux->izq;

 210:       }

 211:      }

 212:     free(aux);

 213:    }

 214:    else

 215:     if(aux->izq!=NULL||aux->der!=NULL)

 216:     {

 217:      if(aux->izq!=NULL)

 218:      {

 219:       if(aux->datodato)

 220:       {

 221:        if(aux==*l)

 222:     *l=aux->izq;

 223:        else

 224:     ant->izq=aux->izq;

 225:       }

 226:       else

 227:       {

 228:        if(aux==*l)

 229:     *l=aux->izq;

 230:        else

 231:        ant->der=aux->izq;

 232:       }

 233:      }

 234:      else

 235:      {

 236:       if(aux->datodato)

 237:       {

 238:        if(aux==*l)

 239:     *l=aux->der;

 240:        else

 241:     ant->izq=aux->der;

 242:       }

 243:       else

 244:       {

 245:        if(aux==*l)

 246:     *l=aux->der;

 247:        else

 248:     ant->der=aux->der;

 249:       }

 250:      }

 251:      free(aux);

 252:     }

 253:     else

 254:      if(aux->izq==NULL&&aux->der==NULL)

 255:      {

 256:       if (aux->datodato)

 257:        ant->izq=NULL;

 258:       else

 259:        ant->der=NULL;

 260:       free(aux);

 261:      }

 262:     }

 263:    }

 264:    else

 265:    {

 266:     gotoxy(30,20);cout<<"Numero no existente";

 267:     getch();

 268:    }

 269:  }

 270: }

 271: void preorden(pNodo *l){

 272:   pNodo Aux,*l2;

 273:   Aux=*l;

 274:   if(*l!=NULL){

 275:     cout<<" "<dato;

 276:     *l2=Aux->izq;

 277:     preorden(l2);

 278:     *l2=Aux->der;

 279:     preorden(l2);

 280:   }

 281: }

 282:  

 283:  

 284: void inorden(pNodo *l){

 285:   pNodo Aux,*l2;

 286:   Aux=*l;

 287:   if(*l!=NULL){

 288:     *l2=Aux->izq;

 289:     inorden(l2);

 290:     cout<<" "<dato;

 291:     *l2=Aux->der;

 292:     inorden(l2);

 293:   }

 294: }

 295:  

 296: void postorden(pNodo *l){

 297:   pNodo Aux,*l2;

 298:   Aux=*l;

 299:   if(*l!=NULL){

 300:     *l2=Aux->izq;

 301:     postorden(l2);

 302:     *l2=Aux->der;

 303:     postorden(l2);

 304:     cout<<" "<dato;

 305:   }

 306: }

 307:  

Cadena de Markov – Investigación de operaciones 2

INSTITUTO TECNOLÓGICO

DE LOS MOCHIS

LIC. INFORMATICA

ALUMNOS:

MIJAIL HERRERA FIGUEROA

JULIO CESAR LEYVA RODRIGUEZ

MATERIA:

INVESTIGACION DE OPERACIONES II

DOCENTE:

CHARLY HERVEY

LOS MOCHIS SINALOA 2010
CADENA DE MARKOV
En una empresa de sexoservidoras se tienen establecidos 3 tipos de servicios: Premium, regular y normal de 3 dichas servidoras, para la servidora 1 el 10% es regular y el 8% es normal lo que para la servidora 2 el 17% es regular y el 10% es normal y lo que para la servidora 3 el 33% es normal y el 3% es regular.

  • Realizar la matriz de transición
  • Elaborar la cadena de Markov
  • Sacar la probabilidad para 2,4 y 8 días.

MATRIZ DE TRANSICION

             Premium regular Normal

Premium 0.82       0.10     0.08

Regular 0.73       0.17      0.10

Normal 0.60       0.07       0.33

                                                 CADENA DE MARKOV

 

                                                     PARA 2 DIAS

             Premium  regular Normal

Premium 0.7934 0.1046 0.102

Regular 0.7827 0.1089 0.1084

Normal 0.7411 0.095 0.1639

PARA 4 DIAS

Premium regular Normal

Premium 0.78694618 0.10407058 0.10898324

Regular 0.78656545 0.10402763 0.10940692

Normal 0.78381153 0.10343506 0.11275341

PARA 8 DIAS

                Premium              regular             Normal

Premium  0.786564932   0.103996849   0.109438218

Regular 0.78656321       0.103996581    0.109439797

Normal 0.772848898     0.10399448     0.109452162

PROGRAMACION DINAMICA

Se construyo especialmente para ilustrar la ruta y las características e introducir la termino logia de la programación dinámica. Este paradigma se refiere a la ruta que hay actualmente desde los Mochis Sinaloa hasta ensenada baja california norte en una agencia de autotransportes.

A. LOS MOCHIS, SINALOA

B. NAVOJOA, SONORA

C. OBREGON, SONORA

D. GUAYMAS,SONORA

E. SANTANA, SONORA

F. HERMOSILLO, SONORA

G. MEXICALI, BAJA CALIFORNIA NORTE

H. TIJUANA, BAJA CALIFORNIA NORTE

I. TECATE, BAJA CALIFORNIA NORTE

J. ENSENADA, BAJA CALIFORNIA NORTE

 



Drivers Controladores autoinstalables HP Mini 210-3000 Windows 7

Drivers autoinstalables HP Mini 210-3000

Contenido del paquete

Intel 82801GBM ICH7-M – High Definition Audio Controller
Atheros AR9285 802.11b/g/n WiFi Adapter
Realtek PCIe FE Family Controller
Intel(R) Graphics Media Accelerator 3150

 

Página 1 de 2

Creado con WordPress & Tema de Anders Norén