| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 327 人关注过本帖
标题:帮我看一下这个程序的错误
只看楼主 加入收藏
godder
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-8-14
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
帮我看一下这个程序的错误
#include <stdio.h>
#include <iostream.h>
class ka
{
public:
    int p,num,sum;
};
class b
{
public:
    int n,re;
};
class com
{
private:
    int text;
    ka a[10],*p;
    b bb,*pp;
public:
    void zengjia()
    {
        int n;
        FILE *fp;
        char ch;
        pp=bb;
        if((fp=fopen("list1","wb+"))==NULL)
        {
            printf("Cannot open file strike any key exit!");
        }
        fread(pp,sizeof(class b),1,fp);
        n=pp->n;
        n++;p=a[n];
        p->p=n;
        cout<<"请输入该卡号这次购买的数量:"<<endl;
        cin>>text;
        p->num=text;
        p->sum=p->sum+text;
        if((fp=fopen("list","wb+"))==NULL)
        {
            printf("Cannot open file strike any key exit!");
        }
        fwrite(p,sizeof(class ka),1,fp);
        fclose(fp);

    }
    void ser1()
    {
        int n;
        FILE *fp;
        char ch;
        pp=bb;
        if((fp=fopen("list1","wb+"))==NULL)
        {
            printf("Cannot open file strike any key exit!");
        }
        fread(pp,sizeof(class b),1,fp);
        n=pp->n;
        if((fp=fopen("list","wb+"))==NULL)
        {
            printf("Cannot open file strike any key exit!");
        }
        fread(p,sizeof(class ka),1,fp);
        fclose(fp);
        int k,i;
        cout<<"请输入要查询资料的卡号n_"<<endl;
        cin>>k;
        for(i=1;i<=n;i++)
            if(p->p==k)
            {
                cout<<"该卡号上次购买的数量是:"<<"\t"<<p->num<<endl;
                cout<<"该卡号一共购买的数量是:"<<"\t"<<p->sum<<endl;
            }
    }
    void ser2()
    {
        int n;
        FILE *fp;
        char ch;
        pp=bb;
        if((fp=fopen("list1","wb+"))==NULL)
        {
            printf("Cannot open file strike any key exit!");
        }
        fread(pp,sizeof(class b),1,fp);
        n=pp->n;
        int i;p=a;
        if((fp=fopen("list","wb+"))==NULL)
        {
            printf("Cannot open file strike any key exit!");
        }
        fread(p,sizeof(class ka),1,fp);
        fclose(fp);
        int sum,N,text1;
        for(i=1;i<=n;i++)
            sum=sum+p->sum;
        N=n;
        text1=sum/N;
        cout<<"所有会员一共购买的数量是:"<<"\t"<<sum<<endl;
        cout<<"会员总数是:"<<"\t"<<N<<endl;
        cout<<"会员的平均消费水平是"<<"\t"<<text1<<endl;
    }
};
void main()
{
    com con;
    int N;
    cout<<"1"<<"\t"<<"增加卡号"<<endl;
    cout<<"2"<<"\t"<<"查询卡号"<<endl;
    cout<<"3"<<"\t"<<"查询总数"<<endl;
    cout<<"请输入要进行项目:N_";
    cin>>N;
    switch(N)
    {
    case 1:
        {
            con.zengjia();
            break;
        }
    case 2:
        {
            con.ser1();
            break;
        }
    case 3:
        {
            con.ser2();
            break;
        }
    }
}
2009-08-15 23:47
风后
Rank: 2
等 级:论坛游民
帖 子:3
专家分:20
注 册:2009-7-26
收藏
得分:20 
指针赋值时出错,应把地址赋给指针
2009-08-16 00:47
风后
Rank: 2
等 级:论坛游民
帖 子:3
专家分:20
注 册:2009-7-26
收藏
得分:0 
  pp= &bb;
&p=&a[n];
2009-08-16 00:49
godder
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-8-14
收藏
得分:0 
谢谢
2009-08-16 00:59
快速回复:帮我看一下这个程序的错误
数据加载中...
 
   



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

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