设为首页收藏本站

新微赢技术网

 找回密码
 注册
搜索
热搜: 回贴
查看: 1163|回复: 0
打印 上一主题 下一主题

[求助]怎么实现循环?

[复制链接]
跳转到指定楼层
1#
发表于 2009-11-5 01:01:01 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
程序的要求是这样的:
某航空公司购买了一台用于航空订票系统的计算机,要求对新系统编程,对每个航班订座(每班10位)。
要求:
程序显示下列菜单选项:
? Please type 1 for “smoking”
? Please type 2 for “nonsmoking”
如果输入1,则程序指定吸烟舱位(座位1到5),如果输入2,则程序指定非吸烟舱位(座位6到10)。程序应输出一个登机牌,表示座位号和是否为吸烟舱位。
提示:
用一个单下标数组表示飞机的座位图。将数组的所有元素初始化为0,表示所有座位都是空的。订每个座位时,将数组相应元素设置为1,表示该座位已订。当然,程序不能再订已经订过的座位。吸烟舱位已满时,应该询问可否订非吸烟舱位;同样,非吸烟舱位已满时,应询问可否订吸烟舱位。如果同意,再相应订座,否则打印消息:“Next flight leaves in 3 hours”。



#include<iostream>
const int SeatsNum = 5; //定义座位数
using namespace std;
int choice = 0; // 选择输入
int seats1[SeatsNum] = {0}; // 吸烟仓座位
int seats2[SeatsNum] = {0}; //无烟仓座位
int getSeatNum(int* seats); //计算座位号
void getSmokingNum(int* seats);//输入所定的座位号和仓类型
void getUnsmokingNum(int* seats);//输入所定的座位号和仓类型
void menu(); //选择菜单
bool seatsOrNot(int* seats); //判断是否有座位
bool seatsOrNot(int* seats) //判断是否有座位
{
for(int i = 0; i < SeatsNum; i++)
{
if(seats[i] == 0)
return true;
}
return false;
}
int getSeatNum(int* seats) //计算座位号
{
int seatNum = 0;
for(int i = 0; i < SeatsNum; i++)
{
if(seats[i] == 0)
{
seats[i] == 1;
seatNum == i+1; //座位号
return seatNum;
}
}
return 0;
}
void getSmokingNum(int* seats) //输出座位号和仓类型
{
int input = 0;
if(seatsOrNot(seats))
cout<< "The seat you booked is " << getSeatNum(seats) << " in the smoking.";
else
{
cout<<"The smoking seats have been sold out!"<<endl;
cout<<"If you want to book a unsmoking seat enter 2,press other keys to return......"<<endl;
cin>>choice;
if(input == 2)
getUnsmokingNum(seats2);
else
{
cout<<"Next flight leaves in three hours......."<<endl;
return;
}
}
}
void getUnsmokingNum(int* seats)//输出座位号和仓类型
{
int input = 0;
if(seatsOrNot(seats))
cout<< "The seat you booked is " << getSeatNum(seats) << " in the unsmoking.";
else
{
cout<<"The smoking seats have been sold out!"<<endl;
cout<<"If you want to book a unsmoking seat enter 1,press other keys to return......"<<endl;
cin>>input;
if(input == 1)
getSmokingNum(seats1);
else
{
cout<<"Next flight leaves in three hours......."<<endl;
return;
}
}
}
void menu()//菜单
{
cout<<"Welcome to use this seats booking system."<<endl;
cout<<"Book the smoking seat press ------1------"<<endl;
cout<<"Book the smoking seat press ------2------"<<endl;
cout<<"Input: ";
}
int main()//主函数
{
menu();
cin>>choice;
switch(choice)
{
case 1: getSmokingNum(seats1);break;
case 2: getUnsmokingNum(seats2);break;
default: ;break;
}
return 0;
}

看下这个程序.....
谢谢>->->->->->->->->-........
您需要登录后才可以回帖 登录 | 注册

本版积分规则

申请友链|小黑屋|最新主题|手机版|新微赢技术网 ( 苏ICP备08020429号 )  

GMT+8, 2024-11-19 11:23 , Processed in 0.066300 second(s), 9 queries , Gzip On, Memcache On.

Powered by xuexi

© 2001-2013 HaiAn.Com.Cn Inc. 寰耽

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