Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: HRSLASH en 11 Diciembre 2010, 23:51 pm



Título: Sistema de reservacion de aerolinea[C]
Publicado por: HRSLASH en 11 Diciembre 2010, 23:51 pm
Hola foreros! hacia mucho q no posteaba nada debido a q cursando en la facu no tenia mucho tiempo libre para programar.
Como ya termine volvi a codear en c y queria subir un programa de reserva de aerolinea q pide como ejercicio un libro q estoy leyendo.
Espero comentarios y sugerencias.
Saludos!

Código
  1.  
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<time.h>
  5. #define SIZE_ASIENTOS 10
  6.  
  7. int asignarAsiento(int [], int, int);
  8. void pasaje(int);
  9. void diagrama(int [], int);
  10.  
  11. main()
  12. {
  13.    srand(time(NULL));
  14.    int asientos[SIZE_ASIENTOS] = {0};
  15.    int i, num, cont = 0;
  16.  
  17.    printf("SISTEMA DE RESERVACION DE AEROLINEAS\n\n");
  18.  
  19.    diagrama(asientos, SIZE_ASIENTOS);
  20.  
  21.    while (cont <= SIZE_ASIENTOS - 1){
  22.  
  23.        printf("Por favor ingrese 1 para sector fumadores\n"
  24.               "Por favor ingrese 2 para sector no fumadores\n");
  25.        scanf("%d", &num);
  26.  
  27.        while (num > 2){
  28.            printf("Numero no valido\n\n");
  29.            printf("Por favor ingrese 1 para sector fumadores\n"
  30.                   "Por favor ingrese 2 para sector no fumadores\n");
  31.            scanf("%d", &num);
  32.        }
  33.  
  34.        if ((asignarAsiento(asientos, SIZE_ASIENTOS, num)) != 0)
  35.            cont++;
  36.  
  37.        diagrama(asientos, SIZE_ASIENTOS);
  38.    }
  39.  
  40.    printf("Avion lleno\nProximo vuelo en 3 horas\n");
  41.  
  42.  
  43.    return 0;
  44. }
  45.  
  46.  
  47.  
  48.  
  49.  
  50. int asignarAsiento(int a[], int size, int n)
  51. {
  52.    char rta[1];
  53.    int i, status = 0;
  54.    static int cont1 = 0, cont2 = 0;
  55.  
  56.    switch(n){
  57.        case 1:                     //SECTOR FUMADORES
  58.            if (cont1 < size / 2){
  59.                while (status == 0){
  60.                    i = rand() % size /2;
  61.                    if(a[i] == 0){
  62.                        a[i] = 1;
  63.                        pasaje(i);
  64.                        cont1++;
  65.                        status = 1;
  66.                    }
  67.                }
  68.            }
  69.            else{
  70.                printf("La sección fumadores esta llena. "
  71.                       "Le gustaria q le asignemos un lugar en la sección "
  72.                       "de no fumadores(s/n)");
  73.                scanf("%s", rta);
  74.  
  75.                if(rta[0] == 's' || rta[0] == 'S'){
  76.                    while (status == 0){
  77.                        i = size / 2 + rand() % size / 2;
  78.                        if(a[i] == 0){
  79.                            a[i] = 1;
  80.                            pasaje(i);
  81.                            cont2++;
  82.                            status = 1;
  83.                        }
  84.                    }
  85.                }
  86.  
  87.                else{
  88.                    printf("\nEl proximo vuelo sale en 3 horas\n\n");
  89.                    return 0;
  90.                }
  91.            }
  92.  
  93.            break;
  94.  
  95.  
  96.        case 2:                     //SECTOR NO FUMADORES
  97.            if (cont2 < size / 2){
  98.                while (status == 0){
  99.                    i = size / 2 + rand() % size / 2;
  100.                    if (a[i] == 0){
  101.                        a [i] = 1;
  102.                        pasaje(i);
  103.                        cont2++;
  104.                        status = 1;
  105.                    }
  106.                }
  107.            }
  108.  
  109.            else{
  110.                printf("La sección de no fumadores esta llena. "
  111.                       "Le gustaria q le asignemos un lugar en la sección "
  112.                       "de fumadores(s/n)");
  113.                scanf("%s", rta);
  114.  
  115.                if(rta[0] == 's' || rta[0] == 'S'){
  116.                    while (status == 0){
  117.                        i = rand() % size /2;
  118.                        if(a[i] == 0){
  119.                            a[i] = 1;
  120.                            pasaje(i);
  121.                            cont1++;
  122.                            status = 1;
  123.                        }
  124.                    }
  125.                }
  126.  
  127.                else{
  128.                    printf("\nEl proximo vuelo sale en 3 horas\n\n");
  129.                    return 0;
  130.                }
  131.            }
  132.  
  133.            break;
  134.    }
  135.  
  136. }
  137.  
  138. void pasaje(int numAsiento)
  139. {
  140.    printf("\n************************\n");
  141.    printf("AEROLINEA\n");
  142.    printf("Pase de abordaje\n");
  143.    if (numAsiento >= 0 && numAsiento <= 4){
  144.        printf("Asiento nº %d\n", numAsiento + 1);
  145.        printf("Sector fumadores\n");
  146.    }
  147.    else{
  148.        printf("Asiento nº %d\n", numAsiento + 1);
  149.        printf("Sector no fumadores\n");
  150.    }
  151.    printf("\n************************\n");
  152. }
  153.  
  154. void diagrama(int a[], int size)
  155. {
  156.    int i;
  157.  
  158.    printf("\n");
  159.    printf("%30s\n\n", "DIAGRAMA AVION");
  160.    printf("%15s %26s\n", "FUMADORES", "NO FUMADORES");
  161.    printf("/-------------------\\");
  162.    printf("    /-------------------\\\n");
  163.        for (i = 0; i <= size - 1; i++)
  164.            printf("%-5d", a[i]);
  165.    printf("\n\n");
  166.  
  167. }
  168.  
  169.  


Título: Re: Sistema de reservacion de aerolinea[C]
Publicado por: Garfield07 en 13 Diciembre 2010, 20:19 pm
Simplemente añado que esta muy bien, pero se podria reducir un poco...
a ver si luego lo minimizo xD


Título: Re: Sistema de reservacion de aerolinea[C]
Publicado por: carlosmendoza en 31 Octubre 2013, 23:57 pm
AMIGO LE FELICITO POR EL GRAN TRABAJO QUE HA REALIZADO SOLO QUISIERA SABER COMO HACER PARA QUE ME aparezca TRES CATEGORIAS POR EJEMPLO CLASE TURISTA, CLASE MEDIA, CLASE PRIMERA. ESPERO SU RESPUESTA


Título: Re: Sistema de reservacion de aerolinea[C]
Publicado por: horlandjo en 20 Diciembre 2017, 02:06 am
Hola no tengo mucha experiencia en esto de la programacion y estoy viendo muchos ejericicios y entre ellos encontré el tuyo, podrías explicarme por favor, porque no me compila en Mac OS X?
Utilicé SublimeText pero me lanza el siguiente mensaje en la terminal


aerolinea.c:10:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
main()
^
aerolinea.c:135:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
2 warnings generated.



Se debe a un problema del sistema operativo o del compilador o que pasó?


Muchas gracias por leerme, y gracias por el aporte que diste al foro.


Título: Re: Sistema de reservacion de aerolinea[C]
Publicado por: MAFUS en 20 Diciembre 2017, 20:02 pm
Se debe a que estudias material muy desfasado.

El primer warning que te lanza es porqué toda función debe declarar el tipo de dato que devuelve. Antes del estándar de 1989 las funciones, si no se declaraba su tipo de dato devuelto, se consideraban int. Actualmente es obligatorio indicar ese dato.

El segundo warning viene de que la función asignar asiento debe devolver un entero, sin embargo se llega hasta el final de ella sin devolver dato alguno. Debe haber una sentencia return con un entero.