帮忙debug一下下面这段代码,高分求助!

[复制链接]
查看11 | 回复1 | 2011-6-24 02:41:09 | 显示全部楼层 |阅读模式
<ahref=\"http://hi.baidu.com/xiaohuoban160/blog/item/d2923b793c94ca200cd7dad2.html\"target=\"_blank\">http://hi.baidu.com/xiaohuoban160/blog/item/d2923b793c94ca200cd7dad2.html</a>
回复

使用道具 举报

千问 | 2011-6-24 02:41:09 | 显示全部楼层
/*
L.Load();函数里面
判断文件不存在后,执行后面的语句,指针异常
*/

#includeiostream
#includestring
#includefstream
usingnamespacestd;


classLogin_Info
{
        stringID;//账号
        stringPassword;//密码
        intRating;//权限
        classLogin_Info*next;
        friendclassRegister_Info;//设置类Register_Info为友元类
        public:
        Login_Info():ID(\"tietuo\"),Password(\"16030\"){};
};


classRegister_Info
{
        Login_Info*head;
        intflag;
        public:
        intrating;
        Register_Info():head(NULL),flag(0){}
        ~Register_Info(){}
        voidInit();//链表初始化
        intLen();
        voidSave();//保存用户账号信息
        voidLoad();
        boolRegister();//添加新用户
        boolRegister_Info::Find(Login_Info*//查找链表中用户名和密码都相符的位置
        boolChange_Pass();//修改用户密码
        boolLogin(int//用户登录
        voidMenu(int//登陆界面
        intGet_flag(){returnflag;}
};


Register_InfoL;
voidRegister_Info::Init()
{
        head=newLogin_Info;
        head-next=NULL;
}

intRegister_Info::Len()
{
        intnum=0;
        Login_Info*pt;
        pt=head;
        while(pt)
        {
                num;
                pt=pt-next;
        }
        returnnum;
}


voidRegister_Info::Save()
{
        intLEN;
        fstreamfp;
        Login_Info*pt;
        pt=head;
        LEN=Len();
        fp.open(\"Register_Information.txt\");
        if(fp.fail())
        cerr\"打开文件失败!\"endl;
        fpLENendl;
        while(pt)
        {
                fppt-ID\"\\t\"pt-Password\"\\t\"pt-Ratingendl;
                pt=pt-next;
        }
        fp.close();
}

voidRegister_Info::Load()
{
        intLEN;
        fstreamfp;
        Login_Info*p,*q;
        fp.open(\"Register_Information.txt\");
        if(fp.fail())
                cerr\"打开文件失败!\"endl;
        else
        {
                fpLEN;
                p=head;
               
                for(inti=0;iLEN;i)
                {
                        q=newLogin_Info;
                        fpq-IDq-Passwordq-Rating;
                        p-next=q;
                        p=p-next;
                }
                q-next=NULL;
               
                fp.close();
        }
}



boolRegister_Info::Register()
{
        Login_Info*p,*q,*r;
        stringst1,st2,st3;
        intst4;
        intn;
        p=head;
        while(p-next)
        p=p-next;
        q=newLogin_Info;
        while(1)
        {
                cout\"增加新用户\"endl;
                cout\"********************************\"endl;
                cout\"用户名:\";
                cinst3;
               
                r=head;
                while(st3!=r-IDnext;
                if(st3==r-ID)
                {
                        cout\"该用户名已存在,请重新输入!\"endl;
                        continue;
                }
                cout\"密码:\";
                cinst1;
                cout\"密码确认\";
                cinst2;
                if(st1!=st2)
                {
                        cout\"两次输入的密码不一致!\"endl;
                        continue;
                }
                cout\"用户权限(1.老师,2.学生):\"endl;
                cinst4;
                cout\"********************************\"endl;
                cout\"请选择:(1.注册,2.退出)\"endl;
                cinn;
                if(n==1)
                {
                        q-ID=st3;
                        q-Password=st1;
                        q-Rating=st4;
                        flag=1;
                        returntrue;
                }
                elseif(n==2)
                        returnfalse;
                else
                {
                cout\"输入有误!请重新输入\"endl;
                returnfalse;
                }
        }
}

boolRegister_Info::Find(Login_Info*
        p=head;
        while((str1!=p-ID||str2!=p-Password)next;
        if(p!=NULL)
        {
                q=p;
                returntrue;
        }
        else
        returnfalse;
}

boolRegister_Info::Change_Pass()
{
stringstr1,str2,str3,str4;
Login_Info*s=NULL;
cout\"更改密码\"endl;
cout\"********************************\"endl;
cout\"用户名:\";
cinstr1;
cout\"旧密码:\";
cinstr2;
if(Find(s,str1,str2))
{
        while(1)
        {
                cout\"新密码:\";
                cinstr3;
                cout\"密码确认:\";
                cinstr4;
                if(str3==str4)
                {
                        s-ID=str1;
                        s-Password=str3;
                        flag=1;
                        returntrue;
                }
                else
                        cout\"两次输入的密码不一致!\"endl;
                }
        }
        else
        {
                cout\"用户名和密码不正确!\"endl;
                returnfalse;
        }
}

boolRegister_Info::Login(int
stringst1,st2;

cout\"用户名:\";
cinst1;
cout\"密码:\";
cinst2;
if(Find(s,st1,st2))
{
L_rating=s-Rating;
returntrue;
}
else
returnfalse;
}

voidRegister_Info::Menu(int
        while(1)
        {
                system(\"cls\");
                cout\"成绩查询系统登录页面\"endl;
                cout\"**********************************************\"endl;
                cout\"1.登陆2.游客身份\"endl;
                cout\"3.注册4.修改密码\"endl;
                cout\"5.退出\"endl;
                cout\"**********************************************\"endl;
                cini;
                if(i==1)
                {
                        system(\"cls\");
                        Login(M_rating);
                        break;
                }
                elseif(i==2)
                {
                        M_rating=0;
                        break;
                }
                elseif(i==3)
                {
                        system(\"cls\");
                        Register();
                }
                elseif(i==4)
                {
                        system(\"cls\");
                        Change_Pass();
                }
                elseif(i==5)
                        exit(0);
                else
                        cerr\"选择有误!\"endl;
        }
}


intmain(intargc,int*argv[])
{
        intrating;
        L.Load();

        L.Menu(rating);
        if(L.Get_flag())
        L.Save();
        cout\"权限:\"ratingendl;
       

        return0;
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行