Advertisement
Guest User

Untitled

a guest
May 28th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <stdio.h>
  6. #include <malloc.h>
  7. #define N 30
  8. #define M 10
  9. typedef struct
  10. {
  11. char id[M];
  12. char name[N];
  13. char family[N];
  14. }passenger;
  15. typedef struct
  16. {
  17. int row;
  18. int chair;
  19. char clas;
  20. char *status;
  21. char *pasport;
  22. struct seat *next;
  23. }seat;
  24. typedef struct
  25. {
  26. int chairs;
  27. int classArows;
  28. seat *listhead;
  29. }plane;
  30. void menu(plane*);
  31. typedef enum{ ticket_order = 1, cancel_order, report_group_passengers, report_not_occupied_seats, Exit }Menu;
  32. void linked_lists(plane*);
  33. void empty(seat*);
  34. int check(plane*,int,int);
  35. int main() {
  36. plane boeing;
  37. do{
  38. printf("Enter number of seats in your plane (minimum 20 seats)\n");
  39. scanf("%d", &boeing.chairs);
  40. if (boeing.chairs < 20)
  41. printf("number of seats must be at least 20\n");
  42. } while (boeing.chairs < 20);
  43. do{
  44. printf("Enter number of rows in 'A' class (beetwen 1-3)\n");
  45. scanf("%d", &boeing.classArows);
  46. if (boeing.classArows <1 || boeing.classArows>3)
  47. printf("number of rows must be beetwen 1-3\n");
  48. } while (boeing.classArows <1 || boeing.classArows>3);
  49. linked_lists(&boeing);
  50. menu(&boeing);
  51. /* build_plane(&boeing);*/
  52. return 0;
  53. }
  54. void menu(plane *boeing)
  55. {
  56. int choose=0,pass=0,yes=0;
  57. char dep=NULL;
  58. 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");
  59. do{
  60. printf("what do you want to do?\nPlease make your choose from the menu\n");
  61. scanf("%d", &choose);
  62. if (choose<1 || choose>5)
  63. printf("please choose beetwen 1-5\n");
  64. } while (choose<1 || choose>5);
  65. switch (choose){
  66.  
  67. case ticket_order:
  68. do{
  69. printf("Enter department code (A-A class or T-T tourist class) for making the order\n");
  70. scanf("%c", &dep);
  71. if (dep != 'T' && dep != 'A')
  72. printf("Wrong choose\n\n\n");
  73. } while (dep != 'T' && dep != 'A');
  74. do{
  75. printf("How many passengers want to fly?\n");
  76. scanf("%d", &pass);
  77. if (pass<1 || pass> boeing->chairs)
  78. printf("Wrong choose\n number of passengers must be beetwin 1 to %d\n", boeing->chairs);
  79. } while (pass<1 || pass> boeing->chairs);
  80. yes=check(boeing,dep,pass);
  81. printf("%d", yes);
  82. break;
  83. case cancel_order:
  84. break;
  85. case report_group_passengers:
  86. break;
  87. case report_not_occupied_seats:
  88. break;
  89. case Exit:
  90. exit(1);
  91. break;
  92. }
  93. }
  94. void linked_lists(plane *boeing)
  95. {
  96. int i,x=1,y=1;
  97. seat *head = NULL;
  98. seat *newseat=NULL;
  99. for (i = 1; i <= boeing->chairs; i++)
  100. {
  101. seat *newseat = (seat*)malloc(sizeof(seat));
  102. if (newseat == NULL)
  103. {
  104. printf("canot allocate memory\n");
  105. exit(1);
  106. }
  107. if (i <= ((boeing->classArows) *(4)))
  108. {
  109. newseat->chair = 2;
  110. newseat->chair = x;
  111. if (newseat->row <= boeing->classArows)
  112. newseat->row = y;
  113. if (x % 4 == 0)
  114. {
  115. x = 0;
  116. y++;
  117. }
  118.  
  119. newseat->clas = 'A';
  120. empty(newseat);
  121.  
  122. }
  123. else
  124. {
  125. newseat->chair = x;
  126. newseat->row = y;
  127. if (x % 6 == 0)
  128. {
  129. x = 0;
  130. y++;
  131. }
  132. newseat->clas = 'T';
  133. empty(newseat);
  134. }
  135. x++;
  136. printf("%d %d %c %s %s\n", newseat->chair, newseat->row, newseat->clas, newseat->status, newseat->pasport);
  137. newseat->next = head;
  138. head = newseat;
  139. }
  140. boeing->listhead = head;
  141. }
  142. void empty(seat *newseat)
  143. {
  144. char temp1[6] = "Empty", temp2[10] = "XXXXXXXXX";
  145. newseat->status = (char*)malloc(strlen(temp1)*sizeof(char)+1);
  146. strcpy(newseat->status, temp1);
  147. newseat->pasport = (char*)malloc(strlen(temp2)*sizeof(char)+1);
  148. strcpy(newseat->pasport, temp2);
  149. }
  150. int check(plane *boeing, int dep, int pass)
  151. {
  152. int i = 1,count=0,x=1;
  153. for (i = 1; i <= boeing->chairs; i++)
  154. {
  155. if (boeing->listhead->clas == dep)
  156. {
  157. if (boeing->listhead->status == "Empty")
  158. count++;
  159. }
  160. boeing->listhead = boeing->listhead->next;
  161. }
  162. if (count >= pass)
  163. return x;
  164. else
  165. {
  166. x = 0;
  167. return x;
  168. }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement