Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.19 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <string.h>
  5. #define SEATS 12
  6.  
  7. typedef struct
  8. {
  9. int seat;
  10. char first[20];
  11. char last[20];
  12. char taken;
  13. }Seating;
  14.  
  15. void SelectionA(Seating *A);
  16. void SelectionB(Seating *A);
  17. void SelectionC(Seating *A);
  18. void SelectionD(Seating *A);
  19. void SelectionE(Seating *A);
  20. void SelectionF(Seating *A);
  21. void file(Seating *A);
  22.  
  23. int main(void)
  24. {
  25.  
  26.  
  27.  
  28. Seating Plan[SEATS];
  29. int index;
  30. file(Plan);
  31. char input;
  32.  
  33.  
  34.  
  35. do{
  36.  
  37. system("cls");
  38.  
  39. printf("\t\tECONO-AIRLINES\t\t");
  40. puts("");
  41. printf("a.\t Display ALL seat assignment(including Empty)\n");
  42. printf("b.\t Show ONLY a list of empty seats and show total of empty seats\n");
  43. printf("c.\t Show ONLY the assigned seats with name of person and total assigned.\n");
  44. printf("d.\t Assign the customer to an empty seat.\n");
  45. printf("e.\t Delete ONE seat assignment.\n");
  46. printf("f.\t Delete ALL seat assignments.\n");
  47. printf("q.\t Quit Program.\n\n");
  48. printf("Input your choice? ");
  49.  
  50. scanf("%c",&input);
  51. fflush(stdin);
  52.  
  53. switch(input)
  54. {
  55. case 'a' :
  56. system("cls");
  57. SelectionA(Plan);
  58. system("pause");
  59. break;
  60. case 'b' :
  61. system("cls");
  62. SelectionB(Plan);
  63. system("pause");
  64. break;
  65. case 'c' :
  66. system("cls");
  67. SelectionC(Plan);
  68. system("pause");
  69. break;
  70. case 'd' :
  71. system("cls");
  72. SelectionD(Plan);
  73. system("pause");
  74. break;
  75. case 'e' :
  76. system("cls");
  77. SelectionE(Plan);
  78. system("pause");
  79. break;
  80. case 'f' :
  81. system("cls");
  82. SelectionF(Plan);
  83. system("pause");
  84. break;
  85.  
  86.  
  87. }}while(input != 'q');
  88.  
  89.  
  90.  
  91.  
  92. system("pause");
  93. return (0);
  94.  
  95. }
  96.  
  97.  
  98. void SelectionA(Seating *Plan)
  99. {
  100.  
  101.  
  102.  
  103.  
  104. int index;
  105. int available = 0;
  106. FILE *fptr;
  107.  
  108. printf("\t\t\tSeating Arrangement\n\n");
  109. printf("\tSeat #\t\t\tUsed\t\t\t LastName\t\t FirstName\n");
  110. puts("");
  111.  
  112. fptr = fopen("plane1.DAT", "rb");
  113.  
  114. for(index=0; index < SEATS; index++)
  115. {
  116. fread(&Plan[index], sizeof(Seating), 1, fptr);
  117. 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);
  118. if (Plan[index].taken == 'n')
  119. available += 1;
  120. }
  121.  
  122. printf("\nThere are %i Empty Seats.",available);
  123. fclose(fptr);
  124.  
  125.  
  126.  
  127. }
  128.  
  129.  
  130. void SelectionB(Seating *Plan)
  131. {
  132.  
  133.  
  134. int index;
  135. int available = 0;
  136. FILE *fptr;
  137.  
  138. printf("\t\t\tSeating Arrangement\n\n");
  139. printf("\tSeat #\t\t\tUsed\t\t\t LastName\t\t\t FirstName\n");
  140. puts("");
  141.  
  142. fptr = fopen("plane1.DAT", "rb");
  143.  
  144. for(index=0; index < SEATS; index++)
  145. {
  146. fread(&Plan[index], sizeof(Seating), 1, fptr);
  147. if(Plan[index].taken == 'n')
  148. {
  149. 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);
  150. available+=1;
  151. }
  152.  
  153. }
  154.  
  155. printf("\nThere are %i Empty Seats.",available);
  156. fclose(fptr);
  157.  
  158.  
  159.  
  160.  
  161. }
  162.  
  163.  
  164. void SelectionC(Seating *Plan)
  165. {
  166.  
  167. int index;
  168. int available = 0;
  169. FILE *fptr;
  170.  
  171. printf("\t\t\tSeating Arrangement\n\n");
  172. printf("\tSeat #\t\t\tUsed\t\t\t LastName\t\t\t FirstName\n");
  173. puts("");
  174. fptr = fopen("plane1.DAT", "rb");
  175. for(index = 0; index < SEATS; index ++)
  176. {
  177. fread(&Plan[index], sizeof(Seating), 1, fptr);
  178. if(Plan[index].taken == 'y')
  179. {
  180. 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);
  181. available += 1;
  182. }
  183. }
  184.  
  185. printf("\nThere are %i ASSIGNED Seats.", available);
  186. fclose(fptr);
  187.  
  188. }
  189.  
  190. void SelectionD(Seating *Plan)
  191. {
  192.  
  193.  
  194.  
  195. int index;
  196. int available = 0;
  197. int choice;
  198. FILE *fptr;
  199. printf("The following seats are available -\n");
  200. fptr = fopen("plane1.DAT", "rb");
  201.  
  202. for(index = 0; index < SEATS; index ++)
  203. {
  204. if(Plan[index].taken == 'n')
  205. {
  206. available += 1;
  207. printf("\t\n %i",Plan[index].seat);
  208. }
  209. }
  210.  
  211.  
  212. printf("\nThere are %i Available Seats\n\n",available);
  213.  
  214. printf("Which seat would you like (0 to exit)?");
  215. scanf("%i",&choice);
  216. fflush(stdin);
  217.  
  218.  
  219. if(choice == 0)
  220. {
  221. system("cls");
  222. fflush(stdin);
  223. return;
  224. }
  225. else{
  226.  
  227. Plan[choice-1].seat = choice;
  228. Plan[choice-1].taken = 'y';
  229. printf("Input last name? \n");
  230. gets(Plan[choice-1].last);
  231. printf("Input first name? \n");
  232. gets(Plan[choice-1].first);
  233.  
  234. fptr = fopen("plane1.DAT", "wb");
  235. for (index = 0; index< SEATS; index ++)
  236. {
  237. fwrite(&Plan[index], sizeof(Seating), 1, fptr);
  238. }
  239.  
  240.  
  241. }
  242. fclose(fptr);
  243. }
  244.  
  245.  
  246. void SelectionE(Seating *Plan)
  247. {
  248. int index;
  249. int choice;
  250. int taken=0;
  251. FILE *fptr;
  252.  
  253.  
  254.  
  255. printf("Here are the seats you can delete.\n");
  256.  
  257. for(index=0; index < SEATS; index++)
  258. {
  259. if(Plan[index].taken == 'y')
  260. {
  261. taken += 1;
  262. printf("\n\t%i\t%s\t\t%s\n",Plan[index].seat, Plan[index].last, Plan[index].first);
  263. }
  264. }
  265.  
  266. printf("\nWhich seat would you like to delete(0 to exit) ");
  267. scanf("%i",&choice);
  268.  
  269. (Plan + choice - 1)->taken = 'n';
  270. strcpy ((Plan + choice - 1)->first, "SEAT");
  271. strcpy ((Plan + choice - 1)->last, "EMPTY");
  272. fptr = fopen("plane1.DAT", "wb");
  273. for (index = 0; index< SEATS; index++)
  274. {
  275. fwrite(&Plan[index], sizeof(Seating), 1, fptr);
  276. }
  277. fclose(fptr);
  278.  
  279.  
  280. getchar();
  281. }
  282.  
  283. void SelectionF(Seating *Plan)
  284. {
  285. int index;
  286. int choice;
  287. int taken=0;
  288. FILE *fptr;
  289.  
  290.  
  291. printf("Are you sure you would like to delete all seats? (y/n)");
  292. scanf(" %c",&choice);
  293.  
  294.  
  295. if(choice == 'y')
  296. {
  297. fptr = fopen("plane1.DAT", "wb");
  298. for(index = 0; index < SEATS; index++)
  299. {
  300. Plan[index].seat = index+1;
  301. Plan[index].taken = 'n';
  302. strcpy (Plan[index].first, "SEAT");
  303. strcpy (Plan[index].last, "EMPTY");
  304. fwrite(&Plan[index], sizeof(Seating), 1, fptr);
  305. }
  306. printf("All assigned seating have been deleted\n");
  307. fclose(fptr);
  308. }
  309. if(choice == 'n')
  310. {
  311. exit;
  312. }
  313.  
  314. }
  315.  
  316.  
  317. void file(Seating *Plan)
  318. {
  319. int index;
  320.  
  321. FILE *fptr;
  322.  
  323. fptr = fopen("plane1.DAT", "rb");
  324.  
  325. if (fptr != NULL)
  326. {
  327. fclose(fptr);
  328. }
  329.  
  330.  
  331. else
  332. {
  333. fptr = fopen("plane1.DAT", "wb");
  334. for (index = 0; index < SEATS; index ++)
  335. {
  336. Plan[index].seat = index+1;
  337. Plan[index].taken = 'n';
  338. strcpy (Plan[index].last, "EMPTY");
  339. strcpy (Plan[index].first, "SEAT");
  340. fwrite(&Plan[index], sizeof(Seating), 1, fptr);
  341. }
  342. fclose(fptr);
  343.  
  344. }
  345.  
  346. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement