| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 474 人关注过本帖
标题:大家帮忙看下,代码没错,但是运行出了问题,我已经是老驴计穷了,求帮忙。 ...
只看楼主 加入收藏
书生小白
Rank: 2
等 级:论坛游民
帖 子:39
专家分:16
注 册:2011-6-14
结帖率:42.86%
收藏
 问题点数:0 回复次数:0 
大家帮忙看下,代码没错,但是运行出了问题,我已经是老驴计穷了,求帮忙。。
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <cmath>
#define TURE 1;
#define ERORR 0;
#define OK 1;
#define FALSE 0;
#define NULL 0
using namespace std;
class city_point                                            //      用类定义城市坐标
{
private:
    string city_name;
    float x;                                                 //         经度
    float y;                                                    //      纬度
public:
    void Mast();
    void chset();
    void inset();
    void read();
    void show();
    void delset();
    void customer();
    void preserve();
    void dele_date();
    void look_city();
    void round_city();
    void set_city_point();
    class city_point *next;
};
void city_point::set_city_point()                              //     为城市坐标初始化的函数
{
    cin>>city_name;
    cin>>x;
    cin>>y;
}
class city_point *head=NULL;
//class city_point *head1=NULL;
class city_point *real=NULL;
void welcome()
{
 
    cout<<"__________________________________________________"<<endl;
    cout<<"-- -----------------------------------------------"<<endl;
    cout<<" ||    欢迎使用网络101班第一小组制作城市搜索系统   ||"<<endl; //主菜单
    cout<<" ||             1~管理员,2~使用者                 ||"<<endl;
    cout<<" ||               0 ~退出程序                      ||"<<endl;
    cout<<" ||  友情提示:为了正常保存数据,请按步骤退出程序  ||"<<endl;
    cout<<" ||               请输入您的身份                   ||"<<endl;
    cout<<"----------------------------------------------------"<<endl;
    cout<<"                  版本号:1.00   2011/9/30          "<<endl;
    cout<<"----------------------------------------------------"<<endl;
}

void city_point::Mast()                                               //管理员操作部分
{
    int i,temp;
    cout<<"请按任意键清屏";
    system("cls") ;
    cout<<"           ||******************************||"<<endl;
    cout<<"           ||  欢迎进入管理员后台操作      ||"<<endl;
    cout<<"           ||  新增城市请输入--[1]         ||"<<endl;
    cout<<"           ||  删除城市请输入--[2]         ||"<<endl;
    cout<<"           ||  修改城市请输入--[3]         ||"<<endl;
    cout<<"           ||  显示全部城市  --[4]         ||"<<endl;
    cout<<"           ||  返回主菜单输入--[0]         ||"<<endl;
    cout<<"           ||******************************||"<<endl;
    do
    {
        cin>>temp;
        if(temp<0  &&  temp>4)                                 //判断输入的值是否合理
        {
            cout<<"输入错误,请重新输入";                     //不合理提示错误,并返回重新输入
            continue ;
        }
        switch(temp)                                 
        {
        case 0: i=0;       break;
        case 1: inset();   break;                  //如果输入1,新增城市数据
        case 2: delset();  break;                 // 如果输入2,删除城市数据
        case 3: chset();   break;               //如果输入3,修改城市数据
        case 4: show();    break;
        }
    }
    while(i!=0);                                   //如果I为0,返回主菜单
}
void city_point::customer()                            //顾客使用
{
    cout<<"请按任意键清屏";
    system("cls") ;                                //  清屏
    int i,temp;
    cout<<"           |**************************|";
    cout<<"           |       欢迎使用本软件     |"<<endl;
    cout<<"           |     目标城市查找--[1]    |"<<endl;
    cout<<"           |     周边城市查找--[2]    |"<<endl;
    cout<<"           |      返回菜单-----[0]    |"<<endl;
    cout<<"           |************************|";
    do
    {
        cin>>temp;
        if(temp<0  &&  temp>2)//判断输入的值
        {
            cout<<"输入错误,请重新输入";   //输入错误提示,并重新输入
            continue ;
        }
        switch(temp)
        {
        case 0:i=temp;        break;  //如果temp为0,将temp赋值给i
        case 1:look_city();   break;  //如果输入为1,执行查看城市函数
        case 2:round_city();   break;  //如输入为果2,执行查找周边城市
        }
    }
    while(i!=0); //如果I为0,返回主菜单
}
void city_point::round_city()            //查城市找周边
{
    float len,a,b,num;
    string csname;
    city_point *p,*p1;
    p=p1=head;
    cout<<"请输入中心城市";
    cin>>csname;
    cout<<"请输入到周围城市的距离";
    cin>>len;
    for(p;p->next!=NULL;p=p->next)
    {
        if(csname==p->city_name)
        {
            p1=p;
        }
    }
    for(p;p->next!=NULL;p=p->next)
    {
        int i=0;
        a=p->x-p1->x;
        b=p->y-p1->y;
        num=sqrt(a*a+b*b);
        if(num>len)
        {
            if(i==0)
                cout<<"不合格城市";
            cout<<p->city_name<<"  "<<p->x<<"  "<<p->y<<"距离为:"<<num;
            continue;
        }
        cout<<"找到如下城市";
        if(num<=len)
        {
            cout<<p->city_name<<"  "<<p->x<<"  "<<p->y<<"距离为:"<<num;
            continue;
        }
        else
            cout<<"没有您要查询的城市";

    }


}
void city_point::look_city()//查看  
{
    int i=0;
    city_point *p;   
    string csname;
    p=head;
    cout<<"目前可供查询的城市有:"<<i<<"个"<<endl;
    cout<<"请输入您要查找的城市名";
    cin>>csname;
    do
    {
        if(csname==p->city_name)
        {
            cout<<csname<<"的信息如下:"<<"  ";
            cout<<"经度"<<p->x<<"  ";
            cout<<"纬度"<<p->y;
        }
        if(p->next==NULL)
        {
            cout<<"没有该城市,请联系管理员录入该城市坐标";
            break;
        }
    }
    while(p->next!=NULL);
}
void city_point::inset()    //新增城市信息
{
    float a,b;
    city_point *p;
    p=head;
    string csname;
    p=new city_point;
    cout<<"请输入您想要新增城市的信息";
    cout<<"城市名"<<" ";
    cin>>csname;
    cout<<"经度"<<" ";
    cin>>a;
    cout<<"纬度"<<" ";
    cin>>b;   
    cout<<setw(8)<<" "<<"城市名"<<setw(7)<<" "<<"经度"<<setw(7)<<" "<<"纬度";
    cout<<setw(8)<<" "<<csname<<setw(7)<<" "<<a<<setw(7)<<" "<<b;
    p->city_name=csname;
    p->x=a;
    p->y=b;
    real->next=p;
    cout<<"添加城市成功";

}
void city_point::delset()          //删除城市
{
    int a;
    city_point *p,*p1;
    p1=p=head;
    string csname;
    cout<<"请输入您要删除的城市名字";
    cin>>csname;
    for(p;p->next!=NULL;p=p->next)    //不是以p->next结束,而是p,多给一次循环,判断最后一个接点
    {
        if(p->city_name==csname)                                   //不设置头接点,此判断是判断是不是第一个城市接点
        {
            cout<<"请确认您要删除的城市数据"<<endl;
            cout<<p->city_name<<"  "<<p->x<<"  "<<p->y<<endl;
            cout<<"确认请按1"<<"  "<<"返回请按0"<<endl;
            cin>>a;
            if(a==1)
            {
                p1=p;
                p=p->next;
                delete p1;
                cout<<"删除完成";
                break;
            }
            if(a==0)break;

        }
        
        if(p->next->city_name==csname)
        {
            cout<<"请确认您要删除的城市数据"<<endl;
            cout<<p->next->city_name<<"  "<<p->next->x<<"  "<<p->next->y<<endl;
            cout<<"确认请按1"<<"  "<<"返回请按0"<<endl;
            cin>>a;
            if(a==1)
            {
                p1=p;
                p1->next=p1->next->next;
                p=p->next;
                delete p;
                cout<<"删除完成";
                break;
            }
            if(a==0)break;
               
            
        }
        
        if(p->next==NULL)
        {
            cout<<"没有你要删除的城市";
            break;

        }
    }
}
void city_point::chset()                      //修改
{
    float a,b;
    city_point *p,*p1;
    p1=head;
    p=head;
    string csname,csname1;
    cout<<"请输入您想要修改的城市";
    cin>>csname;
    for(p;p!=NULL;p=p->next)
    {
        if(p->next==NULL)
        {
            cout<<"没有您要查询的城市。";
            break;
        }
        if(csname==p->city_name)
        {
            cout<<"请输入新的城市名字<<endl";
            cin>>csname1;
            cout<<"请输入新的经度"<<endl;
            cin>>a;
            cout<<"请输入新的纬度"<<endl;
            cin>>b;
            p->city_name=csname1;
            p->x=a;
            p->y=b;
            cout<<"已经修改完毕";
            break;
        }
    }

}
void city_point::show()                     //打印
{
    int i=1;
    city_point *p=head;
    while(p->next!=NULL)
    {
        cout<<setw(8)<<" "<<"城市名"<<setw(7)<<" "<<"经度"<<setw(7)<<" "<<"纬度"<<endl;
        cout<<setw(8)<<" "<<p->city_name<<setw(7)<<" "<<p->x<<setw(7)<<" "<<p->y;
        p=p->next;
        i++;
    }
    cout<<"目前有"<<i<<"个城市可供查询";
}
void city_point::preserve()                     //保存
{
    city_point *p1,p2;
    ofstream outfile("date.txt",ios::app);
    if(!outfile)
    {
        cout<<"打开错误"<<endl;
        exit(1);
    }
    for(p1=head;p1!=NULL;p1=p1->next)
    {
        outfile<<p1->city_name<<"  ";
        outfile<<p1->x<<"  ";
        outfile<<p1->y<<"  "<<endl;
    }
    outfile.close();
}
void city_point::read()                          //读取文件
{
    int i=0;
    city_point *p1,*p2;
    ifstream infile("date.txt",ios::in);                     //定义输入流文件对象,以输入方式打开文件
    if(!infile)
    {
        cout<<"文件打开失败";
        exit(1);
    }
    p1=p2=head=new class city_point;
    //head1->next =head;
    infile>>p1->city_name;
    infile>>p1->x;
    infile>>p1->y;
    while(p1->next!=NULL)              //P1和p->next有的区别
    {
        p1=new class city_point;
        infile>>p1->city_name;
        infile>>p1->x;
        infile>>p1->y;
        p2->next=p1;
        p1=p1->next;
        i++;
    }
    p1=real;
    p2->next=NULL;
    infile.close();
}
void city_point::dele_date()               //释放空间
{
    city_point *p=head;
    city_point *p1=head;
    do
    {
        p1=p;
        delete p;
        p=p1->next;
    }
    while(p1->next!=NULL);
}
int main()//主函数
{
    int i,temp;                                                        //    定义临时变量
    welcome();
    city_point *city=NULL;
    city->read();                                                          //从文件里面读取数据
    do                                                               // 主菜单,调用函数用switch分支语句
    {
        cin>>temp;
        if(temp<0  &&  temp>2)                                            // 判断输入的值是否合理
        {   
            cout<<"输入错误,请重新输入";                             //不合理提示错误,并返回重新输入
            continue;
        }
        switch(temp)
        {
        case 0:i=temp;       break;                                      // 返回主菜单
        case 1: city->Mast();      break;                                        // 管理员操作函数
         case 2: city->customer();   break;                                     // 使用人员操作函数
        }
    }
    while(i!=0);                                                       //  当I的值为0时返回主菜单
    return 0;
}
搜索更多相关主题的帖子: include private public class 
2011-10-01 19:04
快速回复:大家帮忙看下,代码没错,但是运行出了问题,我已经是老驴计穷了,求帮 ...
数据加载中...
 
   



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

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