航空机票预订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:

可以通过以下四个主要功能来实现整个问题:

  1. getData()

    getData()

  2. display()

    显示()

  3. check()

    check()

  4. 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 following:

2-D字符数组用于表示席位矩阵,其中第一列具有每个席位的行号,其余列分别具有四个席位A,B,C,D。 因此,它是一个7X5二维数组,表示飞机座椅矩阵,如下所示:

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }

2. Take user input for seat no

2.接受用户输入的座位号

User is requested to input the desired seat no by giving corresponding no of seat. Like a valid seat no is 1A, 3C, 7D and so on, whereas, an invalid seat request can be 6F, 0B so on.

要求用户通过提供相应的座位号来输入所需的座位号。 像有效席位一样,no是1A,3C,7D等,而无效席位请求可以是6F,0B等。

The input is taken by our function getData() which takes user input & returns the string.

输入由我们的函数getData()获得 ,该函数接受用户输入并返回字符串。

3. Check the seat no request (check() )

3.检查座位无要求(check())

Our major function for this problem is to check the validity of the seat request & update seat matrix status as per request.

我们针对该问题的主要功能是检查座位请求的有效性并根据请求更新座位矩阵状态。

  • Firstly it checks whether the user input is in the range 1A to 7D or not. If user input is out of range a prompt out "invalid request" & continue for further request.

    首先,它检查用户输入是否在1A到7D范围内。 如果用户输入超出范围,则提示“无效请求”并继续进行进一步的请求。

  • Check whether user input is 'N' or not. If it's 'N' then user wants to end the program. Terminate.

    检查用户输入是否为“ N” 。 如果为“ N”,则用户要结束程序。 终止。

  • if seat request is valid but already occupied

    如果座位请求有效但已被占用

    Then prompt a message stating “It’s already occupied”

    然后提示信息“已被占用”

    This checking can be done by founding the 2-D array row & column index for the corresponding seat.

    可以通过找到相应座位的二维数组行和列索引来完成此检查。

    Let,

    让,

    row_index=r&column_index=c
    If(seat_matrix[row_index][column_index]==’X’)

    row_index = r&column_index = c
    如果(seat_matrix [row_index] [column_index] =='X')

    Seat is occupied.

    座位已满。

  • ELSE seat request is a valid one and not occupied still

    ELSE座位请求是有效的,尚未占用

    Update()

    更新()

4. Update the valid entry

4.更新有效条目

If the request is to update the valid seat we simple change its value to 'X'. It can be done by finding row & column index and updating the value of seat_matrix at that location to 'X'.

如果请求更新有效席位,我们只需将其值更改为'X'即可 。 可以通过查找行和列索引并将该位置的seat_matrix值更新为'X'来完成

5. Special function to check whether all seats are occupied

5.特殊功能,检查是否所有座位都被占用

The program also need to be terminated when all seats are occupied. Thus every time we keep a checking whether all the entry of seat_matrix is 'X' or not.

当所有座位都坐满时,还需要终止该程序。 因此,每次我们都检查一下seat_matrix的所有条目是否为“ X”

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }

航空公司座位预订问题的C ++实现 (C++ implementation for Airline Seat Reservation Problem)

#include <bits/stdc++.h>
using namespace std;
// to check whether all sits are occupied or not
int allOccupied(char arr[7][5]){
int count=0;
for(int i=0;i<7;i++){for(int j=1;j<5;j++)
if(arr[i][j]=='X')
count++;
}
if(count==28)
return 1;
return 0;
}
//to display the sits
void display(char arr[7][5]){
for(int i=0;i<7;i++){for(int j=0;j<5;j++){cout<<arr[i][j]<<" ";
}
cout<<endl;
}
return;
}
//take user data
string getData(){
string p;
cout<<"enter valid seat no to check(like 1B) or N to end: ";
cin>>p;
return p;
}
//update sit status
void update(char arr[7][5],int row,int col){
cout<<"congrats, your seat is valid. Reserved for you\n";
cout<<"updated seat status..........\n";
arr[row][col]='X';
}
//checking whether user request for
//his sit no can be processed or not
int check(char arr[7][5],string s){
//if user input is not in the range 1A to 7D
if(s[0]>'7' || s[0]<'1' || s[1]>'D' || s[1]<'A'){
cout<<"invalid seat no\n"; //invalid sit no
return 0;
}
int row=-1,col=-1;
//find the row no of the user sit
for(int i=0;i<7;i++){if(arr[i][0]==s[0])
row=i;
}
//find the column no of user sit
for(int j=0;j<5;j++){if(arr[row][j]==s[1])
col=j;
}
//check whether sit is already occupied or not.
if(col==-1){cout<<"Seat is already occupied\n";
return 0;
}
else{//if it's a valid sit & not occupied,
//process the requested & update the sit as occupied
update(arr,row,col);
}
return 1;
}
void airline(char arr[7][5]){// user can stop process by pressing 'N'
cout<<"enter N if you are done!\n";
string s;
// continue if not interrepted by user or
//there is valid sit in unoccupied state
while(true){
s=getData(); //get user input
//if user input is to stop the process
if(s[0]=='N')
break; // break
//process the request & check according to
if(check(arr,s))
display(arr);
if(allOccupied(arr)){ //if all sits are occupied
cout<<"sorry, no more seats left!!!!!!!!!!1..."<<endl;
break; //break
}
}
cout<<"Thanks, that's all"<<endl; //end of program
}
int main()
{//2-D array for storing sit number
char arr[7][5];
for(int i=0;i<7;i++){//forst column is row number
arr[i][0]=i+1+'0';
for(int j=1;j<5;j++){//to represent sit number A,B,C,D respectively
arr[i][j]='A'+j-1;
}
}
cout<<"initial seat arrangements........\n";
display(arr);
airline(arr); //airline function
return 0;
}
.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }

Output

输出量

initial seat arrangements........
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
enter N if you are done!
enter valid seat no to check(like 1B) or N to end: 2B
congrats, your seat is valid. Reserved for you
updated seat status..........
1 A B C D
2 A X 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
enter valid seat no to check(like 1B) or N to end: 3C
congrats, your seat is valid. Reserved for you
updated seat status..........
1 A B C D
2 A X C D
3 A B X D
4 A B C D
5 A B C D
6 A B C D
7 A B C D
enter valid seat no to check(like 1B) or N to end: 2B
Seat is already occupied
enter valid seat no to check(like 1B) or N to end: 7E
invalid seat no
enter valid seat no to check(like 1B) or N to end: 7C
congrats, your seat is valid. Reserved for you
updated seat status..........
1 A B C D
2 A X C D
3 A B X D
4 A B C D
5 A B C D
6 A B C D
7 A B X D
enter valid seat no to check(like 1B) or N to end: N
Thanks, that's all

翻译自: https://www.includehelp.com/cpp-programs/airline-seat-reservation-problem.aspx

航空机票预订c#代码

航空机票预订c#代码_航空公司座位预订问题的C ++程序相关推荐

  1. java火车票预订系统代码_基于JSP开发火车票网上订票系统 java源码

    今天给大家演示的是一款由jsp+servlet+mysql实现的火车票预定管理系统,该系统主要实现的功能有:前台功能:用户查询车票信息.登录注册.购票.查看已购车票.修改密码等功能,后台管理功能:管理 ...

  2. react入门代码_如何在React中构建温度控制应用程序-包括提示和入门代码

    react入门代码 我们正在建立的 (What we're building) In this beginner React project, we're going to learn how to ...

  3. java 怎么从性能上优化代码_月薪上万做好这一步:程序员职场中必须掌握的的Java代码性能优化技巧...

    尽量指定类.方法的final修饰符 Java编译器会寻找机会内联所有的final方法,内联对于提升Java运行效率作用重大,具体参见Java运行期优化.此举大概能够使性能平均提高50%. 尽量重用对象 ...

  4. asp网上书店的代码_使用Helm将ASP.NET Core应用程序部署到Kubernetes容器集群

    在<容器化单页面应用中RESTful API的访问>以及<容器化单页面应用中Nginx反向代理与Kubernetes部署>两篇文章中,我介绍了一套容器化ASP.NET Core ...

  5. python注销代码_python怎么注销代码_如何从一个简单的web应用程序注销。在CherryPy,Python中...

    我不熟悉CherryPy和Python,但我需要编写一个非常简单的web应用程序来执行login---&gt:do some commands---&gt:logout.对于登录,我使 ...

  6. python3经典小程序代码_一个可以套路别人的python小程序实例代码

    python可以开发什么?谁有python小程序的源代码,...桌面程序,web都可以,还有比如现在讲的多的人工智能,神经网络源码可以去找一些开源代码,搜索一下,蛮多的. 分享python小程序代码练 ...

  7. python 打印自己代码_如何编写一个打印自身源代码的程序

    一个程序,在没有任何外部输入的情况下,打印自身的源代码,这类程序在英文里有一个专门的称呼,叫做Quine,之所以叫这个名字,是为了纪念美国哲学家及逻辑学家Willard Van Orman Quine ...

  8. vbs画动态爱心代码_用C语言实现心形表白程序[酷炫动态版]

    前几天给大家放一个C语言实现心形表白功能的程序,许多小白觉得有意思,今天给大家再放一个更炫酷的表白程序,有需要的童鞋拿去吧~ 先看看效果图吧: 因为是动图,所以只能象征性给大家截图啦~ 怎么样?童鞋们 ...

  9. 简单的五子棋java代码_求一个最简单的JAVA五子棋程序。。

    展开全部 import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt ...

最新文章

  1. Ansible01-Ansible基础和部署
  2. 函数作用域,闭包,数据类型的题目
  3. python综合学习一之多线程
  4. xmlHttpRequest无刷新验证用户名
  5. mysql binlog生成异常_mysql binlog故障演练
  6. Spring IOC容器的依赖注入流程(收集和注册、分析和组装)
  7. 学python能赚钱吗-在校大学生用python当爬虫一个月能赚3000吗?
  8. [not] exists 和 in
  9. 总结定时器设计方法_PLC定时器(T)的工作原理及使用注意事项
  10. java商品管理系统(增删改查)
  11. 海思移动侦测和视频遮挡实现
  12. Java调用外部api接口请求数据(阿里云ISBN查询图书信息为例)
  13. windows pagefile.sys配置调整
  14. 苹果手游代充灰色产业深度揭秘
  15. 亚洲杯:艾因月夜,里皮妙手导演逆转
  16. x570主板怎么样 x570主板支持的cpu
  17. Java 往文件中写数据,新写入的数据总是覆盖原有数据
  18. 基于服务器搭建部署的疫情动态地图
  19. MySQL UDF 提权
  20. 【不萌但新】TypeScript入门笔记

热门文章

  1. 计算机控制基础知识,最新 分析计算机控制系统及其运算基础知识-精品
  2. 惠普800g1支持什么内存_惠普黑白激光打印机哪种好 惠普黑白激光打印机推荐【图文详解】...
  3. PyTorch C++ API libtorch 简介
  4. html画图代码_python之matplotlib画图教程(2)
  5. percona-toolkit---pt-heartbeat
  6. Ubuntu16.04LTS修改开机动画
  7. 蓝桥杯练习系统,入门训练,Java版
  8. [算法总结] 13 道题搞定 BAT 面试——字符串
  9. python_L2_operator
  10. 微信公众号开发 ssl connect error