Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include <malloc.h>
- #define N 30
- #define M 10
- typedef struct
- {
- char id[M];
- char name[N];
- char family[N];
- }passenger;
- typedef struct
- {
- int row;
- int chair;
- char clas;
- char *status;
- char *pasport;
- struct seat *next;
- }seat;
- typedef struct
- {
- int chairs;
- int classArows;
- seat *listhead;
- }plane;
- void menu(plane*);
- typedef enum{ ticket_order = 1, cancel_order, report_group_passengers, report_not_occupied_seats, Exit }Menu;
- void linked_lists(plane*);
- void empty(seat*);
- int check(plane*,int,int);
- int main() {
- plane boeing;
- do{
- printf("Enter number of seats in your plane (minimum 20 seats)\n");
- scanf("%d", &boeing.chairs);
- if (boeing.chairs < 20)
- printf("number of seats must be at least 20\n");
- } while (boeing.chairs < 20);
- do{
- printf("Enter number of rows in 'A' class (beetwen 1-3)\n");
- scanf("%d", &boeing.classArows);
- if (boeing.classArows <1 || boeing.classArows>3)
- printf("number of rows must be beetwen 1-3\n");
- } while (boeing.classArows <1 || boeing.classArows>3);
- linked_lists(&boeing);
- menu(&boeing);
- /* build_plane(&boeing);*/
- return 0;
- }
- void menu(plane *boeing)
- {
- int choose=0,pass=0,yes=0;
- char dep=NULL;
- printf("\n\nMenu:\n1-To make an order of tickets\n2-Cancel tickets order\n3-Producing tickets report for Group of Passengers\n4-Producing a report of not occupied seats\n5-Exit\n\n");
- do{
- printf("what do you want to do?\nPlease make your choose from the menu\n");
- scanf("%d", &choose);
- if (choose<1 || choose>5)
- printf("please choose beetwen 1-5\n");
- } while (choose<1 || choose>5);
- switch (choose){
- case ticket_order:
- do{
- printf("Enter department code (A-A class or T-T tourist class) for making the order\n");
- scanf("%c", &dep);
- if (dep != 'T' && dep != 'A')
- printf("Wrong choose\n\n\n");
- } while (dep != 'T' && dep != 'A');
- do{
- printf("How many passengers want to fly?\n");
- scanf("%d", &pass);
- if (pass<1 || pass> boeing->chairs)
- printf("Wrong choose\n number of passengers must be beetwin 1 to %d\n", boeing->chairs);
- } while (pass<1 || pass> boeing->chairs);
- yes=check(boeing,dep,pass);
- printf("%d", yes);
- break;
- case cancel_order:
- break;
- case report_group_passengers:
- break;
- case report_not_occupied_seats:
- break;
- case Exit:
- exit(1);
- break;
- }
- }
- void linked_lists(plane *boeing)
- {
- int i,x=1,y=1;
- seat *head = NULL;
- seat *newseat=NULL;
- for (i = 1; i <= boeing->chairs; i++)
- {
- seat *newseat = (seat*)malloc(sizeof(seat));
- if (newseat == NULL)
- {
- printf("canot allocate memory\n");
- exit(1);
- }
- if (i <= ((boeing->classArows) *(4)))
- {
- newseat->chair = 2;
- newseat->chair = x;
- if (newseat->row <= boeing->classArows)
- newseat->row = y;
- if (x % 4 == 0)
- {
- x = 0;
- y++;
- }
- newseat->clas = 'A';
- empty(newseat);
- }
- else
- {
- newseat->chair = x;
- newseat->row = y;
- if (x % 6 == 0)
- {
- x = 0;
- y++;
- }
- newseat->clas = 'T';
- empty(newseat);
- }
- x++;
- printf("%d %d %c %s %s\n", newseat->chair, newseat->row, newseat->clas, newseat->status, newseat->pasport);
- newseat->next = head;
- head = newseat;
- }
- boeing->listhead = head;
- }
- void empty(seat *newseat)
- {
- char temp1[6] = "Empty", temp2[10] = "XXXXXXXXX";
- newseat->status = (char*)malloc(strlen(temp1)*sizeof(char)+1);
- strcpy(newseat->status, temp1);
- newseat->pasport = (char*)malloc(strlen(temp2)*sizeof(char)+1);
- strcpy(newseat->pasport, temp2);
- }
- int check(plane *boeing, int dep, int pass)
- {
- int i = 1,count=0,x=1;
- for (i = 1; i <= boeing->chairs; i++)
- {
- if (boeing->listhead->clas == dep)
- {
- if (boeing->listhead->status == "Empty")
- count++;
- }
- boeing->listhead = boeing->listhead->next;
- }
- if (count >= pass)
- return x;
- else
- {
- x = 0;
- return x;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement