鱼C论坛

 找回密码
 立即注册
查看: 2215|回复: 2

[已解决]zuhe.exe 中的 0x771d15ee 处有未经处理的异常: 0xC0000005: 读取位置 0x0000002c ...

[复制链接]
发表于 2017-4-5 22:16:10 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
一段程序独立运行正常。去掉测试用的头文件,把它写进头文件后,运行到指定函数出现错误“zuhe.exe 中的 0x771d15ee 处有未经处理的异常: 0xC0000005: 读取位置 0x0000002c 时发生访问冲突“。鄙人水平有限,希望大家指导指导。
#include<iostream>
#include<string>
using namespace std;
struct Product
{
        int pid;
        string pname;
        float pprice;
        int pnum;
        struct Product *next;
}*Headpro;
struct Customer
{
        int cid;
        string cname;
        string ctele;
        float cjifen;
        struct Customer *next;
}*Headcus;
void initP()//初始化
        {
                Headpro=new struct Product;
                Headpro->pid=0000;
                Headpro->pname="water";
                Headpro->pnum=9;
                Headpro->pprice=1.5;
                Headpro->next=NULL;
                Headcus=new struct Customer;
                Headcus->cid=0000;
                Headcus->cname="jiajia";
                Headcus->ctele="1111111";
                Headcus->cjifen=0;
                Headcus->next=NULL;
}
struct Product *findpro(string a)//按名称查找商品
{
        struct Product *pro;
        pro=new struct Product;
        pro=Headpro->next;
        while(pro!=NULL&&pro->pname!=a)
        {
                pro=pro->next;
        }
        if(pro==NULL){cout<<"没有该商品"<<endl;return NULL;}
        else return pro;
}
struct Product *findpro(int a)//按数目查找商品
{
        struct Product *pro;
        pro=Headpro->next;
        while(pro!=NULL&&pro->pnum<=a)
        {
                pro=pro->next;
        }
        if(pro==NULL){cout<<"已找出所有符合要求的商品。"<<endl;return NULL;}
        else return pro;
}
struct Product *endp()
{
        struct Product *prr;
        prr=Headpro;
        if(prr->next!=NULL)
        {
                prr=prr->next;
        }
        return prr;
}
void addpro()//添加商品
{
        struct Product *have,*proo;
        proo=new struct Product;
        cout<<"请输入要添加商品名称"<<endl;
        string name;
        cin>>name;
        have=findpro(name);
        if(have!=NULL)
                {cout<<"已经存在此商品"<<endl;
        return;}
        have=endp();
        have->next=proo;proo->next=NULL;
        cout<<"请输入商品的具体信息"<<endl;
        cout<<"商品ID"<<endl;cin>>proo->pid;
        cout<<"商品名称"<<endl;cin>>proo->pname;
        cout<<"商品价格"<<endl;cin>>proo->pprice;
        cout<<"商品数目"<<endl;cin>>proo->pnum;
        cout<<"添加商品成功"<<endl;
}
void showpro()//显示全部商品信息
{
        struct Product *pro;
        if(Headpro->next!=NULL)
        {
        cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
        do
        {
                pro=Headpro->next;
                cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;
        }
        while(pro->next!=NULL);
        }
}

