ME AJUDA URGENTE POR FAVOR PRECISO ENTREGAR ESSE TRABALHO HOJE
---
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <assert.h>
#define SETUP 1
#define BOOKING 2
#define SEARCH 3
#define EXIT 4
#define MAX_SEATS 60
typedef struct Passenger
{
char passenger_name[80];
char document[12];
int chosen_seat;
} Passenger;
typedef struct Flight
{
int free_seats;
struct Passenger *passengers[MAX_SEATS];
} Flight;
void clear_screen()
{
system("CLS");
}
void render_menu(struct Flight *flit)
{
clear_screen();
printf("\n\n ----------------------- ");
printf("\n 1 - Cadastrar assentos disponiveis no voo. %d/%d", flit->free_seats, MAX_SEATS);
printf("\n 2 - Reservar uma passagem. ");
printf("\n 3 - Consultar reserva. ");
printf("\n 4 - Fechar Programa ");
printf("\n\n Escolha uma opcao: ");
}
int read_decimal()
{
int dec;
scanf("%d", &dec);
return dec;
}
void setup(struct Flight *flit)
{
clear_screen();
if (flit->free_seats > 0)
{
printf("\n O Voo ja possui %d assentos disponiveis. Deseja atualizar? [S/N] ", flit->free_seats);
char resp;
scanf(" %c", &resp);
if (resp == 'S')
{
flit->free_seats = 0;
setup(flit);
return;
}
else
{
return;
}
}
printf("\n Digite a quantidade de assentos disponiveis para o voo: ");
int seats = read_decimal();
if (seats <= MAX_SEATS)
{
flit->free_seats = seats;
return;
}
else
{
printf("\n ATENCAO: O Voo suporta somente %d assentos.\n", MAX_SEATS);
system("PAUSE");
setup(flit);
}
}
struct Passenger *passenger_create(int seat)
{
struct Passenger *pass = malloc(sizeof(struct Passenger));
assert(pass != NULL);
char resp[80];
pass->chosen_seat = seat;
printf("\n Digite o nome do passageiro: ");
scanf("%s", resp);
strcpy(pass->passenger_name, resp);
printf("\n Digite o numero do RG: ");
scanf("%s", resp);
strcpy(pass->document, resp);
return pass;
}
void book(struct Flight *flit)
{
clear_screen();
if (flit->free_seats == 0)
{
printf("\n Voo lotado! ");
syste("PAUSE");
return;
}
printf("\n Escolha uma poltrona: ");
int chosen_seat = read_decimal();
if (chosen_seat < 0 || chosen_seat > 60)
{
printf("\n Escolha uma poltrona entre 1 e %d! ", MAX_SEATS);
syste("PAUSE");
book(flit);
return;
}
// A escolha da poltrona começa em 1 mas o array é 0 index.
chosen_seat -= 1;
flit->passengers[chosen_seat] = passenger_create(chosen_seat);
printf("\n Passageiro %s reservado na poltrona %d.", flit->passengers[chosen_seat]->passenger_name, flit->passengers[chosen_seat]->chosen_seat);
syste("PAUSE");
}
int main(int argc, char** argv)
{
int option = 0, i;
struct Flight *flit = malloc(sizeof(struct Flight));
flit->free_seats = 0;
for ( i=0; i < MAX_SEATS; i++)
{
flit->passengers[i] = NULL;
}
while (option != EXIT)
{
render_menu(flit);
option = read_decimal();
switch (option)
{
case SETUP:
setup(flit);
break;
case BOOKING:
book(flit);
default:
break;
}
}
return (EXIT_SUCCESS);
}
---
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <assert.h>
#define SETUP 1
#define BOOKING 2
#define SEARCH 3
#define EXIT 4
#define MAX_SEATS 60
typedef struct Passenger
{
char passenger_name[80];
char document[12];
int chosen_seat;
} Passenger;
typedef struct Flight
{
int free_seats;
struct Passenger *passengers[MAX_SEATS];
} Flight;
void clear_screen()
{
system("CLS");
}
void render_menu(struct Flight *flit)
{
clear_screen();
printf("\n\n ----------------------- ");
printf("\n 1 - Cadastrar assentos disponiveis no voo. %d/%d", flit->free_seats, MAX_SEATS);
printf("\n 2 - Reservar uma passagem. ");
printf("\n 3 - Consultar reserva. ");
printf("\n 4 - Fechar Programa ");
printf("\n\n Escolha uma opcao: ");
}
int read_decimal()
{
int dec;
scanf("%d", &dec);
return dec;
}
void setup(struct Flight *flit)
{
clear_screen();
if (flit->free_seats > 0)
{
printf("\n O Voo ja possui %d assentos disponiveis. Deseja atualizar? [S/N] ", flit->free_seats);
char resp;
scanf(" %c", &resp);
if (resp == 'S')
{
flit->free_seats = 0;
setup(flit);
return;
}
else
{
return;
}
}
printf("\n Digite a quantidade de assentos disponiveis para o voo: ");
int seats = read_decimal();
if (seats <= MAX_SEATS)
{
flit->free_seats = seats;
return;
}
else
{
printf("\n ATENCAO: O Voo suporta somente %d assentos.\n", MAX_SEATS);
system("PAUSE");
setup(flit);
}
}
struct Passenger *passenger_create(int seat)
{
struct Passenger *pass = malloc(sizeof(struct Passenger));
assert(pass != NULL);
char resp[80];
pass->chosen_seat = seat;
printf("\n Digite o nome do passageiro: ");
scanf("%s", resp);
strcpy(pass->passenger_name, resp);
printf("\n Digite o numero do RG: ");
scanf("%s", resp);
strcpy(pass->document, resp);
return pass;
}
void book(struct Flight *flit)
{
clear_screen();
if (flit->free_seats == 0)
{
printf("\n Voo lotado! ");
syste("PAUSE");
return;
}
printf("\n Escolha uma poltrona: ");
int chosen_seat = read_decimal();
if (chosen_seat < 0 || chosen_seat > 60)
{
printf("\n Escolha uma poltrona entre 1 e %d! ", MAX_SEATS);
syste("PAUSE");
book(flit);
return;
}
// A escolha da poltrona começa em 1 mas o array é 0 index.
chosen_seat -= 1;
flit->passengers[chosen_seat] = passenger_create(chosen_seat);
printf("\n Passageiro %s reservado na poltrona %d.", flit->passengers[chosen_seat]->passenger_name, flit->passengers[chosen_seat]->chosen_seat);
syste("PAUSE");
}
int main(int argc, char** argv)
{
int option = 0, i;
struct Flight *flit = malloc(sizeof(struct Flight));
flit->free_seats = 0;
for ( i=0; i < MAX_SEATS; i++)
{
flit->passengers[i] = NULL;
}
while (option != EXIT)
{
render_menu(flit);
option = read_decimal();
switch (option)
{
case SETUP:
setup(flit);
break;
case BOOKING:
book(flit);
default:
break;
}
}
return (EXIT_SUCCESS);
}