中易网

公交线路管理,用C++

答案:2  悬赏:70  
解决时间 2021-04-27 13:56
  • 提问者网友:前事回音
  • 2021-04-27 08:57
模拟公交运营公司,对线路编号、始发站、终点站、首末车时间、具体途经站点进行录入、查询和修改。旅客可以按站站查询方式,获取乘车信息。线路信息需要文件存储。
最佳答案
  • 二级知识专家网友:晨与橙与城
  • 2021-04-27 09:48
汗,这个貌似太复杂了。。。
全部回答
  • 1楼网友:疯山鬼
  • 2021-04-27 10:00
void set( ) { bus b; fstream f1; int i=0,t=1; char c,n[100]; f1.open("1.txt",ios::in|ios::out); while(1) { if(c==&apos;n&apos;) break; cout<<"请输入要修改的线路(如:116):"<<endl; scanf("%s",n); while(!f1.eof()) { f1.read((char *)&b,sizeof(b)); if(strcmp(n,b.num)==0) { t=0; i=0; cout<<"请输入修改信息!"<<endl<<endl; cout<<"请修改始发站:"<<endl; cin>>b.starname; cout<<"请修改终点站:"<<endl; cin>>b.endname; cout<<"请修改发车时间:"<<endl; cin>>b.startime; cout<<"请修改到站时间:"<<endl; cin>>b.endtime; cout<<"请修改途经站点:"<<endl; cin>>b.linename; f1.seekg(-sizeof(b),ios::cur); f1.write((char *)&b,sizeof(b)); break; } f1.read((char *)&b,sizeof(b)); } if(t) { cout<<"未找到要修改的线路,是否继续修改?(y/n)!"<<endl; c=getchar();c=getchar(); continue; } cout<<"是否继续修改?(y/n):"<<endl; c=getchar();c=getchar(); } } }; void mchange() { char x1[20]; char x2[20]; while(1) { getchar(); cout<<"输入新密码:"<<endl; gets(x1); cout<<"再次输入新密码:"<<endl; gets(x2); if(strcmp(x1,x2)==0) { strcpy(password,x1); break; } else cout<<"密码不一致:"<<endl; } } void manag() { char x[20]; //输入次数 while(1) { cout<<"请输入密码:"<<endl; scanf("%s",x); system("cls"); if(strcmp(x,password)==0) { bus a; cout<<"\t\t o(∩_∩)o o(∩_∩)o"<<endl; cout<<"\t\t 管理员用户 "<<endl; cout<<"\t\t "<<endl; cout<<"\t\t 1、录入线路信息 "<<endl; cout<<"\t\t 2、修改线路信息 "<<endl; cout<<"\t\t 3、查询线路信息 "<<endl; cout<<"\t\t 4、修改用户密码 "<<endl; cout<<"\t\t 5、返 回 "<<endl; cout<<"\t\t "<<endl; cout<<"\t\t "<<endl; cout<<"\t\t "<<endl; cout<<"请输入选择:"<<endl; cin>>a.q; while(a.q!=5) { switch(a.q) { case 1:a.write();break; case 2:a.set();break; case 3:a.read();break; case 4:mchange();break; default:cout<<"输入有误:"<<endl; } cout<<"请输入选择:"<<endl; cin>>a.q; } break; } else cout<<"输入密码错误!"<<endl; } } void find() { fstream f1; int i=0,t; char s=&apos;y&apos;,n[100]; bus b; while(1) { t=1; if(s==&apos;n&apos;) break; cout<<"请输入要查询的线路(如:213):"<<endl; scanf("%s",n); f1.open("公交线路管理系统.txt",ios::in|ios::out|ios::app); while(!f1.eof()) { f1.read((char *)&b,sizeof(b)); if(strcmp(n,b.num)==0) { t=0; cout<<"始发站:"<<endl; cout<<"终点站:"<<endl; cout<<"首发车时间:"<<endl; cout<<"末班车时间:"<<endl; cout<<"输入途经的所有站点:"<<endl; f1.close(); break; } f1.read((char *)&b,sizeof(b)); } if(t) { f1.close(); cout<<"未找到要查询的线路,是否继续查询?(继续:y,推出:n)!"<<endl; s=getchar();s=getchar(); } else { cout<<"是否继续查询?(继续:y,推出:n):"<<endl; s=getchar();s=getchar(); } } } char exit() { char w; //system("cls"); cout<<"\t\t o(∩_∩)o o(∩_∩)o"<<endl; cout<<"\t\t 退出菜单 "<<endl; cout<<"\t\t "<<endl; cout<<"\t\t 1、确 定 "<<endl; cout<<"\t\t 2、取 消 "<<endl; cout<<"\t\t "<<endl; cout<<"\t\t "<<endl; cout<<"\t\t "<<endl; cout<<"请输入选择:"; cin>>w; return w; } void main() { int a; char s; while(1) { system("cls"); cout<<"\t\t o(∩_∩)o o(∩_∩)o"<<endl; cout<<"\t\t 公交管理 "<<endl; cout<<"\t\t "<<endl; cout<<"\t\t 1、信息查询 "<<endl; cout<<"\t\t 2、管理员用户 "<<endl; cout<<"\t\t 3、退 出 "<<endl; cout<<"\t\t "<<endl; cout<<"\t\t "<<endl; cout<<"\t\t "<<endl; cout<<"请输入选择:"; cin>>a; switch(a) { case 1:find();break; case 2:manag();break; case 3:s=exit();break; } if(s==&apos;1&apos;) break; } cout<<"感谢您使用本公交管理系统。谢谢,再见!"<<endl; }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息