| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 535 人关注过本帖
标题:[求助]怎么实现循环?
只看楼主 加入收藏
lyle3
Rank: 1
等 级:新手上路
帖 子:80
专家分:0
注 册:2006-5-19
收藏
 问题点数:0 回复次数:0 
[求助]怎么实现循环?

程序的要求是这样的:
某航空公司购买了一台用于航空订票系统的计算机,要求对新系统编程,对每个航班订座(每班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;
}

看下这个程序.....
谢谢>->->->->->->->->-........

搜索更多相关主题的帖子: 订票 计算机 舱位 座位 航空 
2007-04-09 13:25
快速回复:[求助]怎么实现循环?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.076680 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved