Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #define SEATS 12
- typedef struct
- {
- int seat;
- char first[20];
- char last[20];
- char taken;
- }Seating;
- void SelectionA(Seating *A);
- void SelectionB(Seating *A);
- void SelectionC(Seating *A);
- void SelectionD(Seating *A);
- void SelectionE(Seating *A);
- void SelectionF(Seating *A);
- void file(Seating *A);
- int main(void)
- {
- Seating Plan[SEATS];
- int index;
- file(Plan);
- char input;
- do{
- system("cls");
- printf("\t\tECONO-AIRLINES\t\t");
- puts("");
- printf("a.\t Display ALL seat assignment(including Empty)\n");
- printf("b.\t Show ONLY a list of empty seats and show total of empty seats\n");
- printf("c.\t Show ONLY the assigned seats with name of person and total assigned.\n");
- printf("d.\t Assign the customer to an empty seat.\n");
- printf("e.\t Delete ONE seat assignment.\n");
- printf("f.\t Delete ALL seat assignments.\n");
- printf("q.\t Quit Program.\n\n");
- printf("Input your choice? ");
- scanf("%c",&input);
- fflush(stdin);
- switch(input)
- {
- case 'a' :
- system("cls");
- SelectionA(Plan);
- system("pause");
- break;
- case 'b' :
- system("cls");
- SelectionB(Plan);
- system("pause");
- break;
- case 'c' :
- system("cls");
- SelectionC(Plan);
- system("pause");
- break;
- case 'd' :
- system("cls");
- SelectionD(Plan);
- system("pause");
- break;
- case 'e' :
- system("cls");
- SelectionE(Plan);
- system("pause");
- break;
- case 'f' :
- system("cls");
- SelectionF(Plan);
- system("pause");
- break;
- }}while(input != 'q');
- system("pause");
- return (0);
- }
- void SelectionA(Seating *Plan)
- {
- int index;
- int available = 0;
- FILE *fptr;
- printf("\t\t\tSeating Arrangement\n\n");
- printf("\tSeat #\t\t\tUsed\t\t\t LastName\t\t FirstName\n");
- puts("");
- fptr = fopen("plane1.DAT", "rb");
- for(index=0; index < SEATS; index++)
- {
- fread(&Plan[index], sizeof(Seating), 1, fptr);
- printf("\t %i\t\t\t %c\t\t\t %s\t\t\t %s\n",Plan[index].seat, Plan[index].taken, Plan[index].last, Plan[index].first);
- if (Plan[index].taken == 'n')
- available += 1;
- }
- printf("\nThere are %i Empty Seats.",available);
- fclose(fptr);
- }
- void SelectionB(Seating *Plan)
- {
- int index;
- int available = 0;
- FILE *fptr;
- printf("\t\t\tSeating Arrangement\n\n");
- printf("\tSeat #\t\t\tUsed\t\t\t LastName\t\t\t FirstName\n");
- puts("");
- fptr = fopen("plane1.DAT", "rb");
- for(index=0; index < SEATS; index++)
- {
- fread(&Plan[index], sizeof(Seating), 1, fptr);
- if(Plan[index].taken == 'n')
- {
- printf("\t %i\t\t\t %c\t\t\t %s\t\t\t\t %s\n",Plan[index].seat, Plan[index].taken, Plan[index].last, Plan[index].first);
- available+=1;
- }
- }
- printf("\nThere are %i Empty Seats.",available);
- fclose(fptr);
- }
- void SelectionC(Seating *Plan)
- {
- int index;
- int available = 0;
- FILE *fptr;
- printf("\t\t\tSeating Arrangement\n\n");
- printf("\tSeat #\t\t\tUsed\t\t\t LastName\t\t\t FirstName\n");
- puts("");
- fptr = fopen("plane1.DAT", "rb");
- for(index = 0; index < SEATS; index ++)
- {
- fread(&Plan[index], sizeof(Seating), 1, fptr);
- if(Plan[index].taken == 'y')
- {
- printf("\t %i\t\t\t %c\t\t\t %s\t\t\t\t %s\n",Plan[index].seat, Plan[index].taken, Plan[index].last, Plan[index].first);
- available += 1;
- }
- }
- printf("\nThere are %i ASSIGNED Seats.", available);
- fclose(fptr);
- }
- void SelectionD(Seating *Plan)
- {
- int index;
- int available = 0;
- int choice;
- FILE *fptr;
- printf("The following seats are available -\n");
- fptr = fopen("plane1.DAT", "rb");
- for(index = 0; index < SEATS; index ++)
- {
- if(Plan[index].taken == 'n')
- {
- available += 1;
- printf("\t\n %i",Plan[index].seat);
- }
- }
- printf("\nThere are %i Available Seats\n\n",available);
- printf("Which seat would you like (0 to exit)?");
- scanf("%i",&choice);
- fflush(stdin);
- if(choice == 0)
- {
- system("cls");
- fflush(stdin);
- return;
- }
- else{
- Plan[choice-1].seat = choice;
- Plan[choice-1].taken = 'y';
- printf("Input last name? \n");
- gets(Plan[choice-1].last);
- printf("Input first name? \n");
- gets(Plan[choice-1].first);
- fptr = fopen("plane1.DAT", "wb");
- for (index = 0; index< SEATS; index ++)
- {
- fwrite(&Plan[index], sizeof(Seating), 1, fptr);
- }
- }
- fclose(fptr);
- }
- void SelectionE(Seating *Plan)
- {
- int index;
- int choice;
- int taken=0;
- FILE *fptr;
- printf("Here are the seats you can delete.\n");
- for(index=0; index < SEATS; index++)
- {
- if(Plan[index].taken == 'y')
- {
- taken += 1;
- printf("\n\t%i\t%s\t\t%s\n",Plan[index].seat, Plan[index].last, Plan[index].first);
- }
- }
- printf("\nWhich seat would you like to delete(0 to exit) ");
- scanf("%i",&choice);
- (Plan + choice - 1)->taken = 'n';
- strcpy ((Plan + choice - 1)->first, "SEAT");
- strcpy ((Plan + choice - 1)->last, "EMPTY");
- fptr = fopen("plane1.DAT", "wb");
- for (index = 0; index< SEATS; index++)
- {
- fwrite(&Plan[index], sizeof(Seating), 1, fptr);
- }
- fclose(fptr);
- getchar();
- }
- void SelectionF(Seating *Plan)
- {
- int index;
- int choice;
- int taken=0;
- FILE *fptr;
- printf("Are you sure you would like to delete all seats? (y/n)");
- scanf(" %c",&choice);
- if(choice == 'y')
- {
- fptr = fopen("plane1.DAT", "wb");
- for(index = 0; index < SEATS; index++)
- {
- Plan[index].seat = index+1;
- Plan[index].taken = 'n';
- strcpy (Plan[index].first, "SEAT");
- strcpy (Plan[index].last, "EMPTY");
- fwrite(&Plan[index], sizeof(Seating), 1, fptr);
- }
- printf("All assigned seating have been deleted\n");
- fclose(fptr);
- }
- if(choice == 'n')
- {
- exit;
- }
- }
- void file(Seating *Plan)
- {
- int index;
- FILE *fptr;
- fptr = fopen("plane1.DAT", "rb");
- if (fptr != NULL)
- {
- fclose(fptr);
- }
- else
- {
- fptr = fopen("plane1.DAT", "wb");
- for (index = 0; index < SEATS; index ++)
- {
- Plan[index].seat = index+1;
- Plan[index].taken = 'n';
- strcpy (Plan[index].last, "EMPTY");
- strcpy (Plan[index].first, "SEAT");
- fwrite(&Plan[index], sizeof(Seating), 1, fptr);
- }
- fclose(fptr);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement