Created
October 29, 2010 00:49
-
-
Save fsouza/652664 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int main () { | |
char onibus[4][9]; | |
int i, j, linha, coluna, opcao, fileira, na_janela = 0, no_corredor = 0, ocupadas = 0; | |
char lado[20], poltrona[20]; | |
for (i = 0; i < 4; i++) { | |
for (j = 0; j < 9; j++) { | |
onibus[i][j] = '0'; | |
} | |
} | |
do { | |
printf("\n VENDA DE PASSAGENS\n\n\n"); | |
printf("Opções disponíveis:\n\n"); | |
printf("1 - Preencher vaga\n"); | |
printf("2 - Ver relatório de vagas\n"); | |
printf("0 - Sair do sistema\n\n"); | |
printf("Selecione uma opção: "); | |
scanf("%d", &opcao); | |
switch(opcao) { | |
case 1: | |
printf("Preenchendo vaga...\n"); | |
do { | |
printf("Digite a fileira desejada (1 a 9): "); | |
scanf("%d", &fileira); | |
} while (fileira < 1 || fileira > 9); | |
do { | |
printf("Digite o lado desejado (direito ou esquerdo): "); | |
scanf("%s", lado); | |
} while (strcmp(lado, "direito") != 0 && strcmp(lado, "esquerdo") != 0); | |
do { | |
printf("Digite a poltrona desejada (janela ou corredor): "); | |
scanf("%s", poltrona); | |
} while (strcmp(poltrona, "janela") != 0 && strcmp(poltrona, "corredor") != 0); | |
if (strcmp(poltrona, "janela") == 0) { | |
na_janela++; | |
} else { | |
no_corredor++; | |
} | |
// Determinando linha e coluna | |
coluna = fileira - 1; | |
if (strcmp(lado, "direito") == 0) { // 0 ou 1 | |
linha = (strcmp(poltrona, "janela") == 0) ? 0 : 1; | |
} else { // 2 ou 3 | |
linha = (strcmp(poltrona, "janela") == 0) ? 3 : 2; | |
} | |
// Ocupando local, caso esteja livre | |
if (onibus[linha][coluna] == '0') { | |
onibus[linha][coluna] = 'x'; | |
} else { | |
printf("POLTRONA JÁ OCUPADA!!!!!!!!!"); | |
} | |
// Incrementando ocupadas | |
ocupadas++; | |
case 2: // Sem break propositalmente, para sempre exibir relatório após preencher poltrona | |
printf("Relatório de vagas:\n\n"); | |
printf("123456789\n"); | |
for (i = 0; i < 4; i++) { | |
for (j = 0; j < 9; j++) { | |
printf("%c", onibus[i][j]); | |
} | |
printf("\n"); | |
} | |
printf("Pessoas na janela: %d.\n", na_janela); | |
printf("Pessoas no corredor: %d.\n", no_corredor); | |
printf("Total ocupadas: %d.\n", ocupadas); | |
printf("Total vazias: %d.\n\n", 36 - ocupadas); | |
break; | |
case 0: | |
break; | |
default: | |
printf("\n\n#################\nOpção inválida!\n#################\n\n"); | |
return 1; | |
} | |
} while (opcao != 0); | |
printf("Tchau! :)"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment