C++ 不知道错误怎么改,求助!!
#include"iostream.h"#include"string.h"#defineN5classstu{intno;charname[10];intch,en,m...
#include "iostream.h"
#include "string.h"
#define N 5
class stu
{
int no;
char name[10];
int ch,en,ma;
static int s1,s2,s3;
public:
stu(int n,char na[],int c,int e,int m)
{
no=n;
strcpy(name,na);
ch=c;
en=e;
ma=m;
s1+=ch;
s2+=en;
s3+=ma;
}
static double avr1(){return s1/N*1.0;}
static double avr2(){return s2/N*1.0;}
static double avr3(){return s3/N*1.0;}
void print()
{
cout<<no<<"\t"<<name<<"\t"<<ch<<"\t"<<en<<"\t"<<ma<<endl;
}
};
int stu::s1=0;
int stu::s2=0;
int stu::s3=0;
void main()
{
stu s[N];
int i,n;
char na[10];
int c,e,m;
for(i=0;i<N;i++)
cin>>n>>na>>c>>" ">>e>>" ">>m;
for(i=0;i<N;i++)
{
s[i].print();
}
cout<<"Chinese avrage:"<<stu::avr1()<<endl;
cout<<"English avrage:"<<stu::avr2()<<endl;
cout<<"Math avrage:"<<stu::avr3()<<endl;
}
谢谢各位大虾。。。 展开
#include "string.h"
#define N 5
class stu
{
int no;
char name[10];
int ch,en,ma;
static int s1,s2,s3;
public:
stu(int n,char na[],int c,int e,int m)
{
no=n;
strcpy(name,na);
ch=c;
en=e;
ma=m;
s1+=ch;
s2+=en;
s3+=ma;
}
static double avr1(){return s1/N*1.0;}
static double avr2(){return s2/N*1.0;}
static double avr3(){return s3/N*1.0;}
void print()
{
cout<<no<<"\t"<<name<<"\t"<<ch<<"\t"<<en<<"\t"<<ma<<endl;
}
};
int stu::s1=0;
int stu::s2=0;
int stu::s3=0;
void main()
{
stu s[N];
int i,n;
char na[10];
int c,e,m;
for(i=0;i<N;i++)
cin>>n>>na>>c>>" ">>e>>" ">>m;
for(i=0;i<N;i++)
{
s[i].print();
}
cout<<"Chinese avrage:"<<stu::avr1()<<endl;
cout<<"English avrage:"<<stu::avr2()<<endl;
cout<<"Math avrage:"<<stu::avr3()<<endl;
}
谢谢各位大虾。。。 展开
1个回答
展开全部
#include "iostream.h"
#include "string.h"
#define N 5
class stu
{
int no;
char name[10];
int ch,en,ma;
static int s1,s2,s3;
public:
// 错误的原因是因为你没有提供不带参数的构造函数
// 当你在程序中提供构造函数之后,编译器便不会
// 在提供构造函数了,所以你需要在类中提供一个
// 不带参数的构造函数
stu(){}
stu(int n,char na[],int c,int e,int m)
{
no=n;
strcpy(name,na);
ch=c;
en=e;
ma=m;
s1+=ch;
s2+=en;
s3+=ma;
}
static double avr1(){return s1/N*1.0;}
static double avr2(){return s2/N*1.0;}
static double avr3(){return s3/N*1.0;}
void print()
{
cout<<no<<"\t"<<name<<"\t"<<ch<<"\t"<<en<<"\t"<<ma<<endl;
}
};
int stu::s1=0;
int stu::s2=0;
int stu::s3=0;
void main()
{
stu s[N];
int i,n;
char na[10];
int c,e,m;
for(i=0;i<N;i++)
cin>>n>>na>>c>>" ">>e>>" ">>m;
for(i=0;i<N;i++)
{
s[i].print();
}
cout<<"Chinese avrage:"<<stu::avr1()<<endl;
cout<<"English avrage:"<<stu::avr2()<<endl;
cout<<"Math avrage:"<<stu::avr3()<<endl;
}
#include "string.h"
#define N 5
class stu
{
int no;
char name[10];
int ch,en,ma;
static int s1,s2,s3;
public:
// 错误的原因是因为你没有提供不带参数的构造函数
// 当你在程序中提供构造函数之后,编译器便不会
// 在提供构造函数了,所以你需要在类中提供一个
// 不带参数的构造函数
stu(){}
stu(int n,char na[],int c,int e,int m)
{
no=n;
strcpy(name,na);
ch=c;
en=e;
ma=m;
s1+=ch;
s2+=en;
s3+=ma;
}
static double avr1(){return s1/N*1.0;}
static double avr2(){return s2/N*1.0;}
static double avr3(){return s3/N*1.0;}
void print()
{
cout<<no<<"\t"<<name<<"\t"<<ch<<"\t"<<en<<"\t"<<ma<<endl;
}
};
int stu::s1=0;
int stu::s2=0;
int stu::s3=0;
void main()
{
stu s[N];
int i,n;
char na[10];
int c,e,m;
for(i=0;i<N;i++)
cin>>n>>na>>c>>" ">>e>>" ">>m;
for(i=0;i<N;i++)
{
s[i].print();
}
cout<<"Chinese avrage:"<<stu::avr1()<<endl;
cout<<"English avrage:"<<stu::avr2()<<endl;
cout<<"Math avrage:"<<stu::avr3()<<endl;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询