佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1023|回复: 2

C Language : Airline Reservations System [已解决]

[复制链接]
发表于 7-10-2008 01:41 AM | 显示全部楼层 |阅读模式

Write a program to assign seats on each flight of the airline’s only plane (capacity: 10 seats)
Your program should display the following menu of alternatives:

Please type 1 for “smoking”


Please type 2 for “nonsmoking”

If the person types 1, then your program should assign a seat in the smoking section (seats 1-5). If the person types 2, then your program should assign a seat in the nonsmoking section (seats 6-10). Your program should then print a boarding pass indicating the person’s seat number and whether it is in the smoking or nonsmoking section of the plane.
Use a single-subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 to indicate that the seat is no longer available.
Your program should, of course, never assign a seat that has already been assigned. When the smoking section is full, your program should ask the person if it is acceptable to be placed in the nonsmoking section (and vice versa). If yes, then make the appropriate seat assignment. If no, then print the message”Next flight leaves in 3 hours”.

以下是我不健全的答案

  1. #include <stdio.h>
  2. int main(int argc, char* argv[])
  3. {
  4. int smoking[5] = { 0 };
  5. int nonsmoking[5] = { 0 };
  6. int assigned = 0;
  7. int opt;
  8. int *seat_class = 0;
  9. int found = 0;
  10. int i=0;
  11. while (1)
  12. {
  13.   printf("\n==============================================\n";
  14.   printf("Welcome to AirAsia Airline Reservations System\n";
  15.   printf("==============================================\n";
  16.   printf("lease type 1 for "smoking". \n";
  17.   printf("lease type 2 for "nonsmoking". \n";
  18.   scanf("%d",&opt);
  19.   if (opt == 1)
  20.    seat_class = smoking;
  21.   else if (opt == 2)
  22.    seat_class = nonsmoking;
  23.   else
  24.    printf("Invalid Input\n";
  25.   
  26.   for (i=0; i<5; i++)
  27.   {
  28.    if (seat_class == 0)
  29.    {
  30.     found++;
  31.     assigned++;
  32.     seat_class++;
  33.     printf("\n=================================\n";
  34.     printf("==========BOARDING PASS==========\n";
  35.     printf("=================================\n";
  36.     if(seat_class == smoking)
  37.     {
  38.      printf("\nDear Customer Your Seat number is %d.\n",i+1);
  39.      printf("Your seat is in the Smoking section of the plane.\n";
  40.     }
  41.     else
  42.     {
  43.      printf("Dear Customer Your Seat number is %d.\n",i+6);
  44.      printf("Your seat is in the Smoking section of the plane.\n";
  45.     }
  46.     if (assigned >= 10)
  47.      printf("+++++++++++++++++++++\n";
  48.     break;
  49.    }
  50.   }
  51.   if (!found)
  52.    printf("\n*** This section is full ***\n";
  53. }
  54. // getch();
  55. return 0;
  56. }
复制代码
请大家指点迷津~
谢谢!~

[ 本帖最后由 蜡笔小烦 于 18-10-2008 03:28 PM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 7-10-2008 01:50 AM | 显示全部楼层
Please type 1 for “smoking”

Please type 2 for “nonsmoking”
If the person types 1, then your program should assign a seat in the smoking section (seats 1-5). If the person types 2, then your program should assign a seat in the nonsmoking section (seats 6-10). Your program should then print a boarding pass indicating the person’s seat number and whether it is in the smoking or nonsmoking section of the plane.
我也是programming的学生
请多多指教
回复

使用道具 举报

 楼主| 发表于 15-10-2008 06:34 PM | 显示全部楼层
  1. #include

  2. int check_all_seats_full();
  3. int check_smoking_seat_full();
  4. int check_nonsmoking_seat_full();

  5. int passenger_seats[10] = {0,0,0,0,0,0,0,0,0,0}; // global variable
  6. // array index 0-4 is array index for smoking area
  7. int smoking_seats_limit_lb = 0; // array index, lb means lower bound
  8. int smoking_seats_limit_up = 4; // array index, up means upper bound

  9. // array index 5-9 is array index for smoking area
  10. int nonsmoking_seats_limit_lb = 5; // array index, lb - lower bound
  11. int nonsmoking_seats_limit_up = 9; // array index, up - upper bound

  12. int main()
  13. {

  14. int all_seats_full;
  15. int smoking_seats_full;
  16. int nonsmoking_seats_full;

  17. char c, c_seat_choice;

  18. printf("==========================\n");
  19. printf("Welcome to Asia Airline\n");
  20. printf("==========================\n");
  21. printf("\n");

  22. /* check seats full */
  23. do
  24. {
  25. all_seats_full = check_all_seats_full();
  26. smoking_seats_full = check_smoking_seat_full();
  27. nonsmoking_seats_full = check_nonsmoking_seat_full();

  28. if(all_seats_full == 1)
  29. {
  30. printf("All seats are full. Next flight is at 3 hours later\n");
  31. printf("Exit the system? N/Y : ");
  32. c = getchar();

  33. }
  34. else
  35. {
  36. printf("===============Seat Status==============\n");

  37. printf("Smoking seats are currently %s\n", smoking_seats_full==1 ? "full" : "not full");
  38. printf("Nonsmoking seats are currently %s\n", nonsmoking_seats_full==1 ? "full" : "not full");
  39. printf("\n");

  40. printf("Press 1 for Smoking Area\n");
  41. printf("Press 2 for Non-Smoking Area\n");
  42. printf("Press q/Q to exit the system\n");
  43. c = getchar();

  44. if(c=='1')
  45. {
  46. if(smoking_seats_full==1)
  47. {
  48. printf("Smoking seats are currently full. Would you mind to take the nonsmoking area seat?\nAnswer (N/Y): ");
  49. c_seat_choice = getchar();

  50. // if yes, assign the seat by changing the array value to from 0 to 1 in the smoking area one( index 0 to 4)
  51. // if no, printf("Next flight leaves in 3 hours\n");
  52. }
  53. else
  54. {
  55. // assign the seat by changing the array value to from 0 to 1 in the smoking area one( index 0 to 4)
  56. }
  57. }
  58. else if(c=='2')
  59. {
  60. if(nonsmoking_seats_full==1)
  61. {
  62. printf("Nonsmoking seats are currently full. Would you mind to take the smoking area seat?\nAnswer (N/Y): ");
  63. c_seat_choice = getchar();

  64. // if yes, assign the seat by changing the array value to from 0 to 1 in the smoking area one( index 5 to 9)
  65. // if no, printf("Next flight leaves in 3 hours\n");

  66. }
  67. else
  68. {

  69. }


  70. }
  71. else if(c=='q' || c=='Q')
  72. {
  73. printf("Exiting system\n");
  74. }
  75. else
  76. {
  77. printf("Invalid Input. Please try again\n");
  78. }
  79. }



  80. }while((c=='y' || c=='Y') && (c!='q' || c!='Q'));





  81. return 0;
  82. }


  83. int check_all_seats_full()
  84. {

  85. int full = 1; // 0 means not full, 1 means full. initially, assume is full. just an assumption
  86. // so that variable 'full' has a default value to start with

  87. int i;

  88. for(i=smoking_seats_limit_lb; i < 10; i++)
  89. {
  90. if(passenger_seats[i]==0)
  91. { // got one seat is empty
  92. full = 0;
  93. break;
  94. }
  95. }

  96. return full;
  97. }

  98. int check_smoking_seat_full()
  99. {

  100. int full = 1; // same comments as in check_all_seats_full

  101. int i;

  102. for(i = smoking_seats_limit_lb ; i <= smoking_seats_limit_up ; i++ )
  103. {
  104. if(passenger_seats[i]==0)
  105. { // got one seat is empty
  106. full = 0;
  107. break;
  108. }
  109. }

  110. return full;
  111. }

  112. int check_nonsmoking_seat_full()
  113. {

  114. int full = 1; // same comments

  115. int i;

  116. for(i = nonsmoking_seats_limit_lb ; i <= nonsmoking_seats_limit_up ; i++ )
  117. {
  118. if(passenger_seats[i]==0) // got one seat is empty
  119. {
  120. full = 0;
  121. break;
  122. }
  123. }


  124. return full;

  125. }
复制代码


好一题填充题~
能了解却做不出来。。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 23-12-2025 04:33 PM , Processed in 0.126040 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表