航天定票管理系统(上千行代码)

原代码
1、类:                 1person类
#include"String.h"
#include"Date.h"
#ifndef person_h
#define person_h
class person{
private:
   char name[30];//姓名
      char sex[4];//性别
      char nation[30];//国籍
   char id[50];
      Date da;//出生日期
   //friend class Date;
   friend class customer;
public:
   person(char na[]="/0",char se[]="/0",char nat[]="/0",char dd[]="/0",int y=1988,int m=4,int d=19):da(y,m,d)
 {strcpy(name,na);
  strcpy(sex,se);
  strcpy(nation,nat);
  strcpy(id,dd);
 }
 void setdate(int y=1988,int m=4,int d=9)
 {da.year=y;da.month=m;da.day=d;}
 int getyear()
 {return da.year;}
 int getday()
 {return da.day;}
 int getmonth()
 {return da.month;}
 Date &getdate(void)
 {cout<<da;}
 void setname(char na[]="/0")
 {strcpy(name,na);}
 char *getname()
 {return name;}
    void setsex(char na[]="/0")
 {strcpy(sex,na);}
 char *getsex()
 {return sex;}
 void setid(char na[]="/0")
 {strcpy(id,na);}
 String getid()
 {return id;}
 void setnation(char na[]="/0")
 {strcpy(nation,na);}
 char *getnation()
 {return nation;}
 friend ostream &operator<<(ostream &os,person &p)//重载输出运算符“<<”
 { os<<"姓名:"<<p.name<<endl;
   os<<"性别:"<<p.sex<<endl;
   os<<"出生日期:"<<p.da;
   os<<"国籍:"<<p.nation<<endl;
   os<<"身份证号:"<<p.id<<endl;
      return os;//返回输出流类ostream的一个对象引用os:即cout
 }
    friend istream &operator>>(istream &is,person &p)//重载输出运算符“>>”
 {
   cout<<"姓名:";
   is>>p.name;
      cout<<"性别:";
   is>>p.sex;
   cout<<"国籍:";
   is>>p.nation;
   cout<<"身份证号:";
   is>>p.id;
   cout<<"出生日期:"<<endl;
   is>>p.da;
      return is;//返回输出流类istream的一个对象引用is:即cin
 }
};
#endif
                        2Date类
//#include"person.h"
#include<iostream.h>
#ifndef Ddate_h
#define Date_h
class Date
{
private: int year,month,day;
friend class person;
public:
    Date(int a=2006,int b=9,int c=1)
 {year=a;
  month=b;
  day=c;
 }
    void setjxdate(int a=2006,int b=9,int c=1)
 {year=a;
  month=b;
  day=c;
 }
 void setyear(int a=2006)
 {year=a;
 }
 int getyear()
 {return year;
 }
 void setmonth(int b=9)
 {month=b;
 }
 int getmonth()
 {return month;
 }
 void setday(int c=1)
 {day=c;
 }
 int getday()
 {return day;
 }
 void coutDate()
 {cout<<"年:"<<year<<" 月:"<<month<<" 日:"<<day;
 }
    void exchangejxdate(const Date &ob)
 {year=ob.year;
  month=ob.month;
  day=ob.day;
 }
 int operator==(Date& dt) const
 {
  return (this->month == dt.month &&
     this->day == dt.day &&
     this->year == dt.year );
 }
 void operator=(const Date& dt)
 {  month=dt.month;
    day=dt.day;
    year=dt.year;}

 friend ostream& operator<<(ostream &os,Date &p)//重载输出运算符“<<”
 { os<<p.year<<"/"<<p.month<<"/"<<p.day<<"/n";
      return os;//返回输出流类ostream的一个对象引用os:即cout
 }

 friend istream &operator>>(istream &is,Date &p)//重载输出运算符“>>”
 { cout<<"年:";
   is>>p.year;
   cout<<"月:";
   is>>p.month;
   while(p.month>12||p.month<1)
   {cout<<"月份输入有误!请重新输入。"<<endl;
    cout<<"月:";
    is>>p.month;
   }
    cout<<"日:";
    is>>p.day;
   while(p.day>31||p.day<1)
   {cout<<"日期输入有误!请重新输入。"<<endl;
    cout<<"日:";
    is>>p.day;}
      return is;//返回输出流类istream的一个对象引用is:即cin
 }
};
#endif
                             3airinfor类
#include <iostream.h>
#include<time.h>
#include<string.h>
#include"String.h"
#include "hdate.h"
#ifndef airinfor_h
#define airinfor_h
class airinfor

 char number[11];//型号
    friend class date;
 date da2;                  //记入时的时间
    date da;                   //出发时间。//创建异常链表。//实现自动删除
    date da1;                  // 终点时间。//创建异常链表。//实现自动删除
    char startbna[20];           //出发
    char endna[20];              //终点地点
 float pay;                //票价
 float allpay;              //该航班总收入量
    int max;                   //最大容量
    int pop;                   //记录已经订购量。
