一个c++程序题急需解答,有点难理解哦!高手指点!

xuhuan881207 2008-05-17 06:17:20
(航空订票系统)航空公司购买了一台用于航空订票系统的计算机,要求对新系统编程,对每个航班订座(每班20位)。
程序显示下列菜单选项:Please type 1 for "smoking"和Please type 2 for "no smoking"。如果输入1,则程序指定吸烟舱位(座位1到10);如果输入2,则程序指定非吸烟舱位(座位11到20)。程序应输出一个登机牌,表示座位号和是否为吸烟舱位。
用一个一维数组表示飞机的座位图。将数组的所有元素初始化为0,表示所有座位都是空的。订每个座位是,将数组相应元素设置为1,表示该座位已订。
程序不能再订已经订过的座位。吸烟舱位已满,应询问可否订非吸烟舱位;同样,非吸烟舱位已满时,应询问可否订吸烟舱位。如果同意,再相应订座,否则输出消息"Next flight leaves in 5 hours"。



<说明:只利用数组与函数的知识编写程序,输出、输入用标准流cout、cin。>
...全文
122 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuhuan881207 2008-05-18
  • 打赏
  • 举报
回复
我是初学者啊,还请高手赐教呀!
kitcaii 2008-05-18
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;
int order(int, int [], int);
void print(int, int);
int main()
{
const int SIZE = 20;
int t;
int n;
int seat[SIZE] = {0};
char s='a';
for(; (s = cin.get()) != 'c'; ) // 按任意键继续,按C键结束查询
{
cout << "Please type 1 for \"smoking\" and 2 for \"no smoking\" :_\b";
cin >> t;
if(t != 1 && t != 2)
{
cout << "your input is incorrect!\n";
continue;
}
n = order(t, seat, SIZE);
print(n, t);
for(int i = 0; i < SIZE; i++)
cout << seat[i];
cout << endl;
s = cin.get();
}
return 0 ;
}



int order(int tag, int st[], int n)
{
int num;
if(tag == 1)
{
for(num= 0; num < 10; num++)
{
if(st[num] == 0)
{
break;
}
}
}
else
{
for(num=10; num < n; num++)
{
if(st[num] == 0)
{
break;
}
}
}
st[num] = 1;
return num+1;
}

void print(int x, int y)
{
if(y == 1)
{
cout << "Your seat number is " << x << " with \"smoking\" " << endl;
}
else
{
cout << "Your seat number is " << x << " with \"no smoking\" " << endl;
}
}
kitcaii 2008-05-18
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;
int order(int, int [], int);
void print(int, int);
int main()
{
const int SIZE = 20;
int t;
int n;
int seat[SIZE] = {0};
char s='a';
for(; (s = cin.get()) != 'c'; ) // 按任意键继续,按C键结束查询
{
cout << "Please type 1 for \"smoking\" and 2 for \"no smoking\" :_\b";
cin >> t;
if(t != 1 && t != 2)
{
cout << "your input is incorrect!\n";
continue;
}
n = order(t, seat, SIZE);
print(n, t);
for(int i = 0; i < SIZE; i++)
cout << seat[i];
cout << endl;
s = cin.get();
}
return 0 ;
}



int order(int tag, int st[], int n)
{
int num;
if(tag == 1)
{
for(num= 0; num < 10; num++)
{
if(st[num] == 0)
{
break;
}
}
}
else
{
for(num=10; num < n; num++)
{
if(st[num] == 0)
{
break;
}
}
}
st[num] = 1;
return num+1;
}

void print(int x, int y)
{
if(y == 1)
{
cout << "Your seat number is " << x << " with \"smoking\" " << endl;
}
else
{
cout << "Your seat number is " << x << " with \"no smoking\" " << endl;
}
}
kitcaii 2008-05-18
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;
int order(int, int [], int);
void print(int, int);
int main()
{
const int SIZE = 20;
int t;
int n;
int seat[SIZE] = {0};
char s='a';
for(; (s = cin.get()) != 'c'; ) // 按任意键继续,按C键结束查询
{
cout << "Please type 1 for \"smoking\" and 2 for \"no smoking\" :_\b";
cin >> t;
if(t != 1 && t != 2)
{
cout << "your input is incorrect!\n";
continue;
}
n = order(t, seat, SIZE);
print(n, t);
for(int i = 0; i < SIZE; i++)
cout << seat[i];
cout << endl;
s = cin.get();
}
return 0 ;
}



int order(int tag, int st[], int n)
{
int num;
if(tag == 1)
{
for(num= 0; num < 10; num++)
{
if(st[num] == 0)
{
break;
}
}
}
else
{
for(num=10; num < n; num++)
{
if(st[num] == 0)
{
break;
}
}
}
st[num] = 1;
return num+1;
}

void print(int x, int y)
{
if(y == 1)
{
cout << "Your seat number is " << x << " with \"smoking\" " << endl;
}
else
{
cout << "Your seat number is " << x << " with \"no smoking\" " << endl;
}
}
mengde007 2008-05-17
  • 打赏
  • 举报
回复
晕,你太懒了吧!
lily604 2008-05-17
  • 打赏
  • 举报
回复
这叫基础的C++
这是在aboslute C++上看的吧
xuhuan881207 2008-05-17
  • 打赏
  • 举报
回复
哎,管它是不是C++啊,反正就是希望高手能编出来!
clhposs 2008-05-17
  • 打赏
  • 举报
回复
<说明:只利用数组与函数的知识编写程序,输出、输入用标准流cout、cin。>
这叫C++吗? 这只能说是C外加C++的IO

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