void deletep()//删除商品
{
        cout<<"输入要删除的商品名称"<<endl;
        string name;
        cin>>name;
        struct Product *pro,*temp;
        pro=findpro(name);
        if(pro==NULL)
                cout<<"不存在该商品"<<endl;
        temp=Headpro;
        while(temp->next!=pro)
                temp=temp->next;
        temp->next=pro->next;
        free(pro);
}
void check()//查询某一商品
{
        cout<<"输入所要查找商品名称"<<endl;
        string name;
        cin>>name;
        struct Product *pro;
        pro=findpro(name);
        if(pro==NULL)
                cout<<"不存在该商品"<<endl;
        else{
                cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
                cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;}
}
void rcheck()//查询少于一定数目的商品
{
        cout<<"输入要查询少于多少数目的商品"<<endl;
        int i;
        cin>>i;
        struct Product *pro;
        pro=findpro(i);
        while(pro!=NULL){
                cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
                cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;}
}
void changep()//修改商品信息
{
        cout<<"输入要删除的商品名称"<<endl;
        string name;
        cin>>name;
        struct Product *pro;
        pro=findpro(name);
        if(pro==NULL)
                cout<<"不存在该商品"<<endl;
        int i=1;
        while(i)
        {
        cout<<"请问你要修改该商品的:"<<endl;
        cout<<"        1.ID 2.名称 3.价格 4.数目 5.不再修改"<<endl;
        cin>>i;
        switch(i)
        {
        case 1:cout<<"修改ID为:"<<endl;cin>>pro->pid;break;
        case 2:cout<<"修改名称为:"<<endl;cin>>pro->pname;break;
        case 3:cout<<"修改价格为:"<<endl;cin>>pro->pprice;break;
        case 4:cout<<"修改数目为:"<<endl;cin>>pro->pnum;break;
        case 5:i=0;break;
        default:cout<<"请选择正确选项"<<endl;
        }
        }
}
        

struct Customer *findcus(int a)//按会员代号查询信息
{
        struct Customer *cus;
        cus=Headcus->next;
        while(cus!=NULL&&cus->cid!=a)
        {
                cus=cus->next;
        }
        if(cus==NULL){cout<<"没有该商品"<<endl;return NULL;}
        else return cus;
}
void showcus()//显示会员信息
{
        struct Customer *cus;
        cus=Headcus;
        cout<<"会员代码"<<"  "<<"会员姓名"<<"  "<<"会员电话"<<"  "<<"会员积分"<<endl;
        if(cus->next!=NULL)
        {
                cus=cus->next;
                cout<<cus->cid<<'.'<<cus->cname<<','<<cus->ctele<<','<<cus->cjifen<<endl;
        }
}

void deletec()//删除会员
{
        cout<<"输入要删除的会员ID"<<endl;
        int i;
        cin>>i;
        struct Customer *cus,*temp;
        cus=findcus(i);
        if(cus==NULL)
                cout<<"不存在该会员"<<endl;
        temp=Headcus;
        while(temp->next!=cus)
                temp=temp->next;
        temp->next=cus->next;
        free(cus);
}
void changec()
{
        cout<<"请输入要更改会员代号"<<endl;
        int i;
        cin>>i;
        struct Customer *cus;
        cus=findcus(i);
        if(cus==NULL)
                cout<<"不存在此会员"<<endl;
        while(i)
        {
        cout<<"你要修改该会员的:"<<endl;
        cout<<"1.代号"<<"2.姓名"<<"3.电话"<<"4.积分"<<"5.修改结束"<<endl;
        switch(i)
        {
        case 1:cin>>cus->cid;break;
        case 2:cin>>cus->cname;break;
        case 3:cin>>cus->ctele;break;
        case 4:cin>>cus->cjifen;break;
        case 5:i=0;break;
        default:cout<<"输入错误"<<endl;
        }
}
}
//以上是头文件,下面是主函数。
#include<iostream>
#include<fstream>
#include<string>
#include"shangpinhuiyuan.h"
using namespace std;


void initsystem()
{
        
                cout<<"欢迎光临本超市"<<endl;
}

        void managerwindow()
{
        int k=1;
        while(k)
        {
        cout<<"请选择要执行的操作。"<<endl;
        cout<<"1.查看全部商品。"<<endl;
        cout<<"2.查看库存少于一定数量商品"<<endl;
        cout<<"3.删除商品。"<<endl;
        cout<<"4.添加商品。"<<endl;
        cout<<"5.修改商品。"<<endl;
        cout<<"6.查看会员信息。"<<endl;
        cout<<"7.修改会员信息。"<<endl;
        cout<<"8.删除会员。"<<endl;
        cout<<"9.查询销售额。"<<endl;
        cout<<"10.查询让利情况。"<<endl;
        cout<<"11.退出系统。"<<endl;
        cin>>k;
        switch(k){
        case 1:showpro();break;
                case 2:rcheck();break;
                case 3:deletep();break;
                case 4:addpro();break;
                case 5:changep();break;
                case 6:showcus();break;
                case 7:changec();break;
                case 8:deletec();break;
                case 9:cout<<"暂定"<<endl;
        }
        }
        }

void userwindow()
{
        int i=1;
        while(i)
        {cout<<"请选择你要的服务"<<endl;
        cout<<"1.选购商品。"<<endl;
                cout<<"2.以管理员身份登入。"<<endl;
                cout<<"3.退出商店。"<<endl;
        cin>>i;
        switch(i){
                case 1:cout<<"1.选购商品。"<<endl;break;
                case 2:managerwindow();break;
                case 3:i=0;break;
                default:cout<<"输入错误,请重新输入"<<endl;
                }
}
}

        

int main()
{
        
        initsystem();
while(1)
        {while(1)
{userwindow();break;}
managerwindow();break;
}
        return 0;
}

        
最佳答案
2017-4-6 11:38:22
本帖最后由 lumber2388779 于 2017-4-6 14:29 编辑

1.函数定义不能放在头文件中的,头文件只是用于放函数声明,还有变量定义等等,不能用于函数定义,你可以写多一个C文件用于放这些函数定义,头文件写上这些声明就可以了
2.你的initP并没有任何地方调用到这个函数,你所有创建出来的结构体指针都是空的,并没有指向任何结构体,这是你报错最主要原因
3.Headcus和Headpro这两个指针复用率太高,容易出错,建议使用typedef定义结构体进行使用
还有其他一些小问题,这些靠你自己去找下了

shangpinhuiyuan.cpp
#include<iostream>
#include<fstream>
#include<string>
#include"shangpinhuiyuan.h"
using namespace std;


void initsystem()
{

        cout<<"欢迎光临本超市"<<endl;
}

void managerwindow()
{
        int k=1;
        while(k)
        {
                cout<<"请选择要执行的操作。"<<endl;
                cout<<"1.查看全部商品。"<<endl;
                cout<<"2.查看库存少于一定数量商品"<<endl;
                cout<<"3.删除商品。"<<endl;
                cout<<"4.添加商品。"<<endl;
                cout<<"5.修改商品。"<<endl;
                cout<<"6.查看会员信息。"<<endl;
                cout<<"7.修改会员信息。"<<endl;
                cout<<"8.删除会员。"<<endl;
                cout<<"9.查询销售额。"<<endl;
                cout<<"10.查询让利情况。"<<endl;
                cout<<"11.退出系统。"<<endl;
                cin>>k;
                switch(k){
case 1:showpro();break;
case 2:rcheck();break;
case 3:deletep();break;
case 4:addpro();break;
case 5:changep();break;
case 6:showcus();break;
case 7:changec();break;
case 8:deletec();break;
case 9:cout<<"暂定"<<endl;
                }
        }
}

void userwindow()
{
        int i=1;
        while(i)
        {cout<<"请选择你要的服务"<<endl;
        cout<<"1.选购商品。"<<endl;
        cout<<"2.以管理员身份登入。"<<endl;
        cout<<"3.退出商店。"<<endl;
        cin>>i;
        switch(i){
case 1:cout<<"1.选购商品。"<<endl;break;
case 2:managerwindow();break;
case 3:i=0;break;
default:cout<<"输入错误,请重新输入"<<endl;
        }
        }
}

int main()
{
        initsystem();
        initP();
        while(1)
        {
                while(1)
                {
                        userwindow();
                        break;
                }
                managerwindow();
                break;
        }
        return 0;
}

shangpinhuiyuan.h
#include<iostream>
#include<string>
using namespace std;

typedef struct Product
{
        int pid;
        string pname;
        float pprice;
        int pnum;
        struct Product *next;
}*Headpro,xHeadpro;
typedef struct Customer
{
        int cid;
        string cname;
        string ctele;
        float cjifen;
        struct Customer *next;
}*Headcus,xHeadcus;

void initP();
Headpro findpro(string a);
Headpro findpro(int a);
Headpro endp();
void addpro();
void showpro();

void deletep();
void check();
void rcheck();
void changep();


Headcus findcus(int a);
void showcus();
void deletec();
void changec();

func.cpp
#include<iostream>
#include<string>
#include"Test7.h"
using namespace std;

Headpro headpro = NULL;
Headcus headcus = NULL;

void initP()//初始化
{
        headpro=new xHeadpro;
        headpro->pid=0000;
        headpro->pname="water";
        headpro->pnum=9;
        headpro->pprice=1.5;
        headpro->next=NULL;
        headcus=new xHeadcus;
        headcus->cid=0000;
        headcus->cname="jiajia";
        headcus->ctele="1111111";
        headcus->cjifen=0;
        headcus->next=NULL;
}
Headpro findpro(string a)//按名称查找商品
{
        Headpro pro;
        pro=new xHeadpro;
        pro=headpro->next;
        while(pro!=NULL&&pro->pname!=a)
        {
                pro=pro->next;
        }
        if(pro==NULL){cout<<"没有该商品"<<endl;return NULL;}
        else return pro;
}
Headpro findpro(int a)//按数目查找商品
{
        Headpro pro;
        pro=headpro->next;
        while(pro!=NULL&&pro->pnum<=a)
        {
                pro=pro->next;
        }
        if(pro==NULL){cout<<"已找出所有符合要求的商品。"<<endl;return NULL;}
        else return pro;
}
Headpro endp()
{
        Headpro prr;
        prr=headpro;
        if(prr->next!=NULL)
        {
                prr=prr->next;
        }
        return prr;
}
void addpro()//添加商品
{
        Headpro have,proo;
        proo=new xHeadpro;
        cout<<"请输入要添加商品名称"<<endl;
        string name;
        cin>>name;
        have=findpro(name);
        if(have!=NULL)
        {cout<<"已经存在此商品"<<endl;
        return;}
        have=endp();
        have->next=proo;proo->next=NULL;
        cout<<"请输入商品的具体信息"<<endl;
        cout<<"商品ID"<<endl;cin>>proo->pid;
        cout<<"商品名称"<<endl;cin>>proo->pname;
        cout<<"商品价格"<<endl;cin>>proo->pprice;
        cout<<"商品数目"<<endl;cin>>proo->pnum;
        cout<<"添加商品成功"<<endl;
}
void showpro()//显示全部商品信息
{
        Headpro pro;
        if(headpro->next!=NULL)
        {
                cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
                do
                {
                        pro=headpro->next;
                        cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;
                }
                while(pro->next!=NULL);
        }
}

void deletep()//删除商品
{
        cout<<"输入要删除的商品名称"<<endl;
        string name;
        cin>>name;
        Headpro pro,temp;
        pro=findpro(name);
        if(pro==NULL)
                cout<<"不存在该商品"<<endl;
        temp=headpro;
        while(temp->next!=pro)
                temp=temp->next;
        temp->next=pro->next;
        free(pro);
}
void check()//查询某一商品
{
        cout<<"输入所要查找商品名称"<<endl;
        string name;
        cin>>name;
        Headpro pro;
        pro=findpro(name);
        if(pro==NULL)
                cout<<"不存在该商品"<<endl;
        else{
                cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
                cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;}
}
void rcheck()//查询少于一定数目的商品
{
        cout<<"输入要查询少于多少数目的商品"<<endl;
        int i;
        cin>>i;
        Headpro pro;
        pro=findpro(i);
        while(pro!=NULL){
                cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
                cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;}
}
void changep()//修改商品信息
{
        cout<<"输入要删除的商品名称"<<endl;
        string name;
        cin>>name;
        Headpro pro;
        pro=findpro(name);
        if(pro==NULL)
                cout<<"不存在该商品"<<endl;
        int i=1;
        while(i)
        {
                cout<<"请问你要修改该商品的:"<<endl;
                cout<<"        1.ID 2.名称 3.价格 4.数目 5.不再修改"<<endl;
                cin>>i;
                switch(i)
                {
                case 1:cout<<"修改ID为:"<<endl;cin>>pro->pid;break;
                case 2:cout<<"修改名称为:"<<endl;cin>>pro->pname;break;
                case 3:cout<<"修改价格为:"<<endl;cin>>pro->pprice;break;
                case 4:cout<<"修改数目为:"<<endl;cin>>pro->pnum;break;
                case 5:i=0;break;
                default:cout<<"请选择正确选项"<<endl;
                }
        }
}


Headcus findcus(int a)//按会员代号查询信息
{
        Headcus cus;
        cus=headcus->next;
        while(cus!=NULL&&cus->cid!=a)
        {
                cus=cus->next;
        }
        if(cus==NULL){cout<<"没有该商品"<<endl;return NULL;}
        else return cus;
}
void showcus()//显示会员信息
{
        Headcus cus;
        cus=headcus;
        cout<<"会员代码"<<"  "<<"会员姓名"<<"  "<<"会员电话"<<"  "<<"会员积分"<<endl;
        if(cus->next!=NULL)
        {
                cus=cus->next;
                cout<<cus->cid<<'.'<<cus->cname<<','<<cus->ctele<<','<<cus->cjifen<<endl;
        }
}

void deletec()//删除会员
{
        cout<<"输入要删除的会员ID"<<endl;
        int i;
        cin>>i;
        Headcus cus,temp;
        cus=findcus(i);
        if(cus==NULL)
                cout<<"不存在该会员"<<endl;
        temp=headcus;
        while(temp->next!=cus)
                temp=temp->next;
        temp->next=cus->next;
        free(cus);
}
void changec()
{
        cout<<"请输入要更改会员代号"<<endl;
        int i;
        cin>>i;
        Headcus cus;
        cus=findcus(i);
        if(cus==NULL)
                cout<<"不存在此会员"<<endl;
        while(i)
        {
                cout<<"你要修改该会员的:"<<endl;
                cout<<"1.代号"<<"2.姓名"<<"3.电话"<<"4.积分"<<"5.修改结束"<<endl;
                switch(i)
                {
                case 1:cin>>cus->cid;break;
                case 2:cin>>cus->cname;break;
                case 3:cin>>cus->ctele;break;
                case 4:cin>>cus->cjifen;break;
                case 5:i=0;break;
                default:cout<<"输入错误"<<endl;
                }
        }
}

这是我修改的代码 你看下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-4-6 11:38:22 | 显示全部楼层    本楼为最佳答案   
本帖最后由 lumber2388779 于 2017-4-6 14:29 编辑

1.函数定义不能放在头文件中的,头文件只是用于放函数声明,还有变量定义等等,不能用于函数定义,你可以写多一个C文件用于放这些函数定义,头文件写上这些声明就可以了
2.你的initP并没有任何地方调用到这个函数,你所有创建出来的结构体指针都是空的,并没有指向任何结构体,这是你报错最主要原因
3.Headcus和Headpro这两个指针复用率太高,容易出错,建议使用typedef定义结构体进行使用
还有其他一些小问题,这些靠你自己去找下了

shangpinhuiyuan.cpp
#include<iostream>
#include<fstream>
#include<string>
#include"shangpinhuiyuan.h"
using namespace std;


void initsystem()
{

        cout<<"欢迎光临本超市"<<endl;
}

void managerwindow()
{
        int k=1;
        while(k)
        {
                cout<<"请选择要执行的操作。"<<endl;
                cout<<"1.查看全部商品。"<<endl;
                cout<<"2.查看库存少于一定数量商品"<<endl;
                cout<<"3.删除商品。"<<endl;
                cout<<"4.添加商品。"<<endl;
                cout<<"5.修改商品。"<<endl;
                cout<<"6.查看会员信息。"<<endl;
                cout<<"7.修改会员信息。"<<endl;
                cout<<"8.删除会员。"<<endl;
                cout<<"9.查询销售额。"<<endl;
                cout<<"10.查询让利情况。"<<endl;
                cout<<"11.退出系统。"<<endl;
                cin>>k;
                switch(k){
case 1:showpro();break;
case 2:rcheck();break;
case 3:deletep();break;
case 4:addpro();break;
case 5:changep();break;
case 6:showcus();break;
case 7:changec();break;
case 8:deletec();break;
case 9:cout<<"暂定"<<endl;
                }
        }
}

void userwindow()
{
        int i=1;
        while(i)
        {cout<<"请选择你要的服务"<<endl;
        cout<<"1.选购商品。"<<endl;
        cout<<"2.以管理员身份登入。"<<endl;
        cout<<"3.退出商店。"<<endl;
        cin>>i;
        switch(i){
case 1:cout<<"1.选购商品。"<<endl;break;
case 2:managerwindow();break;
case 3:i=0;break;
default:cout<<"输入错误,请重新输入"<<endl;
        }
        }
}

int main()
{
        initsystem();
        initP();
        while(1)
        {
                while(1)
                {
                        userwindow();
                        break;
                }
                managerwindow();
                break;
        }
        return 0;
}

shangpinhuiyuan.h
#include<iostream>
#include<string>
using namespace std;

typedef struct Product
{
        int pid;
        string pname;
        float pprice;
        int pnum;
        struct Product *next;
}*Headpro,xHeadpro;
typedef struct Customer
{
        int cid;
        string cname;
        string ctele;
        float cjifen;
        struct Customer *next;
}*Headcus,xHeadcus;

void initP();
Headpro findpro(string a);
Headpro findpro(int a);
Headpro endp();
void addpro();
void showpro();

void deletep();
void check();
void rcheck();
void changep();


Headcus findcus(int a);
void showcus();
void deletec();
void changec();

func.cpp
#include<iostream>
#include<string>
#include"Test7.h"
using namespace std;

Headpro headpro = NULL;
Headcus headcus = NULL;

void initP()//初始化
{
        headpro=new xHeadpro;
        headpro->pid=0000;
        headpro->pname="water";
        headpro->pnum=9;
        headpro->pprice=1.5;
        headpro->next=NULL;
        headcus=new xHeadcus;
        headcus->cid=0000;
        headcus->cname="jiajia";
        headcus->ctele="1111111";
        headcus->cjifen=0;
        headcus->next=NULL;
}
Headpro findpro(string a)//按名称查找商品
{
        Headpro pro;
        pro=new xHeadpro;
        pro=headpro->next;
        while(pro!=NULL&&pro->pname!=a)
        {
                pro=pro->next;
        }
        if(pro==NULL){cout<<"没有该商品"<<endl;return NULL;}
        else return pro;
}
Headpro findpro(int a)//按数目查找商品
{
        Headpro pro;
        pro=headpro->next;
        while(pro!=NULL&&pro->pnum<=a)
        {
                pro=pro->next;
        }
        if(pro==NULL){cout<<"已找出所有符合要求的商品。"<<endl;return NULL;}
        else return pro;
}
Headpro endp()
{
        Headpro prr;
        prr=headpro;
        if(prr->next!=NULL)
        {
                prr=prr->next;
        }
        return prr;
}
void addpro()//添加商品
{
        Headpro have,proo;
        proo=new xHeadpro;
        cout<<"请输入要添加商品名称"<<endl;
        string name;
        cin>>name;
        have=findpro(name);
        if(have!=NULL)
        {cout<<"已经存在此商品"<<endl;
        return;}
        have=endp();
        have->next=proo;proo->next=NULL;
        cout<<"请输入商品的具体信息"<<endl;
        cout<<"商品ID"<<endl;cin>>proo->pid;
        cout<<"商品名称"<<endl;cin>>proo->pname;
        cout<<"商品价格"<<endl;cin>>proo->pprice;
        cout<<"商品数目"<<endl;cin>>proo->pnum;
        cout<<"添加商品成功"<<endl;
}
void showpro()//显示全部商品信息
{
        Headpro pro;
        if(headpro->next!=NULL)
        {
                cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
                do
                {
                        pro=headpro->next;
                        cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;
                }
                while(pro->next!=NULL);
        }
}