public:
    airinfor(char nu[]="/0",int y=2007,int m=1,int d=1,int h=8,int mm=30,int s=0,float p=6,char sta[]="/0",char end[]="/0"):da2(y,m,d),da1(y,m,d,h,mm,s),da(y,m,d,h,mm,s)
 {
     strcpy(number,nu);
  strcpy(startbna,sta);
     strcpy(endna,end);
  pop=0;
  allpay=0;
 }
 friend istream &operator>>(istream &is,airinfor &air);
 friend ostream &operator<<(ostream &os,airinfor &air);
 airinfor &operator=(airinfor &air)
 {
  strcpy(number,air.number);               
     da=air.da;                 
     da1=air.da1;                
     strcpy(startbna,air.startbna);         
     strcpy(endna,air.endna);            
  pay=air.pay;                
     max=air.max;               
     pop=air.pop; 
  return *this;
 }
 void setmax(int x=500)
 {max=x;
 }
 void setpay(float x=0)
 {pay=x;}
 void setallpay(float x=50)
 {allpay+=x;}
 float getallpay()
 {return pay*pop;}
    float getpay()
 {return pay;}
 int getmax()
 {return max;}
 void setpop(int x=1)
 {pop+=x;}
 int getpop()
 {return pop;}
    date &getda1()
 {return da1;
 }
 bool contast()
 {if(pop>max)
  return true;
  else
  return false;
 }
 void setnumb(char na[])
 {strcpy(number,na);
 }
 char *getnum()
 {return number;}

    char *getstart()
 {return startbna;}

 char *getend()
 {return endna;}
 int save()
 {return (max-pop);}
};

istream &operator>>(istream &is,airinfor &air)
{long now=time(0);
 air.da2.qshuju(now);
 cout<<"飞机型号:";
 is>>air.number;
 cout<<"票价:";
 is>>air.pay;
 cout<<"最大承载量:";
 is>>air.max;
 cout<<"始发地点:";
 is>>air.startbna;
 cout<<"终点地点:";
 is>>air.endna;
 cout<<"始发时间:"<<endl;
 is>>air.da;
 cout<<"到达终点时间:"<<endl;
 is>>air.da1;
 while(air.da>air.da1)
 {cout<<"终点时间不可能先于始发时间啊!请重新输入。"<<endl;
  cout<<"始发时间:"<<endl;
  is>>air.da;
  cout<<"到达终点时间:"<<endl;
  is>>air.da1;
 }
 air.pop=0;
 return is;
}

ostream &operator<<(ostream &os,airinfor &air)
{
 os<<"飞机型号:"<<air.number<<endl;
 os<<"票价:"<<air.pay<<endl;
 cout<<"始发地点:"<<air.startbna<<endl;
 cout<<"终点地点:"<<air.endna<<endl;
 os<<"始发时间:"<<air.da;
 os<<"终点时间:"<<air.da1;
 os<<"最大承载量:"<<air.max<<endl;
 os<<"以预定量:"<<air.pop<<endl;
 if(air.contast())
 os<<"很抱歉!该航班机票已经全部被预定完了。"<<endl;
 else
 os<<"该航班还剩"<<air.save()<<"张机票未定"<<endl;
 return os;
}
#endif

                               4hdate类
#include<string.h>
#include<time.h>//再自动设置时利用每月30天每年365天
#ifndef date_h
#define date_h
int hh=0;
class date
{
private:
  long wday;
  static long wday1;
  static long wday2;
  static long second1;
  static long hour1;
  static long minute1;
  static long day1;
  static long month1;
  static long year1;
  static long second2;
  static long hour2;
  static long minute2;
  static long day2; //应用与自动化//要设置一个自动化函数
  static long month2;//作为可以变化的年
  static long year2;
  long   second;//钟
  long   minute;
  long   hour;
  long   day;
  long   month;
  long   year;
public:
 date(void);
    date(long s);
 date(const date &da);
 date(long,long,long);
   date(long s,long m,long h,long d,long mo,long y)
   {year=s;
    month=h;
     day=m;
     hour=y;
     minute=m;
    second=d;}
 void setsecond(long se);
 long getsecond();
    long getsecond1();
 void setminute();//自动把分钟设置进去
 void setminute1(long min);
 long getminute();
 void sethour();
 void sethour1(long ho);
 long gethour();
 void setday(long d);
 long getday();
    void setmonth(long mo);
 long getmonth();
 void setyear(long yea);
 long getyear();
 void setymd(int y,int m,int d);
 void printymd();//显示年月日
 void sethms(int y,int m,int d);
 date &qshuju(long s);//年月日数据的提取
    void printhms();//显示小时分钟秒
 static void setdate(long s,long m,long h,long d,long mo,long y);//1初始值设置
    void setdate2(long s,long m,long h,long d,long mo,long y);//2自动变量的初始值设置
    void setwday(long w)
 {wday=w;
 }

    void setwdayzi(long s)
 {long se=s-second1;
     long day3,da;
     long hou;
     hou=se/(3600);
     da=hou/24;
     day3=31+da+28+31+19;//为什么要加1//这里无形的把时间推后了两天
     wday=day3%7+6;
  if(wday>7)
  wday=wday-7;
 }
long getwday(void)
 {return wday;
 }
 static void setwday1(long w)
 {wday1=w;
 }
    static long getwday1(void)
    {return wday1;
 }
    static void setwday2(long w)
 {wday2=w;
 }

    static long getwday2(void)
    {return wday2;
 }
 static long gyear1();
    static long gmonth1();
    static long gday1();
    static long ghour1();
 static long gsecond1();
    static long gminute1();
    static long ghour2();
 static long gsecond2();
    static long gminute2();
    static long gday2();//应用与自动化//要设置一个自动化函数
    static long gmonth2();
    static long gyear2();
 static long leanyear2();//判断是否实闰年
 long leanyear()
 {return ((year%400)||(year%4&&(year%100!=0)));//闰年366天二月实29 tian
 }
 friend date &operator-(date &da1,date &da2);//注意这里必须加&
    friend date &operator+(int x,date &da);
 date &operator=(const date &da)
 { second=da.second;//钟
      minute=da.minute;
      hour=da.hour;
      day=da.day;
      month=da.month;
      year=da.year;
   wday=da.wday;
   return *this;
 }

friend ostream& operator<<(ostream &os,date &p)//重载输出运算符“<<”
        {os<<p.year<<"/"<<p.month<<"/"<<p.day<<" "<<p.hour<<":"<<p.minute<<":"<<p.second<<"/n";
      return os;//返回输出流类ostream的一个对象引用os:即cout
 }

    bool operator>(const date &da)
 {bool t=false;
  if(year>da.year)
   t=true;
  if(month>da.month&&year==da.year)
   t=true;
  if(day>da.day&&month==da.month&&year==da.year)
    t=true;
  if(hour>da.hour&&day==da.day&&month==da.month&&year==da.year)
   t=true;
 if(minute>da.minute&&hour==da.hour&&day==da.day&&month==da.month&&year==da.year)
   t=true;
  return t;
 }
 friend istream &operator>>(istream &is,date &p)//重载输出运算符“>>”
 { cout<<"年:";
   is>>p.year;
   cout<<"月:";
   is>>p.month;
   while(p.month>12||p.month<1)
   {cout<<"月份输入有误!请重新输入。"<<endl;
    cout<<"月:";
    is>>p.month;
   }
    cout<<"日:";
    is>>p.day;
   while(p.day>31||p.day<1)
   {cout<<"日期输入有误!请重新输入。"<<endl;
    cout<<"日:";
    is>>p.day;
   }
   cout<<"小时:";
   is>>p.hour;
      while(p.hour>24||p.hour<0)
   {cout<<"小时输入有误!请重新输入。"<<endl;
    cout<<"小时:";
    is>>p.hour;
   }
   cout<<"分钟:";
   is>>p.minute;
      while(p.minute>60||p.minute<0)
   {cout<<"分钟输入有误!请重新输入。"<<endl;
    cout<<"分钟:";
    is>>p.minute;
   }
      cout<<"秒钟:";
   is>>p.second;
      while(p.second>60||p.second<0)
   {cout<<"秒钟输入有误!请重新输入。"<<endl;
    cout<<"秒钟:";
    is>>p.second;
   }
      return is;//返回输出流类istream的一个对象引用is:即cin
 }

 ~date()
 {;}
};

date &operator+(int x,date &da)
{
 static date p;
 x=x+31+28+31+19;//注意
 p.wday=x%7+6;
 p.year=date::year1;
 if(p.wday>7)
  p.wday=p.wday-7;
 if(x>=365)
 {
   while(x>365)
   { p.year=date::year1+1;
    if(p.leanyear())
     x=x-366;
    else
     x=x-365;}
      if(p.leanyear())
   {
     if((x%366)>335)
  {x=x%366-335;
   p.month=12;}
     else if((x%366)>305)
        {x=x%366-305;
  p.month=11;}
     else if((x%366)>274)
        {x=x%366-274;
  p.month=10;}
     else if((x%366)>244)
        {x=x%366-244;
  p.month=9;}
     else if((x%366)>213)
        {x=x%366-213;
  p.month=8;}
     else if((x%366)>182)
  {x=x%366-182;
  p.month=7;}
  else if((x%366)>152)
        {x=x%366-152;
  p.month=6;}
  else if((x%366)>121)
        {x=x%366-121;
        p.month=5;}
  else if((x%366)>91)
        {x=x%366-91;
  p.month=4;}
  else if((x%366)>60)
        {x=x%366-60;
  p.month=3;}
  else if((x%366)>31)
        {x=x%366-31;
  p.month=2;}
  else
        {x=x%366;
  p.month=1;}
   }
      else
    {
  if((x%365)>335)
  {x=x%365-335;
   p.month=12;}
     else if((x%365)>305)
        {x=x%365-305;
  p.month=11;}
     else if((x%365)>274)
        {x=x%365-274;
  p.month=10;}
     else if((x%365)>244)
        {x=x%365-244;
  p.month=9;}
     else if((x%365)>213)
        {x=x%365-213;
  p.month=8;}
     else if((x%365)>182)
  {x=x%365-182;
  p.month=7;}
  else if((x%365)>152)
        {x=x%365-152;
  p.month=6;}
  else if((x%366)>121)
        {x=x%366-121;
        p.month=5;}
  else if((x%365)>91)
        {x=x%365-91;
  p.month=4;}
  else if((x%365)>60)
        {x=x%365-60;
  p.month=3;}
  else if((x%365)>31)
        {x=x%365-31;
  p.month=2;}
  else
        {x=x%365;
      p.month=1;}
    }
  }
 else
 {
  if((x%365)>335)
  {x=x%366-335;
   p.month=12;}
     else if((x%365)>305)
        {x=x%365-305;
  p.month=11;}
     else if((x%365)>274)
        {x=x%365-274;
  p.month=10;}
     else if((x%365)>244)
        {x=x%365-244;
  p.month=9;}
     else if((x%365)>213)
        {x=x%365-213;
  p.month=8;}
     else if((x%365)>182)
  {x=x%365-182;
  p.month=7;}
  else if((x%365)>152)
        {x=x%365-152;
   p.month=6;}
  else if((x%365)>121)
        {x=x%365-121;
         p.month=5;}
  else if((x%365)>91)
        {x=x%365-91;
   p.month=4;}
  else if((x%365)>60)
        {x=x%365-60;
   p.month=3;}
  else if((x%365)>31)
        {x=x%365-31;
   p.month=2;}
  else
        {x=x%365;
   p.month=1;} 
  }
  p.day=x;
 return p;
}

date &operator-(date &da1,date &da2)//注意这里必须加&
{ // static date temp;
//注意在有还回值时一般定义为静态或date &operator-(date &da1,date &da2)//注意这里必须加&
  static date temp;
  long d=0,d1=0;
  temp.year=da1.year-da2.year;
  for(int i=0;i<temp.year;i++)
  {
    if(da2.year%400==0||da2.year%4==0&&da2.year%100!=0)
 temp.day=temp.day+366;
 else
 temp.day=temp.day+365;
 da2.year=da2.year+1;
  }
  if(da1.year%400==0||da1.year%4==0&&da1.year%100!=0)
  {    switch(da1.month)
    {case 12:d=366-31+da1.day;break;
     case 11:d=335-30+da1.day;break;
  case 10:d=305-31+da1.day;break;
  case 9: d=274-30+da1.day;break;
  case 8: d=244-31+da1.day;break;
  case 7: d=213-31+da1.day;break;
  case 6: d=182-30+da1.day;break;
  case 5: d=152-31+da1.day;break;
  case 4: d=121-30+da1.day;break;
  case 3: d=91-31+da1.day;break;
  case 2: d=60-29+da1.day;break;
  case 1: d=da1.day;break;
  default:d=0;
    }
  }
   else
   {   switch(da1.month)
    {case 12:d=365-31+da1.day;break;
     case 11:d=334-30+da1.day;break;
  case 10:d=304-31+da1.day;break;
  case 9: d=273-30+da1.day;break;
  case 8: d=243-31+da1.day;break;
  case 7: d=212-31+da1.day;break;
  case 6: d=181-30+da1.day;break;
  case 5: d=151-31+da1.day;break;
  case 4: d=120-30+da1.day;break;
  case 3: d=90-31+da1.day;break;
  case 2: d=59-28+da1.day;break;
  case 1: d=da1.day;break;
  default:d=0;
    }
   }
   if(da2.year%400==0||da2.year%4==0&&da2.year%100!=0)
   {
    switch(da2.month)
   {case 12:d1=366-31+da2.day;break;
     case 11:d1=335-30+da2.day;break;
  case 10:d1=305-31+da2.day;break;
  case 9: d1=274-30+da2.day;break;
  case 8: d1=244-31+da2.day;break;
  case 7: d1=213-31+da2.day;break;
  case 6: d1=182-30+da2.day;break;
  case 5: d1=152-31+da2.day;break;
  case 4: d1=121-30+da2.day;break;
  case 3: d1=91-31+da2.day;break;
  case 2: d1=60-29+da2.day;break;
  case 1: d1=da2.day;break;
  default:d1=0;
    }
   }
   else
   {    switch(da2.month)
    {case 12:d1=365-31+da2.day;break;
     case 11:d1=334-30+da2.day;break;
  case 10:d1=304-31+da2.day;break;
  case 9: d1=273-30+da2.day;break;
  case 8: d1=243-31+da2.day;break;
  case 7: d1=212-31+da2.day;break;
  case 6: d1=181-30+da2.day;break;
  case 5: d1=151-31+da2.day;break;
  case 4: d1=120-30+da2.day;break;
  case 3: d1=90-31+da2.day;break;
  case 2: d1=59-28+da2.day;break;
  case 1: d1=da2.day;break;
  default:d1=0;
    }
   }
   temp.day=temp.day+d-d1;
   return temp;
}

date::date(void)
{ second=0;
  minute=0;
  hour=0;
  day=0;
  month=0;
  year=0;
  wday=0;
}

date::date(long y,long m,long d)
{year=y;
 month=m;
 day=d;
}

date::date(long s)
{second=s;
}

date::date(const date &da)
{second=da.second;}

void date::setsecond(long se)
{second=se;}

long date::getsecond()
{return second;}

long date::getsecond1()
{return second%60;}
void date::setminute1(long min)
{minute=min;}

void date::setminute()
{long se,s;
se=second/60;
s=se%60;
minute=s;}
long date::getminute()
{return minute;}

void date::sethour()
{long se,s;
  se=second/3600;
  s=se%24;
  hour=(s+8);}//本地时间

void date::sethour1(long ho)
{hour=ho;}

long date::gethour()
{return hour;}

void date::setday(long d)
{day=d;}

long date::getday()
{return day;}

void date::setmonth(long mo)
{month=mo;}

long date::getmonth()
{return month;}

void date::setyear(long yea)
{year=yea;}

long date::getyear()
{return year;}

void date::setdate(long s,long m,long h,long d,long mo,long y)//通过自能化实现
{second1=s;////通过自能化实现。判断型//要经过处理
 year1=y;
 month1=m;
 day1=d;
 hour1=h;
 month1=mo;
 minute1=m;}

void date::setdate2(long s,long m,long h,long d,long mo,long y)
{second2=s;
 hour2=h;
 minute2=m;
 year2=y;
 month2=m;
 day2=d;}
long date::gyear1()
{return year1;}

long date::gmonth1()
{return month1;}

long date::gday1()
{return day1;}

long date::ghour1()
{return hour1;}

long date::gminute1()
{return minute1;}

long date::gsecond1()
{return second1;}

long date::ghour2()
{return hour2;}

long date::gminute2()
{return minute2;}

long date::gsecond2()
{return second2;}

long date::gday2()//应用与自动化//要设置一个自动化函数
{return day2;}

long date::gmonth2()
{return month2;}

