航空机票预订c#代码
Problem statement: Write a program to assign passengers seats in an airplane. Assume a small airplane with seat numbering as follows:
问题陈述:编写一个程序来分配飞机上的乘客座位。 假设小型飞机的座位编号如下:
1 A B C D
2 A B C D
3 A B C D
4 A B C D
5 A B C D
6 A B C D
7 A B C D
The program should display the seat pattern, with an ‘X’ marking the seats already assigned. After displaying the seats available, the program prompts the seat desired, the user types in a seat, and then the display of available seats is updated. This continues until all seats are filled or until the user signals that the program should end. If the user types in a seat that is already assigned, the program should say that the seat is occupied and ask for another choice.
程序应显示座位模式,并带有“ X”标记已分配的座位。 在显示可用座位之后,程序会提示所需的座位,用户键入座位,然后更新可用座位的显示。 这一直持续到所有座位都装满或用户发出程序结束的信号为止。 如果用户键入已经分配的座位,则程序应说明该座位已被占用,并要求其他选择。
Input Example:
输入示例:
For example, after seats 1A, 2B, and 4C are taken, the display should look like:
例如,在坐下了座位1A,2B和4C之后,显示屏应如下所示:
1 X B C D
2 A X C D
3 A B C D
4 A B X D
5 A B C D
6 A B C D
7 A B C D
Solution
解
The whole problem can be implemented with help of 4 major functions:
可以通过以下四个主要功能来实现整个问题:
getData()
getData()
display()
显示()
check()
check()
update()
update()
The entire problem is discussed dividing into parts focusing on functional modularity.
讨论了整个问题,分为针对功能模块化的部分。
1. Initialize a 2-D array to represent the seat matrix
1.初始化一个二维数组以表示座位矩阵
A 2-D character array is used to represent the seat matrix where the first column have the row number of each seat & the rest of the columns have four seat A,B,C,D respectively. Thus it’s a 7X5 2-D array to represent the airplane seat matrix which looks like fo