Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 23rd, 2012  |  syntax: None  |  size: 3.01 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.  * File:   main.c
  3.  * Author: leleobhz
  4.  *
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. /* Mas hein? Declaracao estranha de ponteiro para array: http://eli.thegreenplace.net/2010/04/06/pointers-vs-arrays-in-c-part-2d/ */
  12.  
  13. void assento_vago (int (*mtrz)[][5], int *linhalivre, int *colunalivre, int tipo)
  14. {
  15.     int i;
  16.     int j;
  17.     int colunafinal;
  18.     /* Executiva */
  19.     if (tipo==1)
  20.     {
  21.         j=0;
  22.         colunafinal=1;
  23.     } else
  24.     /* Peao :P */
  25.     if (tipo==2)
  26.     {
  27.         j=2;
  28.         colunafinal=4;
  29.     }
  30.     for (i=0;i<=3;i++)
  31.     {
  32.         for (j=0;j<=colunafinal;j++)
  33.         {
  34.             if (*mtrz[i][j]==0)
  35.             {
  36.                 *linhalivre = i;
  37.                 *colunalivre = j;
  38.                 goto end;
  39.             }
  40.         }
  41.     }
  42.     end:;
  43. }
  44.  
  45. void bilhete (int *linha, int *coluna)
  46. {
  47.     /* Montar a string bonitinha */
  48.     char assento[2];
  49.  
  50.     assento[0] = (char) *linha + 1;
  51.     switch (*coluna)
  52.     {
  53.         case 0: assento[1]='A'; break;
  54.         case 1: assento[1]='B'; break;
  55.         case 2: assento[1]='C'; break;
  56.         case 3: assento[1]='D'; break;
  57.         case 4: assento[1]='E'; break;
  58.     }
  59.     /* POG: Tentar achar o windows pra ver como limpar a tela: Mea Culpa: Grosseria */
  60.  
  61.     #if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
  62.         system("cls");
  63.     #else
  64.         fprintf(stdout, "\033[2J");
  65.         fprintf(stdout, "\033[1;1H");
  66.     #endif
  67.         /* Cabia num printf so, mas pra ficar legal de ler*/
  68.         printf("*********************************************************");
  69.         printf("*\t\t\t\t\t\t\t*");
  70.         printf("* Reserva de passagem aerea\t\t\t\t*");
  71.         printf("*\t\t\t\t\t\t\t*");
  72.         printf("*\t\t\t\t\t\t\t*");
  73.         printf("* Assento reservado: %s\t\t\t\t\t*", assento);
  74.         printf("*\t\t\t\t\t\t\t*");
  75.         printf("*\t\t\t\t\t\t\t*");
  76.         printf("*********************************************************");
  77. }
  78.  
  79. int main(int argc, char** argv)
  80. {
  81.     int i;
  82.     int j;
  83.     /* Sim, eu sei que são objetos separados */
  84.     int linhalivre;
  85.     int colunalivre;
  86.     char opcao;
  87.  
  88.     /* Inicia matriz */
  89.     int mtrz[4][5]={{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0} };
  90.  
  91.     printf ("Reserva de passagens\n\n");
  92.     printf ("Para classe economica, digite 1\n");
  93.     printf ("Para classe executiva, digite 2\n");
  94.  
  95.     /* Bem que tentei evitar o Enter no final, mas foi triste */
  96.     opcao = getchar();
  97.  
  98.     switch (opcao)
  99.     {
  100.         case '1':
  101.             assento_vago(&mtrz,&linhalivre,&colunalivre,2);
  102.             *mtrz[linhalivre,colunalivre]=1;
  103.             bilhete(&linhalivre,&colunalivre);
  104.             break;
  105.         case '2':
  106.             assento_vago(&mtrz,&linhalivre,&colunalivre,1);
  107.             *mtrz[linhalivre,colunalivre]=1;
  108.             bilhete(&linhalivre,&colunalivre);
  109.             break;
  110.         default:
  111.             break;
  112.     }
  113.  
  114.     return (EXIT_SUCCESS);
  115. }