long date::gyear2()
{return year2;}
void date::setymd(int y,int m,int d)
{year=y;
 month=m;
 day=d;}
void date::printymd()
{cout<<"年 "<<year<<" 月 "<<month<<" 日 "<<day<<endl;}

void date::sethms(int y,int m,int d)
{hour=y;
 minute=m;
 second=d;}

long date::leanyear2()
{return ((year2%400)||(year2%4&&(year2%100!=0)));//闰年366天二月实29 tian
}

void date::printhms()
{cout<<"时 "<<hour<<" 分 "<<minute<<" 秒 "<<second<<endl;}

date &date::qshuju(long s)//自动年月日的编写
{
 static date da1;
 long se=s-second1;
 long day,da;
 long hou;
 second2=s%60;
 minute2=s/60%60;
 hou=se/(3600);
 hour2=hou%24;
 da=hou/24;
 day=31+da+28+31+19;//为什么要加1这里无形的把时间推后了两天
 wday2=day%7+6;
 if(wday2>7)
  wday2=wday2-7;
 if(hou>=(365*24))
 { 
   while(day>365)
    {year2=year2+1;
    if(leanyear2())
     day=day-366;
    else
     day=day-365;}
      if(leanyear2())
   {
     if((day%366)>335)
  {day2=day%366-335;
   month2=12;}
     else if((day%366)>305)
        {day2=day%366-305;
  month2=11;}
     else if((day%366)>274)
        {day2=day%366-274;
  month2=10;}
     else if((day%366)>244)
        {day2=day%366-244;
  month2=9;}
     else if((day%366)>213)
        {day2=day%366-213;
  month2=8;}
     else if((day%366)>182)
  {day2=day%366-182;
  month2=7;}
  else if((day%366)>152)
        {day2=day%366-152;
  month2=6;}
  else if((day%366)>121)
        {day2=day%366-121;
        month2=5;}
  else if((day%366)>91)
        {day2=day%366-91;
  month2=4;}
  else if((day%366)>60)
        {day2=day%366-60;
  month2=3;}
  else if((day%366)>31)
        {day2=day%366-31;
   month2=2;}
  else
        {day2=day%366;
  month2=1;}
   }

       else
    {
  if((day%365)>335)
  {day2=day%365-335;
   month2=12;}
     else if((day%365)>305)
        {day2=day%365-305;
     month2=11;}
     else if((day%365)>274)
        {day2=day%365-274;
  month2=10;}
     else if((day%365)>244)
        {day2=day%365-244;
  month2=9;}
     else if((day%365)>213)
        {day2=day%365-213;
  month2=8;}
     else if((day%365)>182)
  {day2=day%365-182;
  month2=7;}
  else if((day%365)>152)
        {day2=day%365-152;
  month2=6;}
  else if((day%366)>121)
        {day2=day%366-121;
        month2=5;}
  else if((day%365)>91)
        {day2=day%365-91;
  month2=4;}
  else if((day%365)>60)
        {day2=day%365-60;
  month2=3;}
  else if((day%365)>31)
        {day2=day%365-31;
  month2=2;}
  else
        {day2=day%365;
      month2=1;}
    }
  }
 else
 {
  if((day%365)>335)
  {day2=day%366-335;
   month2=12;}
     else if((day%365)>305)
        {day2=day%365-305;
  month2=11;}
     else if((day%365)>274)
        {day2=day%365-274;
  month2=10;}
     else if((day%365)>244)
        {day2=day%365-244;
  month2=9;}
     else if((day%365)>213)
        {day2=day%365-213;
  month2=8;}
     else if((day%365)>182)
  {day2=day%365-182;
  month2=7;}
  else if((day%365)>152)
        {day2=day%365-152;
   month2=6;}
  else if((day%365)>121)
        {day2=day%365-121;
         month2=5;}
  else if((day%365)>91)
        {day2=day%365-91;
   month2=4;}
  else if((day%365)>60)
        {day2=day%365-60;
   month2=3;}
  else if((day%365)>31)
        {day2=day%365-31;
   month2=2;}
  else
        {day2=day%365;
   month2=1;} 
  }
 da1.year=year2;
 da1.month=month2;
 da1.day=day2;
 return da1;
}

long date::second1=1176825600;//bendishijian是24:00:00
long date::minute1=0;
long date::hour1=24;
long date::day1=18;
long date::month1=4;
long date::year1=2007;
long date::second2=1176825600;//bendishijian是24:00:00
long date::minute2=0;
long date::hour2=24;
long date::day2=18;
long date::month2=4;
long date::year2=2007;
long date::wday1=3;
long date::wday2=3;
#endif

                             5customer类
#include<iostream.h>
#include"person.h"
#include"airinfor.h"
#ifndef customer_h
#define customer_h
class customer:public person{
  airinfor air;
  person per;
  int num;
public:
 customer():person(),air(),per()
 {num=1;
 }
    friend istream &operator>>(istream &is,customer &cus)
 {cout<<"请输入该名顾客的基本信息:"<<endl;
  is>>cus.per;
  cout<<"请输入预定票数:";
  is>>cus.num;
  return is;
 }
 friend ostream &operator<<(ostream &os,customer &cus)
 {cout<<"该名顾客的信息如下|"<<endl;
  os<<cus.per;
  cout<<"所预定航班类型|"<<endl;
  os<<cus.air;
  cout<<"预定票数:"<<cus.num<<endl;
  return os;
 }

    person &getname1()//还会势力
 {return per;}

