|
查看: 1023|回复: 2
|
C Language : Airline Reservations System [已解决]
[复制链接]
|
|
|
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”.
以下是我不健全的答案 -
- #include <stdio.h>
- int main(int argc, char* argv[])
- {
- int smoking[5] = { 0 };
- int nonsmoking[5] = { 0 };
- int assigned = 0;
- int opt;
- int *seat_class = 0;
- int found = 0;
- int i=0;
- while (1)
- {
- printf("\n==============================================\n";
- printf("Welcome to AirAsia Airline Reservations System\n";
- printf("==============================================\n";
- printf("lease type 1 for "smoking". \n";
- printf("lease type 2 for "nonsmoking". \n";
- scanf("%d",&opt);
- if (opt == 1)
- seat_class = smoking;
- else if (opt == 2)
- seat_class = nonsmoking;
- else
- printf("Invalid Input\n";
-
- for (i=0; i<5; i++)
- {
- if (seat_class == 0)
- {
- found++;
- assigned++;
- seat_class++;
- printf("\n=================================\n";
- printf("==========BOARDING PASS==========\n";
- printf("=================================\n";
- if(seat_class == smoking)
- {
- printf("\nDear Customer Your Seat number is %d.\n",i+1);
- printf("Your seat is in the Smoking section of the plane.\n";
- }
- else
- {
- printf("Dear Customer Your Seat number is %d.\n",i+6);
- printf("Your seat is in the Smoking section of the plane.\n";
- }
- if (assigned >= 10)
- printf("+++++++++++++++++++++\n";
- break;
- }
- }
- if (!found)
- printf("\n*** This section is full ***\n";
- }
- // getch();
- return 0;
- }
复制代码 请大家指点迷津~
谢谢!~
[ 本帖最后由 蜡笔小烦 于 18-10-2008 03:28 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 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
|
显示全部楼层
- #include
- int check_all_seats_full();
- int check_smoking_seat_full();
- int check_nonsmoking_seat_full();
- int passenger_seats[10] = {0,0,0,0,0,0,0,0,0,0}; // global variable
- // array index 0-4 is array index for smoking area
- int smoking_seats_limit_lb = 0; // array index, lb means lower bound
- int smoking_seats_limit_up = 4; // array index, up means upper bound
- // array index 5-9 is array index for smoking area
- int nonsmoking_seats_limit_lb = 5; // array index, lb - lower bound
- int nonsmoking_seats_limit_up = 9; // array index, up - upper bound
- int main()
- {
- int all_seats_full;
- int smoking_seats_full;
- int nonsmoking_seats_full;
- char c, c_seat_choice;
- printf("==========================\n");
- printf("Welcome to Asia Airline\n");
- printf("==========================\n");
- printf("\n");
- /* check seats full */
- do
- {
- all_seats_full = check_all_seats_full();
- smoking_seats_full = check_smoking_seat_full();
- nonsmoking_seats_full = check_nonsmoking_seat_full();
- if(all_seats_full == 1)
- {
- printf("All seats are full. Next flight is at 3 hours later\n");
- printf("Exit the system? N/Y : ");
- c = getchar();
- }
- else
- {
- printf("===============Seat Status==============\n");
- printf("Smoking seats are currently %s\n", smoking_seats_full==1 ? "full" : "not full");
- printf("Nonsmoking seats are currently %s\n", nonsmoking_seats_full==1 ? "full" : "not full");
- printf("\n");
- printf("Press 1 for Smoking Area\n");
- printf("Press 2 for Non-Smoking Area\n");
- printf("Press q/Q to exit the system\n");
- c = getchar();
- if(c=='1')
- {
- if(smoking_seats_full==1)
- {
- printf("Smoking seats are currently full. Would you mind to take the nonsmoking area seat?\nAnswer (N/Y): ");
- c_seat_choice = getchar();
- // if yes, assign the seat by changing the array value to from 0 to 1 in the smoking area one( index 0 to 4)
- // if no, printf("Next flight leaves in 3 hours\n");
- }
- else
- {
- // assign the seat by changing the array value to from 0 to 1 in the smoking area one( index 0 to 4)
- }
- }
- else if(c=='2')
- {
- if(nonsmoking_seats_full==1)
- {
- printf("Nonsmoking seats are currently full. Would you mind to take the smoking area seat?\nAnswer (N/Y): ");
- c_seat_choice = getchar();
- // if yes, assign the seat by changing the array value to from 0 to 1 in the smoking area one( index 5 to 9)
- // if no, printf("Next flight leaves in 3 hours\n");
- }
- else
- {
- }
- }
- else if(c=='q' || c=='Q')
- {
- printf("Exiting system\n");
- }
- else
- {
- printf("Invalid Input. Please try again\n");
- }
- }
- }while((c=='y' || c=='Y') && (c!='q' || c!='Q'));
- return 0;
- }
- int check_all_seats_full()
- {
- int full = 1; // 0 means not full, 1 means full. initially, assume is full. just an assumption
- // so that variable 'full' has a default value to start with
- int i;
- for(i=smoking_seats_limit_lb; i < 10; i++)
- {
- if(passenger_seats[i]==0)
- { // got one seat is empty
- full = 0;
- break;
- }
- }
- return full;
- }
- int check_smoking_seat_full()
- {
- int full = 1; // same comments as in check_all_seats_full
- int i;
- for(i = smoking_seats_limit_lb ; i <= smoking_seats_limit_up ; i++ )
- {
- if(passenger_seats[i]==0)
- { // got one seat is empty
- full = 0;
- break;
- }
- }
- return full;
- }
- int check_nonsmoking_seat_full()
- {
- int full = 1; // same comments
- int i;
- for(i = nonsmoking_seats_limit_lb ; i <= nonsmoking_seats_limit_up ; i++ )
- {
- if(passenger_seats[i]==0) // got one seat is empty
- {
- full = 0;
- break;
- }
- }
- return full;
- }
复制代码
好一题填充题~
能了解却做不出来。。。。 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|