test05.cpp

来自「数组、指针和引用的操作练习 航空售票系统:为一个容量为10个座位飞机的航班之每」· C++ 代码 · 共 91 行

CPP
91
字号
// test05.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream"
using namespace std;

int main(int argc, char* argv[])
{
	int i,j,k,m,p,num,a[5],b[5];
	char c;
	for(i=0;i<5;i++)
	{
		a[i]=0;
		b[i]=0;
	}
	for(j=0;j<=10;j++)
	{
		cout<<"please type 1 for \"smoking\""<<"\n";
		cout<<"please type 2 for \"nonsmoking\""<<"\n";
		cin>>num;
		if(num==1)
		{
        	for(k=0;k<5;k++)
			{
				if(a[k]==0)
				{
					a[k]=1;
					cout<<"your number is:  "<<k+1<<"\n";
					cout<<"you are in \"smoking\""<<"\n"<<"\n";
					break;
				}
				if(a[4]==1)
				{
					cout<<"there is no seat in \"smoking\""<<"\n";
					cout<<"if you want \"nonsmoking\",please type \'y\';otherwise type \'n\'"<<"\n";
					cin>>c;
					if(c=='y')
					{
						for(m=0;m<5;m++)
						{
							if(b[m]==0)
							{
								b[m]=1;
                                cout<<"your number is:  "<<m+6<<"\n";
					            cout<<"you are in \"nonsmoking\""<<"\n"<<"\n";
								break;
							}
							if(b[4]==1)
							{
								cout<<"there is no seat for you"<<"\n"<<"\n";
			
							}
						}
					}
					else
					{
						cout<<"Next flight leaves 6 hour."<<"\n"<<"\n";
					}
					break;
				}
				
			}
				
		}
		if(num==2)
		{
			for(p=0;p<6;p++)
			{
				if(b[p]==0)
				{
					b[p]=1;
					cout<<"your number is   "<<p+6<<"\n";
					cout<<"you are in \"nonsmoking\""<<"\n"<<"\n";
					break;
				}
			   if(b[4]==1)
				{
					cout<<"there is no seat for you "<<"\n"<<"\n";
				    break;
				}
				
			}
		}
		
	}
		

	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?