    void copy(airinfor &ar)
 {air=ar;}
 void setnum(int n)
 {num=n;}
    int getnum()
 {return num;}
 void chperson()//修改人的信息
 {cout<<"请输入要修改的信息:"<<endl;
  cin>>per;
 }
 void chperson(airinfor &ar)//修所乘做的航班的信息
 {air=ar;
 }
};

#endif


2、主函数
#include<iostream.h>
#include<fstream.h>
#include"customer.h"
void setair();                      //设置航班
void setin();                       //集体设置
void mtime(date &mk);               //时间显示
void afterday(date &mk,int i);      //转化时间
void today();
void change();
int lookall();
void clear();  //清理过起的信息
void bookt();   
void lookabook();
void researh();  
void changein();
void lookallbook(char na[]="q"); 
void byroute();
void researh(); 
void changein();
void lookmm();//查看机票的销售量
void main()
{cout<<">>>>>>欢迎使用航班管理系统<<<<</n";
 cout<<">作者:罗振辉 叶滔"<<endl<<endl;
 char ch='Y';
 int c;
 while(ch!='N')
 {
 cout<<"|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|/n";
 cout<<"|选择1       预设航班基本信息系统   |/n";
 cout<<"|选择2       预定机票系统           |/n";
 cout<<"|选择0       退出系统               |/n";
 cout<<"|___________________________________|/n";
 cout<<"请选择:";
 cin>>c;
 switch(c)
 {case 1: setair();break;
  case 2: bookt();break;
  case 0: ch='N';break;
  default:cout<<"没有该选项!请重新选择。";break;
 }
 }
}

void setair()
{char ch='Y';
 int c;
 while(ch!='N')
 {
 cout<<"|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|/n";
 cout<<"|选择1       预设航班基本信息       |/n";
 cout<<"|选择2       修改已设置的数据       |/n";
 cout<<"|选择3       查看所有航班信息       |/n";
 cout<<"|选择4       查看指定航班的销售信息 |/n";
 cout<<"|选择5       清除已经过期的设置     |/n";
 cout<<"|选择0       退出系统               |/n";
 cout<<"|___________________________________|/n";
 cout<<"请选择:";
 cin>>c;
 switch(c)
 {case 1: setin();break;
  case 2: change();break;
  case 3: lookall();break;
  case 4: lookmm();break;
  case 5: clear();break;
  case 0: ch='N';break;
  default:cout<<"没有该选项!请重新选择。"<<endl;break;
 }
 }
}

void lookmm()
{fstream in("data.txt",ios::in|ios::out|ios::binary);
 if(in.eof())
 {cout<<"文件不存在!"<<endl;
  return ;}
  airinfor air;
  int ii=0;
  char name[11];
  cout<<endl;
  cout<<"请输入航班的飞机型号:";
  cin>>name;
  while(!in.eof())
  {in.read((char*)&air,sizeof(airinfor));
  if(strcmp(air.getnum(),name)==0)
  {ii=1;
   break;}
 }
 if(ii==1)
 {cout<<"该航班的原始信息如下|"<<endl;
  cout<<"---------------------------------/n";
  cout<<air<<endl;
  cout<<"销售总金额:"<<air.getallpay()<<"元人民币"<<endl;
  cout<<"---------------------------------/n";
  cout<<endl;
 }
 else
  cout<<"/n没有该航班的记录!如要进行设置请还回。"<<endl<<endl;
  in.close();
}

void setin()
{
fstream in("data.txt",ios::in|ios::out|ios::binary);
if(in.eof())
{cout<<"文件不存在!"<<endl;
  return ;
}
airinfor air;
airinfor ai[50];
int i=0;
int ii=0,ib=0;
char ch='Y';
cout<<"此刻的日期时间如下|"<<endl;
today();
cout<<endl;
date da;
while(ch!='n')
{afterday(da,i);
 cout<<"这天的具体日期时间如下|"<<endl;
 mtime(da);
 cout<<"请进行这天所有航班基本信息设置。"<<endl;
 while(ch!='N')
 {in.seekp(0,ios::end);
  cout<<"请输入第"<<ii+1<<"次航班基本信息"<<endl;
  cin>>air;
  ai[ii]=air;
  for(int j=0;j<ii;j++)
   if(strcmp(ai[j].getnum(),air.getnum())==0)
   {ib=1;
    break;}
  if(ib==0)
   in.write((char*)&air,sizeof(air));//这里指针不会自动向后移动
  else
  {cout<<endl;
   cout<<"该航班信息已经输入了!"<<endl;
  }
   ii++;
   cout<<endl;
   cout<<"/a继续下一次航班基本信息输入Y否则N: ";
   cin>>ch;
 }
 i++;
 cout<<endl;
 cout<<"/a继续输入下一天的航班信息Y否则输入n: ";
 cin>>ch;
 cout<<endl;
 ii=0;
}
in.close();
}

void mtime(date &mk)
{cout<<"---------------------------------/n";
 cout<<mk.getyear()<<"/"<<mk.getmonth()<<"/"<<mk.getday()<<endl;
 cout<<"---------------------------------/n";
}

void afterday(date &mk,int i)
{int y,d,m;
 //date mm(2007,4,19),kk1,kk;
 cout<<"["<<i+1<<"]"<<endl;
 cout<<"请依次输入要进行预定设置航班的开始日期"<<endl;
 cout<<"年(>=2007):";
 cin>>y;
 while(y<2007)
 {
 cout<<"该年小于2007!请重新输入"<<endl;
 cout<<"年(>=2007):";
 cin>>y;}
 cout<<"月:";
 cin>>m;
 while(m>12)
 {cout<<"该月份不存在!请重新输入"<<endl;
  cin>>m;}
 cout<<"日:";
 cin>>d;
 while(d>31)
 {cout<<"该日期不存在!请重新输入"<<endl;
  cin>>d;}
 mk.setymd(y,m,d);
}

