c++设计地铁售票系统_c++ 课程设计之车票管理系统

1 #include//数据流输入/输出2 #include//文件输入/输出3 #include//字符串操作4 #include//参数化输入/输出5 #include//时间库函数6 usingnamespacestd;//命名空间7 8 classBus_infor9 {10 private:11 staticintBus_No;//静态数据成员,统计当前所有的Bus_infor对象的数目12 charstart[20];//起点站13 charend[20];//终点站14 intBus_order;//班次号15 intall_tickted;//额定载量16 inttickted;//已定票人数17 intHour_start,Minute_start;//发车时间18 floatGoHour;//行车时间19 20 public:21 Bus_infor();22 ~Bus_infor();23 Bus_infor*next;24 voidinput();//录入函数25 voidinput(ifstream&is);//读取函数26 voidoutput();//输出函数27 voidoutput(ofstream&os);//写入函数28 voidOrder_tickt(intn);//定票函数29 voidUnorder_tickt(intn);//退票函数30 voidGetTime_start();//获取发车时间函数31 boolGetTime();//判断当前班次状况函数32 intGet_all_tickted()  {returnall_tickted;  }//内联函数,返回额定载量33 intGet_tickted()  {returntickted; }//返回已定票人数34 intGet_bus_order()  {returnBus_order;  }//返回班次号35 stringGet_end()const;//返回终点站的字符串36 };37 38 intBus_infor::Bus_No=1;39 40 Bus_infor::Bus_infor()41 {42 Bus_No++;43 tickted=0;44 }45 46 Bus_infor::~Bus_infor()47 {48 Bus_No--;49 }50 51 voidBus_infor::input()52 {53 cout<>Bus_order;58 if(cin.fail())//判断输入的数据类型是否有错59 {60 cout<>all_tickted;71 if(cin.fail())//判断输入的数据类型是否有错72 {73 cout<>GoHour;85 if(cin.fail())//判断输入的数据类型是否有错86 {87 cout<>start;cin>>end;96 cout<>a;98 if(a=='y'||a=='Y') tickted=0;99 }100 101 voidBus_infor::input(ifstream&is)102 {103 is>>Bus_order>>Hour_start>>Minute_start>>start>>end>>GoHour>>all_tickted>>tickted;104 is.get();105 }106 107 voidBus_infor::output()108 {109 110 cout<>Hour_start>>Minute_start;145 if(cin.fail())//判断输入的数据类型是否有错146 {147 cout<24||Minute_start<0||Minute_start>60)152 cout<tm_hourtm_hour==Hour_start&&local->tm_min<=Minute_start))165 return1;//比较当前时间与发车时间,获得班次的当前状况,返回1表示班次未出发166 else167 return0;//返回0表示班次已出发168 }169 170 voidBus_infor::Order_tickt(intn)171 {172 tickted=tickted+n;173 }174 175 voidBus_infor::Unorder_tickt(intn)176 {177 tickted=tickted-n;178 }179 180 stringBus_infor::Get_end()const181 {182 strings=end;183 returns;184 }185 186 classBus_link187 {188 public:189 Bus_link(){head=newBus_infor;head->next=NULL;key=0;}//带参数的构造函数190 ~Bus_link(){delete head;}//析构函数191 voidinput();//录入车票信息192 voidmend();//修改车票信息193 voiddel();//删除车票信息194 intfind(Bus_infor**p1,intnum,char*pn);//查找函数,找出所有符合的195 intfind1(Bus_infor**p1,intnum,char*pn);//查找函数,找到符合的返回196 voidfound();//查询车票信息197 voidshow();//显示车票信息198 voidOrder();//定购车票信息199 voidUnorder();//退还车票信息200 voidsave();//保存车票信息201 voidbegin();//初始化车票信息202 voidclear();//清除函数203 voidabout();//关于车票信息204 charmainmenu();//主菜单函数205 voidsetkey(intk){ key=k; }//设置系统修改标志206 intgetkey(){returnkey;}//返回系统修改标志207 private:208 Bus_infor*head;//链表指针209 intkey;//系统修改标志210 intpassword;//管理员登陆标志211 };212 213 voidBus_link::input()214 {215 if(password==1)216 {217 Bus_infor*p,*p2=NULL;218 p=head;219 intn=1;220 while(p->next)221 p=p->next;222 while(n)223 {224 p2=newBus_infor;225 p2->input();226 p->next=p2;227 p2->next=NULL;228 p=p->next;229 Bus_link::setkey(1);230 cout<>n;232 if(!cin)233 throwstring("\n数据输入错误");234 Bus_link::setkey(1);235 }236 }237 else238 cout<next)248 {249 (p->next)->output();250 p=p->next;251 }252 }253 254 voidBus_link::found()255 {256 Bus_infor*p;257 intnum,n;258 charname[20];259 do260 {261 cout<>n;263 if(!cin)264 throwstring("\n数据输入错误");265 }while(n<1||n>2);266 if(n==1)267 {268 cout<>num;270 if(!cin)271 throwstring("\n数据输入错误");272 }273 if(n==2)274 {275 cout<>name;277 }278 if(!find(&p,num,name))279 {280 cout<next)291 {292 (*p1)=p;293 if( (p->next)->Get_bus_order()==num||(p->next)->Get_end()==pn )294 {295 cout<next)->output();298 t=1;299 }300 p=p->next;301 }302 returnt;303 }304 305 intBus_link::find1(Bus_infor**p1,intnum,char*pn)306 {307 Bus_infor*p;308 p=head;309 while(p->next)310 {311 (*p1)=p;312 if( (p->next)->Get_bus_order()==num||(p->next)->Get_end()==pn )313 {314 cout<next)->output();317 return1;318 }319 p=p->next;320 }321 return0;322 }323 324 voidBus_link::del()325 {326 if(password==1)327 {328 Bus_infor*p,*p2;329 intnum;charname[20];330 cout<>num;332 if(!cin)333 throwstring("\n数据输入错误");334 if(!find1(&p,num,name) )335 {336 cout<>a;341 if(a=='y'||a=='Y')342 {343 p2=p->next;344 p->next=p2->next;345 delete p2;346 Bus_link::setkey(1);347 }348 }349 else350 cout<>num;362 if(!cin)363 throwstring("\n数据输入错误");364 if(!find1(&p,num,name) )365 {366 cout<next)->input();370 Bus_link::setkey(1);371 }372 else373 cout<>X;383 if(X=='y'||X=='Y'){384 intnum;385 cout<>num;387 if(!cin)388 throwstring("\n数据输入错误");389 if(!find1(&p,num,"^") )390 {391 cout<next;395 if(!(p->GetTime()))//判断要定票的车辆是否已经出发,若已经出发则不允许定票396 {397 cout<>n;402 if(!cin)403 throwstring("\n数据输入错误");404 if((p->Get_tickted()+n)<=p->Get_all_tickted())405 p->Order_tickt(n);406 elsecout<>X;423 if(X=='y'||X=='Y'){424 intnum;425 cout<>num;427 if(!cin)428 throwstring("\n数据输入错误");429 if(!find1(&p,num,"^") )430 {431 cout<next;435 if(p->GetTime()==0)//判断要定票的车辆是否已经出发,若已经出发则不允许定票436 {437 cout<>n;442 if(!cin)443 throwstring("\n数据输入错误");444 if((p->Get_tickted()-n)>=0)445 p->Unorder_tickt(n);446 elsecout<next)466 {467 (p->next)->output(os);468 p=p->next;469 }470 }471 cout<>num;511 is.seekg(t);//移动到原来位置512 if(num<0)513 {514 is.close();515 return;516 }517 p2=newBus_infor;518 p2->input(is);//输入is对象内容519 p->next=p2;520 p2->next=NULL;521 p=p->next;522 }523 }524 525 voidBus_link::clear()526 {527 Bus_infor*p,*p2;528 p=head->next;529 while( p )530 {531 p2=p;532 p=p->next;533 delete p2;534 }535 }536 537 charBus_link::mainmenu()538 {539 structtm*local;540 chars1[128];541 time_t t;542 t=time(NULL);543 local=localtime(&t);544 strftime(s1,128,"%Y-%m-%d %H:%M",local);//按照指定的格式,把时间保存在s1字符串里面545 strings;//定义字符串s,来判断功能选择是否输入错误546 cout<>n;562 if(n=="1")563 {564 cout<>m;566 if(m=="123456")567 {568 password=1;569 cout<>s;587 if(s.length()!=1||s[0]'9')//s.length()返回字符串的长度,即字符个数588 cout<>i;625 if(!cin)626 throwstring("\n数据输入错误");627 }628 if(k==0||i==2)629 {630 if(pp.getkey()==1)631 {632 cout<>i;634 if(!cin)635 throwstring("\n数据输入错误");636 if(i==1)637 pp.save();638 pp.clear();639 k=0;640 }641 k=0;642 }643 }644 }645 catch(strings)646 {647 cout<

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#include<iostream> using namespace std; class C { public: float card_fee; virtual void real_fee() = 0; virtual void show_the_real_fee() = 0; }; class student : public C { public: student(float fee) { card_fee = fee; } void real_fee(){ card_fee *= 0.5; }//计算学生卡的实际费用 void show_the_real_fee(){ cout << "学生卡实际的费用是:" << card_fee<<"元"<<endl; } }; class older : public C { public: older(float fee){ card_fee = fee; } void real_fee(){ card_fee *= 0.6; }//计算老人卡的实际费用 void show_the_real_fee(){ cout << "老人卡实际的费用是:" << card_fee << "元" << endl; } }; class normal : public C { public: normal(float fee){ card_fee = fee; } void real_fee(){ card_fee *= 0.95; }//计算一般卡的实际费用 void show_the_real_fee(){ cout << "一般市民卡实际的费用是:" << card_fee << "元" << endl; } }; void main() { cout << "请输入公交费原价:"; float fee; cin >> fee; cout <<"公交费原价为"<<fee<<"元"<< endl; cout << "请输入刷卡人群性质" << endl << "学生卡:请输 1;" << endl << "老人卡:请输 2;" << endl << "普通卡:请输 3;" << endl; int man; cin >> man;//2.定义了一个变量,用于了解用户刷的卡的种类,以便进行相应的计算 C *p_card;//3.定义了一个父类指针,为了方便对子类的操作(即:该指针指向"谁"时,用这个指针调用的函数就是"谁"的函数,因为子类的函数的名子都一样,函数里的内容不一样,调用不同子类的函数后,计算的结果就不同) switch (man)//4.根据用户的输入,开启相应的功能 { case 1: {student stu_card(fee); p_card = &stu_card; p_card->real_fee(); p_card->show_the_real_fee();}break; case 2: {older old_card(fee); p_card = &old_card; p_card->real_fee(); p_card->show_the_real_fee();}break; case 3: {normal normal_card(fee); p_card = &normal_card; p_card->real_fee(); p_card->show_the_real_fee();}break; default:cout <<"输入错误!"<< endl;//5.如果用户输入的不是1,2,3,而是其他字符,则报错 } getchar();getchar(); }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值