求解答
c语言吧
全部回复
仅看楼主
level 4
yingb2010 楼主
求各位大侠的解答,就是找找这个编译不过的错误~谢谢啦~
#include"stdafx.h"
#include"iostream"
using namespace std;
#define N 3
class Stud
{
private:
     int no;
     char name[8];
     int deg;
static int sum;//总分
static int num;//人数
public:
     void setdata(int number,char *name1,int score);//赋值
     void disp();//输出
     void sum1(int );
     static int avg();
    
};
void Stud::setdata(int number,char *name1,int score)
{
         deg=score;
         no=number;
         strcpy(name,name1);
}
int Stud::avg()//静态成员函数
{    
     return sum/N;
}
void Stud::sum1(int score)
{
     sum=sum+score;
}
void Stud::disp()
{
cout<<no<<" "<<name<<" "<<deg<<endl;
}
//静态数据成员初始化
int Stud::sum=0;
int Stud::num=0;
int main(int argc, char* argv[])
{     int i,number,score;
     char name;
     Stud a[N];
    
     for(i=0;i<N;i++)
     {
         cout<<"输入学号 姓名 成绩:"<<endl;
         scanf("%d %s %d",&number,name,&score);
     //     scanf("%s",name);
     //     scanf("%d",&score);
         a[i].setdata(int number,char *name,int score);     //设置
         a[i].sum1(int score);     //总计
     }
     cout<<"学号 "<<"姓名 "<<"成绩"<<endl; //开始按照格式输出
     for(i=0;i<N;i++)
     {
         a[i].disp();
         cout<<"\n"<<endl;
     }
     cout<<"平均分="<<Stud::avg()<<endl;
     return 0;
}

2010年10月17日 10点10分 1
1