void today()
{long s1=time(0);
 long s,m,h1;
 date da;
 da.qshuju(s1);
 cout<<"---------------------------------/n";
if(date::getwday2()==7)
  cout<<"星期日"<<endl;
else
  cout<<"星期"<<date::getwday2()<<endl;
  cout<<date::gyear2()<<"/"<<date::gmonth2()<<"/"<<date::gday2()<<" ";
  s=s1%60;m=s1/60%60;h1=s1/3600%24+8;
  if(h1>=24)
  h1=h1-24;//注意这里要减去24;防此超过24
 if(h1==0)
 {
  cout<<"00";
  if(s>=10&&m>=10)
     cout<<":"<<m<<":"<<s<<endl;
     else if(s<10&&m>=10)
     cout<<":"<<m<<":"<<0<<s<<endl;
     else if(s<10&&m<10)
     cout<<":"<<0<<m<<":"<<0<<s<<endl;
     else
     cout<<":"<<0<<m<<":"<<s<<endl;}
  else
  {if(s>=10&&m>=10)
       cout<<h1<<":"<<m<<":"<<s<<endl;
       else if(s<10&&m>=10)
       cout<<h1<<":"<<m<<":"<<0<<s<<endl;
       else if(s<10&&m<10)
       cout<<h1<<":"<<0<<m<<":"<<0<<s<<endl;
       else
       cout<<h1<<":"<<0<<m<<":"<<s<<endl;
 }
    cout<<"---------------------------------/n";
}

void change()
{fstream in("data.txt",ios::in|ios::out|ios::binary);
 if(in.eof())
 {cout<<"文件不存在!"<<endl;
  return ;}
  airinfor air;
  int ii=0;
  char name[11];
  cout<<endl;
  cout<<"请输入要进行修改的航班的飞机型号:";
  cin>>name;
  while(!in.eof())
  {in.read((char*)&air,sizeof(airinfor));
  if(strcmp(air.getnum(),name)==0)
  {ii=1;
   break;}
 }
 if(ii==1)
 {cout<<"该航班的原始信息如下|"<<endl;
  cout<<"---------------------------------/n";
  cout<<air<<endl;
  cout<<"---------------------------------/n";
  cout<<endl;
  cout<<"请输入该航班的新信息|"<<endl;
  cin>>air;
  in.seekp(-long(sizeof(airinfor)),ios::cur);
  in.write((char*)&air,sizeof(airinfor));
 }
 else
  cout<<"/n没有该航班的记录!如要进行设置请还回。"<<endl<<endl;
  in.close();
}
int lookall()
{fstream in("data.txt",ios::in|ios::out|ios::binary);
 if(in.eof())
 {cout<<"文件不存在!"<<endl;
  return 0;}
 airinfor air;
 int i=1,ii=0;
 cout<<"所有的信息如下|"<<endl;
 cout<<"---------------------------------------------/n";
 while(!in.eof())
 {
  in.read((char*)&air,sizeof(airinfor));
  if(!in.eof()&&strcmp(air.getnum(),"删除")!=0)
  {ii=1;
  cout<<"["<<i<<"]"<<endl;
  cout<<"---------------------------------/n";
  cout<<air<<endl;
  cout<<"---------------------------------/n";
  }
  in.seekp(-long(sizeof(airinfor)),ios::cur);
  in.write((char*)&air,sizeof(airinfor));
  i++;
 }
 if(ii==0)
 cout<<"还没有任何航班的记录!如要进行设置请还回。"<<endl;
 cout<<"---------------------------------------------/n";
 in.close();
 return ii;
}

void clear()
{fstream in("data.txt",ios::in|ios::out|ios::binary);
 if(in.eof())
 {cout<<"文件不存在!"<<endl;
  return ;}
 airinfor air;
 airinfor air1;
 air1.setnumb("删除");
 long s1=time(0);
 int i=1,ii=0;
 date da,da1;
 da.qshuju(s1);
 da1.setymd(date::gyear2(),date::gmonth2(),date::gday2());
 while(!in.eof())
 {
  in.read((char*)&air,sizeof(airinfor));
  if(!in.eof())
  {
    if(da1>air.getda1()&&strcmp(air.getnum(),"删除")!=0)
 {ii=1;
     cout<<"["<<i<<"]"<<endl;
     cout<<"---------------------------------/n";
     cout<<air<<endl;
     cout<<"该信息过期!删除成功"<<endl;
     cout<<"---------------------------------/n";
     in.seekp(-long(sizeof(airinfor)),ios::cur);
     in.write((char*)&air1,long(sizeof(airinfor)));
     i++;
 }
  }
 } if(ii==0)
   cout<<"所有的航班无过期的记录!"<<endl;
   in.close();
}

void bookt()
{char ch='Y';
 int c;
 while(ch!='N')
 {
 cout<<"|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|/n";
 cout<<"|选择1       浏览航班信息并选择定票   |/n";
 cout<<"|选择2       查询过客信息             |/n";
 cout<<"|选择3       修改顾客信息             |/n";
 cout<<"|选择0       退出系统                 |/n";
 cout<<"|_____________________________________|/n";
 cout<<"请选择:";
 cin>>c;
 switch(c)
 {case 1: lookabook();break;
  case 2: researh();break;
  case 3: changein();break;
  case 0: ch='N';break;
  default:cout<<"没有该选项!请重新选择。"<<endl;break;
 }
 }
}

