问题
·飞机乘客信息录入系统
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
struct passenger
{
int num;
char name[10];
int age;
char sex;
double weight;
double luggage;
char meal;
};
void main()
{/
int n=0,i,j,rn=5;
struct passenger *p=new passenger[5];///????????????????????????
cout<<"======>> please input the basic information "<<endl;
for(i=0;;i++)
{
cout<<endl;
cout<<"NO(input 0 to quit) ="; cin>>(*(p+i)).num;
if((*(p+i)).num==0) break;
cout<<"Name ="; cin>>(*(p+i)).name;
cout<<"Age ="; cin>>(*(p+i)).age;
cout<<"Sex('f'or'm') ="; cin>>(*(p+i)).sex;
cout<<"Weight ="; cin>>(*(p+i)).weight;
cout<<"Luggage ="; cin>>(*(p+i)).luggage;
cout<<"Meal('A|a'or'B|b') ="; cin>>(*(p+i)).meal;
if(((*(p+i)).weight+(*(p+i)).luggage)>500)
{
cout<<"**********************************"<<endl;
cout<<"***"<<(*(p+i)).name<<" is overweight!!"<<"***"<<endl;
cout<<"**********************************"<<endl;
}
n++;
cout<<"------->>-----NEXT ONE------>>------->>>"<<endl;
}
cout<<"++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<" No"<<" Name"<<" Age"<<" Sex"<<" Weight"<<" Luggage"<<" Meal "<<endl;
for(i=0;i<n;i++)
{
cout<<setw(3)<<(*(p+i)).num<<setw(7)<<(*(p+i)).name<<setw(5)<<(*(p+i)).age<<setw(4)<<(*(p+i)).sex<<setw(8)<<(*(p+i)).weight<<setw(9)<<(*(p+i)).luggage<<setw(5)<<(*(p+i)).meal<<endl;
}
cout<<"++++++++++++++++++++++++++++++++++++++"<<endl;
//maopao paixu
cout<<endl;
cout<<endl;
cout<<"======>>according to age,rank again"<<endl;
cout<<"++++++++++++++++++++++++++++++++++++++"<<endl;
for(i=1;i<=n-1;i++)
for(j=0;j<=n-i-1;j++)
if((*(p+j)).age>(*(p+j+1)).age)
{
swap(*(p+j),*(p+j+1));
}
for(i=0;i<n;i++)
{
cout<<setw(3)<<(*(p+i)).num<<setw(7)<<(*(p+i)).name<<setw(5)<<(*(p+i)).age<<setw(4)<<(*(p+i)).sex<<setw(8)<<(*(p+i)).weight<<setw(9)<<(*(p+i)).luggage<<setw(5)<<(*(p+i)).meal<<endl;
}
cout<<"++++++++++++++++++++++++++++++++++++++"<<endl;
//maopao paixu
cout<<endl;
cout<<"======>>according to weight+luggage,rank again"<<endl;
cout<<"++++++++++++++++++++++++++++++++++++++"<<endl;
for(i=1;i<=n-1;i++)
for(j=0;j<=n-i-1;j++)
if(((*(p+j)).weight+(*(p+j)).luggage)>((*(p+j+1)).weight+(*(p+j+1)).luggage))
{
swap(*(p+j),*(p+j+1));
}
for(i=0;i<n;i++)
{
cout<<setw(3)<<(*(p+i)).num<<setw(7)<<(*(p+i)).name<<setw(5)<<(*(p+i)).age<<setw(4)<<(*(p+i)).sex<<setw(8)<<(*(p+i)).weight<<setw(9)<<(*(p+i)).luggage<<setw(5)<<(*(p+i)).meal<<endl;
}
cout<<"++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<endl;
cout<<endl;
//gong neng xuan ze
int a,f,m;
char b;
cout<<"==============>>please choose function 1 2 3"<<endl;
cout<<"==>>1--calculate the number of man and woman"<<endl;
cout<<"==>>2--display people's information under 18"<<endl;
cout<<"==>>3--show people's information chosen AorB"<<endl;
cout<<endl;
cout<<"which function do you want to choose ?"; cin>>a;
// nan nv ren shu
if(a==1)//50
{
for(f=0,m=0,i=0;i<n;i++)
{
if((*(p+i)).sex=='f') f++;
if((*(p+i)).sex=='m') m++;
}
cout<<"the number of female is "<<f<<endl;
cout<<"the numbei of male is "<<m<<endl;
}
// 18 sui ren shu
if(a==2)
{
for(m=0,i=0;i<n;i++)
{
if((*(p+i)).age<18)
{
m++;
cout<<setw(3)<<(*(p+i)).num<<setw(7)<<(*(p+i)).name<<setw(5)<<(*(p+i)).age<<setw(4)<<(*(p+i)).sex<<setw(8)<<(*(p+i)).weight<<setw(9)<<(*(p+i)).luggage<<setw(5)<<(*(p+i)).meal<<endl;
}
}
cout<<"the numbei of people's year <18 is "<<m<<endl;//70
}
// tao can xin xi
if(a==3)
{
cout<<"choose A or B about meal"<<endl;
cin>>b;
if(b=='A')
{
for(i=0;i<n;i++)
{
if((*(p+i)).meal=='A'||'a')//80
{
cout<<setw(3)<<(*(p+i)).num<<setw(7)<<(*(p+i)).name<<setw(5)<<(*(p+i)).age<<setw(4)<<(*(p+i)).sex<<setw(8)<<(*(p+i)).weight<<setw(9)<<(*(p+i)).luggage<<setw(5)<<(*(p+i)).meal<<endl;
}
}
}
if(b=='B')
{
for(i=0;i<n;i++)
{
if((*(p+i)).meal=='B'||'b')
{
cout<<setw(3)<<(*(p+i)).num<<setw(7)<<(*(p+i)).name<<setw(5)<<(*(p+i)).age<<setw(4)<<(*(p+i)).sex<<setw(8)<<(*(p+i)).weight<<setw(9)<<(*(p+i)).luggage<<setw(5)<<(*(p+i)).meal<<endl;
}
}
}
delete []p;
}
}