找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 1170|回复: 0

[求助]怎么实现循环?

[复制链接]
发表于 2009-11-5 01:01:01 | 显示全部楼层 |阅读模式 IP:江苏扬州
程序的要求是这样的:
某航空公司购买了一台用于航空订票系统的计算机,要求对新系统编程,对每个航班订座(每班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;
}

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

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-10-1 09:41 , Processed in 0.244375 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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