void deletep()//删除商品
{
        cout<<"输入要删除的商品名称"<<endl;
        string name;
        cin>>name;
        Headpro pro,temp;
        pro=findpro(name);
        if(pro==NULL)
                cout<<"不存在该商品"<<endl;
        temp=headpro;
        while(temp->next!=pro)
                temp=temp->next;
        temp->next=pro->next;
        free(pro);
}
void check()//查询某一商品
{
        cout<<"输入所要查找商品名称"<<endl;
        string name;
        cin>>name;
        Headpro pro;
        pro=findpro(name);
        if(pro==NULL)
                cout<<"不存在该商品"<<endl;
        else{
                cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
                cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;}
}
void rcheck()//查询少于一定数目的商品
{
        cout<<"输入要查询少于多少数目的商品"<<endl;
        int i;
        cin>>i;
        Headpro pro;
        pro=findpro(i);
        while(pro!=NULL){
                cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
                cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;}
}
void changep()//修改商品信息
{
        cout<<"输入要删除的商品名称"<<endl;
        string name;
        cin>>name;
        Headpro pro;
        pro=findpro(name);
        if(pro==NULL)
                cout<<"不存在该商品"<<endl;
        int i=1;
        while(i)
        {
                cout<<"请问你要修改该商品的:"<<endl;
                cout<<"        1.ID 2.名称 3.价格 4.数目 5.不再修改"<<endl;
                cin>>i;
                switch(i)
                {
                case 1:cout<<"修改ID为:"<<endl;cin>>pro->pid;break;
                case 2:cout<<"修改名称为:"<<endl;cin>>pro->pname;break;
                case 3:cout<<"修改价格为:"<<endl;cin>>pro->pprice;break;
                case 4:cout<<"修改数目为:"<<endl;cin>>pro->pnum;break;
                case 5:i=0;break;
                default:cout<<"请选择正确选项"<<endl;
                }
        }
}


Headcus findcus(int a)//按会员代号查询信息
{
        Headcus cus;
        cus=headcus->next;
        while(cus!=NULL&&cus->cid!=a)
        {
                cus=cus->next;
        }
        if(cus==NULL){cout<<"没有该商品"<<endl;return NULL;}
        else return cus;
}
void showcus()//显示会员信息
{
        Headcus cus;
        cus=headcus;
        cout<<"会员代码"<<"  "<<"会员姓名"<<"  "<<"会员电话"<<"  "<<"会员积分"<<endl;
        if(cus->next!=NULL)
        {
                cus=cus->next;
                cout<<cus->cid<<'.'<<cus->cname<<','<<cus->ctele<<','<<cus->cjifen<<endl;
        }
}

void deletec()//删除会员
{
        cout<<"输入要删除的会员ID"<<endl;
        int i;
        cin>>i;
        Headcus cus,temp;
        cus=findcus(i);
        if(cus==NULL)
                cout<<"不存在该会员"<<endl;
        temp=headcus;
        while(temp->next!=cus)
                temp=temp->next;
        temp->next=cus->next;
        free(cus);
}
void changec()
{
        cout<<"请输入要更改会员代号"<<endl;
        int i;
        cin>>i;
        Headcus cus;
        cus=findcus(i);
        if(cus==NULL)
                cout<<"不存在此会员"<<endl;
        while(i)
        {
                cout<<"你要修改该会员的:"<<endl;
                cout<<"1.代号"<<"2.姓名"<<"3.电话"<<"4.积分"<<"5.修改结束"<<endl;
                switch(i)
                {
                case 1:cin>>cus->cid;break;
                case 2:cin>>cus->cname;break;
                case 3:cin>>cus->ctele;break;
                case 4:cin>>cus->cjifen;break;
                case 5:i=0;break;
                default:cout<<"输入错误"<<endl;
                }
        }
}

这是我修改的代码 你看下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-4-6 17:34:28 | 显示全部楼层
谢谢你的指导啊,新人第一次发帖,收到你那么精心的回复,感觉很温暖,很惊喜呢。。问题根据你的提示已经解决了。哈哈。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-6-26 22:16

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表