void lookabook()
{char ch='Y';
 int c;
 while(ch!='N')
 {
 cout<<"|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|/n";
 cout<<"|选择1       浏览所有航班信息并预定机票     |/n";
 cout<<"|选择2       通过路线浏览航班信息并预定机票 |/n";
 cout<<"|选择0       退出系统                       |/n";
 cout<<"|___________________________________________|/n";
 cout<<"请选择:";
 cin>>c;
 switch(c)
 {case 1: lookallbook();break;
  case 2: byroute();break;
  case 0: ch='N';break;
  default:cout<<"没有该选项!请重新选择。"<<endl;break;
 }
 }
}

void lookallbook(char na[])
{
int k;
if(strcmp(na,"q")==0)
 k=lookall();
if(k!=0)
{cout<<"请选择,输入想要预定的航班型号(输入N退出):";
 char name[11];
 cin>>name;
 if(strcmp(name,"N")!=0)
 {customer cs;
 fstream in("data.txt",ios::in|ios::out|ios::binary);
 if(in.eof())
 {cout<<"文件不存在!"<<endl;
  return ;
 }
 fstream cus("data1.txt",ios::in|ios::out|ios::binary);
 if(cus.eof())
 {cout<<"文件不存在!"<<endl;
  return ;
 }
 airinfor air;
 int ii=0;
 while(!in.eof())
 {in.read((char*)&air,sizeof(airinfor));
  if(!in.eof()&&strcmp(air.getnum(),name)==0)
  {ii=1;
   break;}
 }
 if(ii==1)
 {  cus.seekp(0,ios::end);
 if(!air.contast()&&air.save()!=0)
 {cout<<"请输入您的基本信息|"<<endl;
  cin>>cs;
  if(cs.getnum()>air.save())
  cout<<"很抱歉!您所要预定的票数超过了该航班的所省票数,如果方便的话请选择其他航班"<<endl;
  else
  {air.setpop(cs.getnum());
   in.seekp(-long(sizeof(airinfor)),ios::cur);
      in.write((char*)&air,sizeof(airinfor));
   cs.copy(air);
      cus.write((char*)&cs,sizeof(customer));
  }
 }
  else
    cout<<"很抱歉!该航班机票已经全部被定完了!"<<endl;
 }
 else
  cout<<"/n没有该航班的记录!如要请还回。"<<endl<<endl;
  in.close();
  cus.close();
 }
}
}

void byroute()
{
 cout<<"请输入想要预定的航班起始地点(输入N退出):";
 char name[11],na[11];
 cin>>name;
 if(strcmp(name,"N")!=0)
 {cout<<"请终点地点:";
 cin>>na;
 customer cs;
 fstream in("data.txt",ios::in|ios::out|ios::binary);
 if(in.eof())
 {cout<<"文件不存在!"<<endl;
  return ;
 }
 airinfor air;
 int ii=0;
 while(!in.eof())
 {
  in.read((char*)&air,sizeof(airinfor));

if(!in.eof()&&strcmp(air.getstart(),name)==0&&strcmp(air.getend(),na)==0&&strcmp(air.getnum(),"删除")!=0)
  {ii=1;
  cout<<"---------------------------------------/n";
  cout<<air;
  cout<<"---------------------------------------/n";
  }
 }
 if(ii==1)
 lookallbook("W");
 else
  cout<<"/n没有该航班的记录!如要请还回。"<<endl<<endl;
  in.close();
 }
}

void researh()
{customer cs;
int ii=0;
 fstream cus("data1.txt",ios::in|ios::out|ios::binary);
 if(cus.eof())
 {cout<<"文件不存在!"<<endl;
  return ;
 }
 cout<<"请输入顾客姓名:";
 char name[30];
 cin>>name;
 while(!cus.eof())
 {cus.read((char *)&cs,sizeof(customer));
  if(strcmp(cs.getname1().getname(),name)==0)
  {ii=1;
   break;
  }
 }
 if(ii==1)
 {cout<<"该顾客信息如下|"<<endl;
  cout<<"---------------------------------------/n";
  cout<<cs;
  cout<<"---------------------------------------/n";
 }
 else
  cout<<"不存在该顾客的信息!可能姓名输入错误。"<<endl;
  cus.close();
}

void changein()
{
customer cs;
 int ii=0;
 fstream cus("data1.txt",ios::in|ios::out|ios::binary);
 if(cus.eof())
 {cout<<"文件不存在!"<<endl;
  return ;
 }
 cout<<"请输入顾客姓名:";
 char name[30];
 cin>>name;
 while(!cus.eof())
 {cus.read((char *)&cs,sizeof(customer));
 if(strcmp(cs.getname1().getname(),name)==0)
  //注意这里要通过间接调用,因为这里是单纯的二进制文件数据
  {ii=1;
   break;}
 }
 if(ii==1)
 {cout<<"该顾客信息如下|"<<endl;
  cout<<"---------------------------------------/n";
  cout<<cs;
  cout<<"---------------------------------------/n";
  cout<<"请输入新的信息|"<<endl;
  cin>>cs;
  cout<<"OK!修改成功!"<<endl;
  cus.seekp(-long(sizeof(customer)),ios::cur);
  cus.write((char *)&cs,sizeof(customer));
 }
 else
  cout<<"不存在该顾客的信息!可能姓名输入错误。"<<endl;
 cus.close();}

你可能感兴趣的:(航天定票管理系统(上千行代码))