| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1456 人关注过本帖
标题:帮忙改一下,通过就行,谢谢了
只看楼主 加入收藏
不知道是谁
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-7-5
结帖率:0
收藏
已结贴  问题点数:20 回复次数:5 
帮忙改一下,通过就行,谢谢了
struct Bus
{
 
    int Stop_Id;  //公交站点自编号码
    string Stop_Name; //公交站点名
    Bus_line S;
 
};
 
struct Bus_line
{
    string Line_Id;  //公交线路的自编号码
    string Line_Name;// 公交线路名
    int LINE_STOP_INDEX ;//公交站点在所在公交线路运行路线中的索引号
    int LINE_DIRECTION;//0环线,1上行,2下行
 
};
 
 
 
2按路线查找所经过站点函数
using namespace std;
//公交线路查询函数
void Find_lines(Bus bus[],int Len,string nam)
{
    string stop1[300],stop2[300],stop0[300];
    int i,j,l,m,k,leap0,leap1,leap2;
    char c;
    string t;
    while(1)
    {
        cout<<endl;
        cout<<"\t请输入你要查询的公交线路名称(如104):"<<endl;
        cout<<"\t";
        cin>>nam;
        for(i=0,j=0,l=0,m=0; i根据线路方向查找并保存所查询的公交线路所经过的站点
        {
            if(nam==bus[i].S.Line_Name)
            {
                if(bus[i].S.LINE_DIRECTION==1)
                {
 
                    stop1[j]=bus[i].Stop_Name;
                    j++;
                }
                else if(bus[i].S.LINE_DIRECTION==2)
                {
                    stop2[l]=bus[i].Stop_Name;
                    l++;
 
                }
 
                else if(bus[i].S.LINE_DIRECTION==0)
                {
                    stop0[m]=bus[i].Stop_Name;
                    m++;
                }
 
            }
        }
 
        if(j!=0)
        {
            leap1=0;
            cout<<endl;
            cout<<"\t该公交线路所经过的站点为:"<<endl;
            cout<<"\t上行:"<<endl<<endl;   //
            for(i=0; i
            {
                for(k=0; k
                {
                    if(stop1[i]==stop1[k])
                    {
                        leap1=1;
                    }
                }
                if(leap1==0)
                    cout<<"\t"<<stop1[i]<<endl<<endl;
            }
            cout<<endl;
 
        }
 
        if(l!=0)
        {
            leap2=0;
            cout<<"\t下行:"<<endl;
            for(i=0; i
            {
                for(k=0; k
                {
                    if(stop1[i]==stop1[k])
                    {
                        leap2=1;
                    }
                }
                if(leap2==0)
                    cout<<"\t"<<stop2[i]<<endl<<endl;
            }
            cout<<endl;
 
        }
        if(m!=0)
        {
            leap0=0;
            cout<<"\t环行:"<<endl;
            for(i=0; i
            {
                for(k=0; k
                {
                    if(stop0[i]==stop0[k])
                    {
                        leap0=1;
                    }
                }
                if(leap0==0)
                    cout<<"\t"<<stop0[i]<<endl<<endl;
            }
            cout<<endl;
 
        }
        if(j==0&&l==0&&m==0)
        {
            cout<<"\t无此公交线路!!!"<<endl;
 
        }
        cout<<"\t线路查询结束,是否继续查询?(Y/N)"<<endl;
        cout<<"\t";
        cin>>c;
        while(c!='Y'&&c!='y'&&c!='N'&&c!='n')
        {
            printf("\t输入选择错误,请重新输入\n");
            cout<<"\t";
            cin>>c;
        }
        if(c=='n'||c=='N')
        {
            break;
        }
 
    }
}
 
 
 
 
 
3.按站点查找所经过该站点的所有公交路线
//公交站点查询函数
 
void Find_stops(Bus bus[],int Len,string station)
{
    int i,j,k,leap;
    string line[2000];
    char ch;
    while(1)
    {
        cout<<"\t请输入你要查询的公交站点 如(九堡):"<<endl;
        cout<<"\t";
        string station;
        cin>>station;
        for(i=0,j=0; i查找并保存经过该站点的所有公交线路
        {
            if(station==bus[i].Stop_Name)
            {
                line[j]=bus[i].S.Line_Name;
                j++;
            }
        }
 
        if(j==0)
        {
            cout<<"\t无此站点,请重新输入"<<endl;
 
        }
        else
        {
            cout<<"\t经过此站点的公交线路有:"<<endl<<endl;
            for(i=0; i筛选并输出公交线路
            {
                leap=0;
                for(k=0; k
                {
                    if(line[i]==line[k])
                        leap=1;
 
                }
                if(leap==0)
                    cout<<"\t"<<line[i]<<endl;
 
            }
            cout<<endl;
        }
 
 
        cout<<"\t是否继续查找线路?(Y/N)";
        cout<<"\t";
        cin>>ch;
        while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n')
        {
            printf("\t输入选择错误,请重新输入!\n");
            cout<<"\t";
            cin>>ch;
        }
        if(ch=='n'||ch=='N')
        {
            break;
        }
    }
}
 
 
 
 
 
4站点直达函数
//站点直达公交查询函数
 
int Line_Search(Bus bus[],int Len,string stop1,string stop2)
{
    int i,j,k,n,m,t,min,leap;
    min=200;
    int a[1000],b[1000];
    for(i=0,k=0,m=0; i
    {
        if(stop1==bus[i].Stop_Name)   //记录保存站点下标
        {
            a[k]=i;
            k++;
        }
        if(stop2==bus[i].Stop_Name)   //记录保存站点下标
        {
            b[m]=i;
            m++;
        }
 
    }
    leap=0;
    for(i=0; i
    {
        for(j=0; j
        {
            if((bus[b[j]].S.Line_Name==bus[a[i]].S.Line_Name)&&(bus[b[j]].S.LINE_DIRECTION==bus[a[i]].S.LINE_DIRECTION))
            {
                leap=1;
            }
        }
    }
    if(leap==0)
        return 0;
    else
    {
 
        for(i=0; i求两站点之间所经过的站点最少的线路
        {
            for(j=0; j
            {
                if((bus[b[j]].S.Line_Name==bus[a[i]].S.Line_Name)&&(bus[b[j]].S.LINE_DIRECTION==bus[a[i]].S.LINE_DIRECTION)&&(bus[b[j]].S.LINE_STOP_INDEX>bus[a[i]].S.LINE_STOP_INDEX))
                {
                    t=bus[b[j]].S.LINE_STOP_INDEX-bus[a[i]].S.LINE_STOP_INDEX;
                    if(t求两站点之间所经过的站点最少的线路
                    {
                        n=b[j];
                        min=t;
                    }
                }
            }
        }
    }
    return n ;
}
 
5.一次换乘线路查询函数
//  一次换乘查询函数
 
int Frist_transfer(Bus bus[],int Len,string Station1,string Station2)
{
    int Line_Search(Bus bus[],int,string,string);
    int i,j,a1,b1,i2,j2,k,m,p,q,r,line1[300],line2[300];
    int leap,leap1,leap2,a,b;
    string stop1[300],stop2[300],sta1[300],sta2[300],Change_stop[100];
    for(i=0,k=0,m=0; i
    {
        if(Station1==bus[i].Stop_Name)    //记录保存站点下标
        {
            line1[k]=i;
            k++;
        }
 
        if(Station2==bus[i].Stop_Name)  //记录保存站点下标
        {
            line2[m]=i;
            m++;
        }
    }
 
 
    for(i=0,p=0; i查找并保存同一公交路线上起始站点以后的所有站点
    {
        for(j=0; j
        {
            if(((bus[i].S.LINE_STOP_INDEX-bus[line1[j]].S.LINE_STOP_INDEX)>0)&&(bus[i].S.Line_Name==bus[line1[j]].S.Line_Name)&&(bus[i].S.LINE_DIRECTION==bus[line1[j]].S.LINE_DIRECTION))
            {
                stop1[p]=bus[i].Stop_Name;
                p++;
            }
 
        }
 
    }
    for(i=0,q=0; i查找并保存同一公交路线上终点以前的所有站点
    {
        for(j=0; j
        {
            if(((bus[i].S.LINE_STOP_INDEX-bus[line2[j]].S.LINE_STOP_INDEX)<0)&&(bus[i].S.Line_Name==bus[line2[j]].S.Line_Name)&&(bus[i].S.LINE_DIRECTION==bus[line2[j]].S.LINE_DIRECTION))
            {
                stop2[q]=bus[i].Stop_Name;
                q++;
            }
        }
    }
 
    for(i=0,a1=0,leap1=0; i
    {
        for(j=0; j
        {
            if(stop1[i]==stop1[j])
            {
                leap1=1;
            }
 
        }
        if(leap1==0)
        {
            sta1[i]=stop1[i];
            a1++;
        }
    }
 
    for(i=0,b1=0,leap2=0; i
    {
        for(j=0; j
        {
            if(stop2[i]==stop2[j])
            {
                leap2=1;
            }
 
        }
        if(leap2==0)
        {
            sta2[i]=stop2[i];
            b1++;
        }
    }
 
 
    leap=0;
    for(i2=0,r=0; i2查找并保存换乘站点
    {
        for(j2=0; j2
        {
            if(sta1[i2]==sta2[j2])
            {
                leap=1;
                Change_stop[r]=sta2[j2];
                r++;
            }
        }
    }
 
    if(leap==0)
    {
        return 0;
    }
    else
    {
        cout<<"\t";
        cout<<"一次换乘方案有"<<r<<"种:"<<endl;
        for(i=0; i输出换乘方案
        {
            cout<<"\t";
            cout<<"第"<<i+1<<"方案:"<<endl;
            a=Line_Search(bus,Len,Station1,Change_stop[i]);
            cout<<"\t您可在"<<Station1<<" 乘坐"<<bus[a].S.Line_Name<<"到"<<Change_stop[i]<<" 下车;"<<endl;;
            b=Line_Search(bus,Len,Change_stop[i],Station2);
            cout<<"\t在"<<Change_stop[i]<<" 站换乘"<<bus[b].S.Line_Name<<"到"<<Station2<<"下车."<<endl<<endl;
        }
    }
 
    return leap;
 
}
 
 
 
 
 
 
6. 二次换乘线路查询函数
// 二次换乘线路查询函数
 
int Second_transfer(Bus bus[],int Len,string STATION1,string STATION2)
{
    int Line_Search(Bus bus[],int,string,string);
    int i,j,i1,i2,i0,j0,k1,m1,p1,q1,Line1[1000],Line2[1000],Lcp,leap,leap1;
    string STOP1[1000],STOP2[1000],Stop1[1000],Stop2[1000];
    string StopA,StopB;
    int d,e,f;
    Lcp=0;
    for(i=0,k1=0,m1=0; i
    {
        if(STATION1==bus[i].Stop_Name)   //记录保存站点下标
        {
            Line1[k1]=i;
            k1++;
        }
 
        if(STATION2==bus[i].Stop_Name)  //记录保存站点下标
        {
            Line2[m1]=i;
            m1++;
        }
    }
 
    for(i=0,p1=0; i查找并保存同一公交路线上起始站点以后的所有站点
    {
        for(j=0; j
        {
            if(((bus[i].S.LINE_STOP_INDEX-bus[Line1[j]].S.LINE_STOP_INDEX)>0)&&(bus[i].S.Line_Name==bus[Line1[j]].S.Line_Name)&&(bus[i].S.LINE_DIRECTION==bus[Line1[j]].S.LINE_DIRECTION))
            {
                Stop1[p1]=bus[i].Stop_Name;
                p1++;
            }
 
        }
 
    }
 
    for(i=0,q1=0; i查找并保存同一公交路线上终点以前的所有站点
    {
        for(j=0; j
        {
            if(((bus[i].S.LINE_STOP_INDEX-bus[Line2[j]].S.LINE_STOP_INDEX)<0)&&(bus[i].S.Line_Name==bus[Line2[j]].S.Line_Name)&&(bus[i].S.LINE_DIRECTION==bus[Line2[j]].S.LINE_DIRECTION))
            {
                Stop2[q1]=bus[i].Stop_Name;
                q1++;
            }
        }
    }
 
    for(i=0,i1=0,leap=0; i
    {
        for(j=0; j
        {
            if(Stop1[i]==Stop1[j])
            {
                leap=1;
            }
 
        }
        if(leap==0)
        {
            STOP1[i1]=Stop1[i];
            i1++;
        }
    }
 
 
    for(i=0,i2=0,leap1=0; i
    {
        for(j=0; j
        {
            if(Stop2[i]==Stop2[j])
            {
                leap1=1;
            }
 
        }
        if(leap1==0)
        {
            STOP2[i2]=Stop2[i];
            i2++;
        }
    }
 
    for(i0=0; i0
    {
        for(j0=0; j0
        {
            e=Line_Search(bus,Len,STOP1[i0],STOP2[j0]);
            if(e!=0)
            {
                Lcp=1;
            }
        }
    }
    if(Lcp==0)
    {
        return 0;
    }
    else
    {
        cout<<"\t二次换乘方案有:"<<endl;
        for(i0=0; i0
        {
            for(j0=0; j0
            {
                e=Line_Search(bus,Len,STOP1[i0],STOP2[j0]);
                if(e!=0)
                {
                    StopA=STOP1[i0];
                    StopB=STOP2[j0];
                    d=Line_Search(bus,Len,STATION1,StopA);  //调用直达线路查询函数,求起点到中转站1的最佳线路
                    f=Line_Search(bus,Len,StopB,STATION2);// 调用直达线路查询函数,求中转站2到终点的最佳线路
                    cout<<"\t您可在"<<STATION1<<"站乘坐"<<bus[d].S.Line_Name<<"到"<<StopA<<"站下车;"<<endl;
                    cout<<"\t在"<<StopA<<"站换乘"<<bus[e].S.Line_Name<<"到"<<StopB<<" 站下车;"<<endl;
                    cout<<"\t在"<<StopB<<"站换乘"<<bus[f].S.Line_Name<<"到"<<STATION2<<"站下车."<<endl<<endl;
                }
 
            }
 
        }
    }
    return Lcp;
}
 
 
 
 
 
 
7.公交换乘函数
//公交换乘函数
 
void ChangeBus(Bus bus[],int Len,string Begain_stop,string End_stop)
{
    extern int Line_Search(Bus bus[],int,string,string);
    extern int Frist_transfer(Bus bus[],int,string,string);
    extern int Second_transfer(Bus bus[],int,string,string);
    int i,r1,r2,Leap,Leap1,Leap2;
    char c;
    while(1)
    {
        cout<<"\t请输入起点和终点:"<<endl;
        cout<<"\t起点:";
        cin>>Begain_stop;
        cout<<endl;
        cout<<"\t终点:";
        cin>>End_stop;
        for(i=0,r1=0,r2=0; i
        {
            if(Begain_stop==bus[i].Stop_Name)
                r1=1;
            if(End_stop==bus[i].Stop_Name)
                r2=1;
        }
 
        if(r1==1&&r2==1)
        {
            Leap=Line_Search(bus,Len,Begain_stop,End_stop);  //调用站点直达线路查询函数
            if(Leap!=0)
            {
                cout<<"\t您可在 "<<Begain_stop<<" 站乘坐"<<bus[Leap].S.Line_Name<<"公交到达 "<<End_stop<<"下车"<<endl<<endl;
            }
            else
            {
                cout<<"\t两站点之间无直达线路!!"<<endl;
                Leap1=Frist_transfer(bus,Len,Begain_stop,End_stop); // 调用一次换乘路线查询函数
                if(Leap1==0)
                {
                    cout<<"\t两站点无一次换乘线路!!"<<endl;
                    Leap2=Second_transfer(bus,Len,Begain_stop,End_stop);  // 调用二次换乘线路查询函数
                    if(Leap2==0)
                    {
                        cout<<"\t两站点无两次换乘线路!!"<<endl;
                        cout<<"\t因本公交系统不支持3次或3次以上的线路查询功能,此次查询结束,请见谅!"<<endl;
                    }
 
                }
 
            }
            cout<<"\t换乘查询结束,是否继续查询?(Y/N)..."<<endl;
            cout<<"\t";
            cin>>c;
            while(c!='Y'&&c!='y'&&c!='N'&&c!='n')
            {
                printf("\t输入选择错误,请重新输入...\n");
                cin>>c;
            }
            if(c=='n'||c=='N')
            {
                break;
            }
        }
        else
        {
            cout<<"\t你输入的站点有误,请重新输入..."<<endl;
        }
    }
}
 
 
 
 
 
 
 
8.数据载入函数
using namespace std;
// 公交数据载入函数
int File_read(Bus bus[],char* filename)
{
    int i=0;
 
    ifstream infile(filename,ios::in);
    if(!infile)
    {
        cerr<<"open errror!"<<endl;
        exit(1);
    }
    string r;
    getline(infile,r,'\n');
    while(!infile.eof())
    {
        //infile>>bus[i].ID;
        infile>>bus[i].S.Line_Id;
        infile>>bus[i].S.Line_Name;
        infile>>bus[i].Stop_Id;
        infile>>bus[i].Stop_Name;
        infile>>bus[i].S.LINE_STOP_INDEX;
        infile>>bus[i].S.LINE_DIRECTION;
        if(bus[i].Stop_Id>0)
            i++;
 
    }
    infile.close();
    return i;
 
}
 
 
9.
公交站点遍历
 
using namespace std;
//公交站点遍历
 
void Display_stops(Bus bus[],int Len)
{
 
    int i,j,leap,k=0;
    cout<<"\t该公交系统所有站点信息如下:"<<endl;
    cout<<"\t";
    for(i=0; i
    {
        leap=0;
        for(j=0; j
        {
            if(bus[i].Stop_Name==bus[j].Stop_Name)
            {
                leap=1;
 
            }
        }
        if(leap==0)
        {
 
            cout<<bus[i].Stop_Name<<"  ";
            k++;
            if(k%4==0)
            {
                cout<<endl<<endl;
                cout<<"\t";
            }
 
        }
    }
    cout<<endl<<endl;
    cout<<"\t该公交系统内共储存"<<k<<"个站点"<<endl;
    cout<<"\t";
    system("pause");
 
}
 
 
 
 
 
 
 
 
 
10.公交线路遍历
using namespace std;
 
void Display_lines(Bus bus[],int Len)
{
    int i,j,leap,k=0;
    cout<<"\t该公交系统所有公交线路信息如下:"<<endl;
    cout<<"\t";
    for(i=0; i
    {
        leap=0;
        for(j=0; j
        {
            if(bus[i].S.Line_Name==bus[j].S.Line_Name)
            {
                leap=1;
            }
        }
        if(leap==0)
        {
            cout<<bus[i].S.Line_Name<<"\t";
            k++;
            if(k%7==0)
            {
                cout<<endl<<endl;
                cout<<"\t";
            }
 
        }
 
    }
    cout<<endl<<endl;
    cout<<"\t公交系统内共"<<k<<"条线路"<<endl;
    cout<<"\t";
    system("pause");
 
}
 
 
 
 
 
 
 
11.mian函数
#include
#include
#include
#include
#include
#include
#include"Bus.h"
#define N 30000
#define Max 1000
#define LEN 30000
int Length;
using namespace std;
 
Bus bus[LEN];
 
 
int main()
{
    extern void welcome();
    extern void Exit();
    extern char menu();
    extern void Display_lines(Bus bus[],int);
    extern void Display_stops(Bus bus[],int);
    extern void Find_lines(Bus bus[],int,string);
    extern void Find_stops(Bus bus[],int,string);
    extern int File_read(Bus bus[],char *filename);
    extern void ChangeBus(Bus bus[],int,string,string);
    welcome();
    cout<<"\t";
    system("pause");
    system("cls");
    Length=File_read(bus,"busLinesInfo.txt");
    cout<<"\t\t   公交系统载入成功,共载入"<<Length<<"行数据"<<endl;
    char choice;
    string station,line_name;
    string Begain_stop,End_stop;
 
    while(1)
    {
        choice=menu();
        switch(choice)
        {
 
        case'1':
            Find_lines(bus,Length,line_name);
            break;
        case'2':
            Find_stops(bus,Length,station);
            break;
        case'3':
            ChangeBus(bus,Length,Begain_stop,End_stop);
            break;
        case'4':
            File_read(bus,"busLinesInfo.txt");
            cout<<"\t公交数据载入成功 !!!"<<endl;
            cout<<"\t";
            system("pause");
            break;
 
        case'5':
            Display_lines(bus,Length);
            break;
        case'6':
            Display_stops(bus,Length);
            break;
        case'7':
        {
            Exit();
            cout<<"\t";
            system("pause");
            return 0;
        }
        break;
        }
        default:
        {
            cout<<"\t输入选择错误,请重新输入!!!"<<endl;
        }break;
        }
    }
    return 0;
}
 
 
 
 
 
 
 
 
12菜单函数
//开始菜单
char menu()
{
    char s;
    cout<<" \t* * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl<<endl;
    cout<<" \t*           欢 迎 使 用 杭 州 公 交 管 理 系 统       *"<<endl<<endl;
    cout<<" \t*             1.公交线路查询    2.公交站点查询        *"<<endl<<endl;
    cout<<" \t*             3.公交换乘查询    4.公交数据载入        *"<<endl<<endl;
    cout<<" \t*             5.公交线路遍历    6 公交站点遍历        *"<<endl<<endl;
    cout<<" \t*             7.退出公交系统                          *"<<endl<<endl;
    cout<<" \t* * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl<<endl;
    cout<<" \t请选择您要实现的功能并输入序号:"<<endl;
    cout<<"\t";
    cin>>s;
    while(s!='1'&&s!='2'&&s!='3'&&s!='4'&&s!='5'&&s!='6'&&s!='7'&&s!='8'&&s!='9'&&s!='10')
    {
        cout<<"\t输入选择错误,请重新输入..."<<endl;
        cin>>s;
 
    }
    return s;
 
}
2015-07-05 16:29
实际应用
Rank: 5Rank: 5
等 级:职业侠客
威 望:2
帖 子:89
专家分:341
注 册:2015-5-30
收藏
得分:20 
哥们,能不能把问题描述一下呀
好找问题点呀
2015-07-05 16:32
不知道是谁
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-7-5
收藏
得分:0 
回复 2楼 实际应用
这个是个公交车模拟系统,有点错误,希望能改一下,通过就可以了
2015-07-05 16:33
实际应用
Rank: 5Rank: 5
等 级:职业侠客
威 望:2
帖 子:89
专家分:341
注 册:2015-5-30
收藏
得分:0 
是什么错误,具体点
编译错,运行错,还是结果错
错误信息贴出来
程序太长不想费事,只想直接找原因
2015-07-05 21:44
不知道是谁
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-7-5
收藏
得分:0 
回复 4楼 实际应用
编译错误,有很多处,例如:
1。for(i=0,j=0,l=0,m=0; i根据线路方向查找并保存所查询的公交线路所经过的站点
2. string Stop_Name; //公交站点名
    Bus_line S;
3.
2015-07-06 14:26
实际应用
Rank: 5Rank: 5
等 级:职业侠客
威 望:2
帖 子:89
专家分:341
注 册:2015-5-30
收藏
得分:0 
这都是基本语法的问题
1.for里没写,终止条件,右括号
2.结构Bus_line 的位置应在Stop_name 的前面
其他的,你贴出来再说吧
2015-07-06 21:14
快速回复:帮忙改一下,通过就行,谢谢了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021558 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved