AIrline Booking System

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Nov 2009
Posts: 13
Reputation: Bheeman89 is an unknown quantity at this point 
Solved Threads: 0
Bheeman89's Avatar
Bheeman89 Bheeman89 is offline Offline
Newbie Poster

AIrline Booking System

 
0
  #1
32 Days Ago
Hello guys....I just have some doubt about C programming...well I have done a lot of functions for airline booking system but im not able to implement the multi dimensional array... I dont get how should I implement it in this problem as the variables are global and they are used in different functions. So below is just a part of where i am blur on how to use the multidimensional array...here im trying to use 4 dimensional array and I get a lot of errors in it....Hope you guys can help me out....Thanks

  1. void menu_PurchaseTicket()
  2. {
  3. menu_chooseTicket();//a variable is used to store the input here
  4. menu_ChooseDestination();//a variable is used to store the input here
  5. menu_ChooseTime();//a variable is used to store the input here
  6. menu_ViewSeating();//function showing the seats arrangement in rows and columns(5x5)
  7. menu_ChooseSeat();//a variable is used to store the input here
  8.  
  9. int seat[cust_TicketClass][cust_Destination][cust_Time][cust_Seat];
  10. int a,b,c,d;
  11. for(a=0;a<2;a++)
  12. {
  13. if(cust_TicketClass == 0)
  14. printf("Business Class");
  15. else
  16. printf("Economy Class");
  17.  
  18. for(b=0;b<2;b++)
  19. {
  20. if(cust_Destination == 0)
  21. printf("Destination: Kuala Lumpur --> Langkawi\n\n");
  22. else
  23. printf("Destination: Langkawi --> Kuala Lumpur\n\n");
  24.  
  25. for(c=0;c<5;c++)
  26. {
  27. switch(cust_Time)
  28. {
  29. case '1':
  30. printf("Departure Time: 9.00 a.m\n");
  31.  
  32. case '2':
  33. printf("Departure Time: 11.00 a.m\n");
  34.  
  35. case '3':
  36. printf("Departure Time: 1.00 p.m\n");
  37.  
  38. case '4':
  39. printf("Departure Time: 3.00 p.m\n");
  40.  
  41. case '5':
  42. printf("Departure Time: 5.00 p.m\n");
  43.  
  44. default:
  45. printf("Please enter the correct selection\n\n");
  46.  
  47. for(d=0;d<25;d++)
  48. {
  49. if(cust_Seat>25 || cust_Seat<0)
  50. printf("Invalid Seat Number");
  51.  
  52. if(cust_Seat>0 || cust_Seat<25)
  53. seat[cust_TicketClass][cust_Destination][cust_Time][cust_Seat]=1;
  54. }
  55. }
  56. }
  57. }
  58. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,598
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 202
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso
 
0
  #2
32 Days Ago
You should switch to using a struct to represent your ticket class, destination, seat, and time. . All four of those things are obviously related data. You're only going to cause yourself headache trying to use a 4d array for this purpose, and using a 4d array like that doesn't make sense for your data . Why not create a struct to group the related data and then create an array of structs?
Last edited by BestJewSinceJC; 32 Days Ago at 4:41 pm.
Out.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 16
Reputation: venomxxl is an unknown quantity at this point 
Solved Threads: 2
venomxxl's Avatar
venomxxl venomxxl is offline Offline
Newbie Poster
 
0
  #3
32 Days Ago
Can you paste the errors you get? And possibly more code?
By the first look I can advise to use pointers instead of int seat[][][][].
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 13
Reputation: Bheeman89 is an unknown quantity at this point 
Solved Threads: 0
Bheeman89's Avatar
Bheeman89 Bheeman89 is offline Offline
Newbie Poster
 
0
  #4
32 Days Ago
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <conio.h>
  4. void mainmenu(void);
  5. void menu_PurchaseTicket(void);
  6. void menu_chooseTicket(void);
  7. void menu_BizClass(void);
  8. void menu_EconomyClass(void);
  9. void menu_DepartureBizKL(void);
  10. void menu_DepartureBizLK(void);
  11. void menu_DepartureEconKL(void);
  12. void menu_DepartureEconLK(void);
  13. void menu_ViewSeating(void);
  14. void menu_ChooseDestination(void);
  15. void menu_ChooseTime(void);
  16. void menu_ChooseSeat(void);
  17.  
  18. int exit_ViewSeating, cust_TicketClass, cust_Destination, cust_Time, cust_Seat;
  19. char MenuSelect,TicketSelect,BizClassSelect,EconomyClassSelect,ViewSeatingSelect;
  20. main()
  21. {
  22. mainmenu();
  23. }
  24.  
  25. //main menu function
  26. void mainmenu()
  27. {
  28. system("cls");
  29. //print welcome screen
  30. printf("\n\t\t\t\t--WELCOME TO--");
  31. printf("\n\t\t<<<< THALABATHY AIRLINE RESERVATION SYSTEM >>>> \n");
  32.  
  33. printf("\n\n\t\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
  34. printf("\n\t\t\t\t%%%%%% Main Menu %%%%%%%\n");
  35. printf("\t\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
  36.  
  37.  
  38.  
  39. printf("\n\t\t\t\tP to Purchase Ticket\n");
  40. printf("\n\t\t\t\tV to View Seating Arrangement\n");
  41. printf("\n\t\t\t\tQ to Quit the system\n\n");
  42. printf("\n\n\t\t\t\tPlease enter your choice:");
  43. fflush(stdin);
  44. MenuSelect = getchar();
  45.  
  46. switch(MenuSelect)
  47. {
  48.  
  49. case 'P':
  50. case 'p':
  51. menu_PurchaseTicket();
  52. break;
  53.  
  54.  
  55. case 'V':
  56. case 'v':
  57.  
  58. menu_ViewSeating();
  59. break;
  60.  
  61.  
  62. case 'Q':
  63. case 'q':
  64.  
  65. printf("Thank you for choosing Airlines Reservation System");
  66. break;
  67.  
  68.  
  69. default:
  70. printf("Please enter the correct selection");
  71.  
  72.  
  73. }
  74.  
  75. }
  76.  
  77. void menu_PurchaseTicket()
  78. {
  79. menu_chooseTicket();
  80. menu_ChooseDestination();
  81. menu_ChooseTime();
  82. menu_ViewSeating();
  83. menu_ChooseSeat();
  84.  
  85. int seat[cust_TicketClass][cust_Destination][cust_Time][cust_Seat];
  86. int a,b,c,d;
  87. for(a=0;a<2;a++)
  88. {
  89. if(cust_TicketClass == 0)
  90. printf("Business Class");
  91. else
  92. printf("Economy Class");
  93.  
  94. for(b=0;b<2;b++)
  95. {
  96. if(cust_Destination == 0)
  97. printf("Destination: Kuala Lumpur --> Langkawi\n\n");
  98. else
  99. printf("Destination: Langkawi --> Kuala Lumpur\n\n");
  100.  
  101. for(c=0;c<5;c++)
  102. {
  103. switch(cust_Time)
  104. {
  105. case '1':
  106. printf("Departure Time: 9.00 a.m\n");
  107.  
  108. case '2':
  109. printf("Departure Time: 11.00 a.m\n");
  110.  
  111. case '3':
  112. printf("Departure Time: 1.00 p.m\n");
  113.  
  114. case '4':
  115. printf("Departure Time: 3.00 p.m\n");
  116.  
  117. case '5':
  118. printf("Departure Time: 5.00 p.m\n");
  119.  
  120. default:
  121. printf("Please enter the correct selection\n\n");
  122.  
  123. for(d=0;d<25;d++)
  124. {
  125. if(cust_Seat>25 || cust_Seat<0)
  126. printf("Invalid Seat Number");
  127.  
  128. if(cust_Seat>0 || cust_Seat<25)
  129. seat[cust_TicketClass][cust_Destination][cust_Time][cust_Seat]=1;
  130. }
  131. }
  132. }
  133. }
  134. }
  135.  
  136.  
  137. /*system("cls");
  138. printf("PLEASE CHOOSE YOUR TICKET CLASS:\n\n");
  139. printf("B for BUSINESS CLASS SEATS\n\n");
  140. printf("E for ECONOMY CLASS SEATS\n\n");
  141. printf("M for RETURN TO MAIN MENU\n\n");
  142. printf("Please enter your selection -->");
  143. fflush(stdin);
  144. TicketSelect = getchar();
  145.  
  146. switch(TicketSelect)
  147. {
  148. case 'B':
  149. case 'b':
  150. menu_BizClass();
  151. break;
  152.  
  153.  
  154. case 'E':
  155. case 'e':
  156. menu_EconomyClass();
  157. break;
  158.  
  159.  
  160. case 'M':
  161. case 'm':
  162. mainmenu();
  163. break;
  164.  
  165. default:
  166. system("cls");
  167. printf("Please enter the correct selection");
  168. menu_PurchaseTicket();
  169. }*/
  170. }
  171.  
  172. void menu_chooseTicket()
  173. {
  174. system("cls");
  175. printf("Please choose your Tciket Class\n\n");
  176. printf("1 >> Business Class\n\n");
  177. printf("2 >> Economy Class\n\n");
  178. printf("Please enter your selection --> ");
  179. fflush(stdin);
  180. scanf("%d",&cust_TicketClass);
  181.  
  182. }
  183.  
  184. void menu_ChooseDestination()
  185. {
  186. system("cls");
  187. printf("Please choose destination\n\n");
  188. printf("1 >> Kuala Lumpur --> Langkawi\n\n");
  189. printf("2 >> Langkawi --> Kuala Lumpur\n\n");
  190. printf("Please enter your selection --> ");
  191. fflush(stdin);
  192. scanf("%d",&cust_Destination);
  193. }
  194.  
  195. void menu_ChooseTime()
  196. {
  197. system("cls");
  198. printf("Please choose flight time\n\n");
  199. printf("1 >> 9 a.m.\n\n");
  200. printf("2 >> 11 a.m.\n\n");
  201. printf("3 >> 1 p.m.\n\n");
  202. printf("4 >> 3 p.m.\n\n");
  203. printf("5 >> 5 p.m.\n\n");
  204. printf("Please enter your selection --> ");
  205. fflush(stdin);
  206. scanf("%d",&cust_Time);
  207. }
  208.  
  209. void menu_ChooseSeat()
  210. {
  211. printf("Please choose your seat --> ");
  212. scanf("%d",&cust_Seat);
  213.  
  214. }
  215.  
  216.  
  217. void menu_BizClass()
  218. {
  219. system("cls");
  220. printf("Destination Menu\n");
  221. printf("A --> Kuala Lumpur to Langkawi\n");
  222. printf("B --> Langkawi to Kuala Lumpur\n");
  223. printf("M --> Return to Main Menu\n");
  224. printf("Please Enter your Selection -->");
  225. fflush(stdin);
  226. BizClassSelect = getchar();
  227.  
  228. switch(BizClassSelect)
  229. {
  230. case 'a':
  231. case 'A':
  232. menu_DepartureBizKL();
  233. break;
  234.  
  235. case 'b':
  236. case 'B':
  237. menu_DepartureBizLK();
  238. break;
  239.  
  240. case 'M':
  241. case 'm':
  242. mainmenu();
  243. break;
  244.  
  245. default:
  246. system("cls");
  247. printf("Please enter the correct selection");
  248. menu_BizClass();
  249. }
  250.  
  251.  
  252.  
  253. }
  254.  
  255. void menu_EconomyClass()
  256. {
  257. system("cls");
  258. printf("Destination Menu\n");
  259. printf("A --> Kuala Lumpur to Langkawi\n");
  260. printf("B --> Langkawi to Kuala Lumpur\n");
  261. printf("M --> Return to Main Menu\n");
  262. printf("Please Enter your Selection -->");
  263. fflush(stdin);
  264. EconomyClassSelect = getchar();
  265.  
  266. switch(EconomyClassSelect)
  267. {
  268. case 'a':
  269. case 'A':
  270. menu_DepartureEconKL();
  271. break;
  272.  
  273. case 'b':
  274. case 'B':
  275. menu_DepartureEconLK();
  276. break;
  277.  
  278. case 'M':
  279. case 'm':
  280. mainmenu();
  281. break;
  282.  
  283. default:
  284. system("cls");
  285. printf("Please enter the correct selection");
  286. menu_EconomyClass();
  287. }
  288. }
  289.  
  290. void menu_DepartureBizKL()
  291. {
  292. system("cls");
  293. printf("Business Class\n");
  294. printf("Departure Menu\n");
  295. printf("Destination: Kuala Lumpur --> Langkawi\n");
  296. printf("A --> 9.00 a.m\n");
  297. printf("B --> 11.00 a.m\n");
  298. printf("C --> 1.00 p.m\n");
  299. printf("D --> 3.00 p.m\n");
  300. printf("E --> 5.00 p.m\n");
  301. printf("Please enter your selection --> ");
  302.  
  303.  
  304. }
  305.  
  306. void menu_DepartureBizLK()
  307. {
  308. system("cls");
  309. printf("Business Class\n");
  310. printf("Departure Menu\n");
  311. printf("Destination: Langkawi --> Kuala Lumpur\n");
  312. printf("A --> 9.00 a.m\n");
  313. printf("B --> 11.00 a.m\n");
  314. printf("C --> 1.00 p.m\n");
  315. printf("D --> 3.00 p.m\n");
  316. printf("E --> 5.00 p.m\n");
  317. printf("Please enter your selection --> ");
  318.  
  319.  
  320. }
  321.  
  322. void menu_DepartureEconKL()
  323. {
  324. system("cls");
  325. printf("Economy Class\n");
  326. printf("Departure Menu\n");
  327. printf("Destination: Kuala Lumpur --> Langkawi\n");
  328. printf("A --> 9.00 a.m\n");
  329. printf("B --> 11.00 a.m\n");
  330. printf("C --> 1.00 p.m\n");
  331. printf("D --> 3.00 p.m\n");
  332. printf("E --> 5.00 p.m\n");
  333. printf("Please enter your selection --> ");
  334.  
  335.  
  336. }
  337.  
  338. void menu_DepartureEconLK()
  339. {
  340. system("cls");
  341. printf("Economy Class\n");
  342. printf("Departure Menu\n");
  343. printf("Destination: Langkawi --> Kuala Lumpur\n");
  344. printf("A --> 9.00 a.m\n");
  345. printf("B --> 11.00 a.m\n");
  346. printf("C --> 1.00 p.m\n");
  347. printf("D --> 3.00 p.m\n");
  348. printf("E --> 5.00 p.m\n");
  349. printf("Please enter your selection --> ");
  350.  
  351.  
  352. }
  353.  
  354. void menu_ViewSeating()
  355. {
  356. int row,col;
  357. int seats[5][5]={0};
  358. printf("\t\tSeating In All Flights\n\n");
  359. printf("\t1\t2\t3\t4\t5\n");
  360. for (row=0; row<5; row++)
  361. {
  362. printf("\n%d", row+1);
  363. for (col=0; col<5; col++)
  364. {
  365. printf("\t%d", seats[row][col]);
  366. }
  367. }
  368.  
  369.  
  370. printf("\n\nNote: Please choose your seat using row and column format.\n\nFor example:To book seat at row 1 column 3 type 13\n\n");
  371. printf("\n<< Legend >>\n\n");
  372. printf("\n\nBusiness Class Seats: 11,12,13,14,15\n\n");
  373. printf("\n\nEconomy Class Seats: Other than the above\n\n");
  374. }

this is my full code for the program guys..please correct me if there are anything.... =) ur advise are urgently needed....
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,598
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 202
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso
 
0
  #5
32 Days Ago
My advice was to not use a 4 dimensional array when one is not needed. In fact my claim is that using a 4d array in this case is not good programming. If you were to declare a 2d array with this data:

seats where MAX SEATS is 50
people where MAX PEOPLE is 10

You would then have array[10][50] which is 10 arrays of 50 elements each = 500 elements. But you only have 60 elements. It seems to me that the larger your MAX sizes are declared, the more space you are wasting, unless I am either that tired, or your algorithm is that strange. Additionally, using a 4D array is obviously making your program difficult to debug, so why don't you switch to a sensible alternative? If you don't believe me, then wait for the C experts to come in here, they'll be quick to point out (rightfully so) that I'm wrong if I am wrong.
Last edited by BestJewSinceJC; 32 Days Ago at 9:25 pm.
Out.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 13
Reputation: Bheeman89 is an unknown quantity at this point 
Solved Threads: 0
Bheeman89's Avatar
Bheeman89 Bheeman89 is offline Offline
Newbie Poster

Re: Your Post

 
0
  #6
32 Days Ago
Okie brother... but can i knoe wad is the alternative... bcoz here i have 2 flight...25 seats each flight and 5 seats are biz class while other 20 is economy class... Other than dat this flight will be travelling 5 times a day 7 days a week.... so what is ur idea brother.... =) check your inbox brother i have sent u a msg... =) thnkz
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,598
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 202
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso
 
0
  #7
32 Days Ago
Please don't PM daniweb members. Personally I don't mind, but in general, that is the rule here. If people want to help they will respond in your thread. Regarding your PM, if your professor mentioned that it was extra credit to use more than a 2D array, then I must be mistaken about my entire post, so ignore all my posts in this thread. Thanks.
Out.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 13
Reputation: Bheeman89 is an unknown quantity at this point 
Solved Threads: 0
Bheeman89's Avatar
Bheeman89 Bheeman89 is offline Offline
Newbie Poster
 
0
  #8
32 Days Ago
Originally Posted by BestJewSinceJC View Post
Please don't PM daniweb members. Personally I don't mind, but in general, that is the rule here. If people want to help they will respond in your thread. Regarding your PM, if your professor mentioned that it was extra credit to use more than a 2D array, then I must be mistaken about my entire post, so ignore all my posts in this thread. Thanks.
okie brother..im sorry... =) but i didnt mean that u r wrong..there are alternatives ways...i just thought of ur idea arrays of sturct...that will create records ryte...i think its a brilliant idea...maybe i will implement that after consulting from my professor...thnks brother...
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,598
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 202
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso
 
0
  #9
31 Days Ago
no problem. If you want to go that route, I don't see how he could be upset. There are a lot of tutorials online on how to use structs.
Out.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 13
Reputation: Bheeman89 is an unknown quantity at this point 
Solved Threads: 0
Bheeman89's Avatar
Bheeman89 Bheeman89 is offline Offline
Newbie Poster
 
0
  #10
31 Days Ago
Originally Posted by BestJewSinceJC View Post
no problem. If you want to go that route, I don't see how he could be upset. There are a lot of tutorials online on how to use structs.
alryte brother...thnk you..if i have any problem..i will get back to you yea... =)
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC