#include<iostream> #include<string> using namespace std; class student { public: student(char *name1,char *num1,float score_a,float score_b,float score_c); ~student(); void panduan(); void show_basic(); void show_addition(); private: char *name; char *num; float score1; float score2; float score3; static int sum; static float avep; static float ave1; static float ave2; static float ave3; static float sum1; static float sum2; static float sum3; static float sum4; }; student::student(char *name1,char *num1,float score_a,float score_b,float score_c) { name=new char[strlen(name1)+1]; strcpy(name,name1); num=new char[strlen(num1)+1]; strcpy(num,num1); score1=score_a; score2=score_b; score3=score_c; ++sum; sum1=score1+score2+score3; //计算个人总分 sum2=sum2+score1; //计算全部人第1科总分 sum3=sum3+score2; //计算全部人第2科总分 sum4=sum4+score3; //计算全部人第3科总分 avep=sum1/3; //计算个人平均分 ave1=sum2/sum; ave2=sum3/sum; ave3=sum4/sum; //计算各科平均分 } student::~student() { delete []name; delete []num; } void student::show_basic() { cout<<"姓名:"<<name<<endl; cout<<"学号:"<<num<<endl; cout<<"程序设计:"<<score1<<endl; cout<<"信号处理:"<<score1<<endl; cout<<"数据结构:"<<score1<<endl; } void show_addition() { cout<<"学生人数:"<<sum<<endl; cout<<"个人平均成绩"<<avep<<endl; cout<<"程序设计平均成绩:"<<ave1<<endl; cout<<"信号处理平均成绩:"<<ave2<<endl; cout<<"数据结构平均成绩:"<<ave3<<endl; } void student::panduan() { int i,fail1,fail2,fail3; for(i=0;i<sum;i++) { if(score1<60) fail1++; } for(i=0;i<sum;i++) { if(score2<60) fail2++; } for(i=0;i<sum;i++) { if(score3<60) fail3++; } } int student::sum=0; float student::avep=0; float student::ave1=0; float student::ave2=0; float student::ave3=0; float student::sum1=0; float student::sum2=0; float student::sum3=0; float student::sum4=0; void main() { student stu1("li","070","70","55","60"); stu1.show_basic(); stu1.show_addition(); student stu2("lo","071","90","65","51"); stu2.show_basic(); stu2.show_addition(); }
出错的地方是这个,显示未定义可本人定义了,还有其他的错误;
解决方案
100
#include<iostream>
#include<string>
using namespace std;
class student
{
public:
student(char *name1, char *num1, float score_a, float score_b, float score_c);
~student();
void panduan();
void show_basic();
void student::show_addition();
private:
char *name;
char *num;
float score1; float score2; float score3;
static int sum; static float avep; static float ave1; static float ave2; static float ave3;
static float sum1; static float sum2; static float sum3; static float sum4;
static int fail1, fail2, fail3;
};
student::student(char *name1, char *num1, float score_a, float score_b, float score_c)
{
name = new char[strlen(name1) + 1];
strcpy(name, name1);
num = new char[strlen(num1) + 1];
strcpy(num, num1);
score1 = score_a; score2 = score_b; score3 = score_c;
++sum;
sum1 = score1 + score2 + score3; //计算个人总分
sum2 = sum2 + score1; //计算全部人第1科总分
sum3 = sum3 + score2; //计算全部人第2科总分
sum4 = sum4 + score3; //计算全部人第3科总分
avep = sum1 / 3; //计算个人平均分
ave1 = sum2 / sum; ave2 = sum3 / sum; ave3 = sum4 / sum; //计算各科平均分
}
student::~student()
{
delete[]name;
delete[]num;
}
void student::show_basic()
{
cout << “姓名:” << name << endl;
cout << “学号:” << num << endl;
cout << “程序设计:” << score1 << endl;
cout << “信号处理:” << score2 << endl;
cout << “数据结构:” << score3 << endl;
}
void student::show_addition()
{
cout << “学生人数:” << sum << endl;
cout << “个人平均成绩” << avep << endl;
cout << “程序设计平均成绩:” << ave1 << endl;
cout << “信号处理平均成绩:” << ave2 << endl;
cout << “数据结构平均成绩:” << ave3 << endl;
}
void student::panduan()
{
if (score1 < 60)
fail1++;
cout << “程序设计不及格人数” << fail1 << endl;
if (score2 < 60)
fail2++;
cout << “信号处理不及格人数” << fail2 << endl;
if (score3 < 60)
fail3++;
cout << “数据结构不及格人数” << fail3 << endl;
}
int student::sum = 0; float student::avep = 0; float student::ave1 = 0; float student::ave2 = 0; float student::ave3 = 0;
float student::sum1 = 0; float student::sum2 = 0; float student::sum3 = 0; float student::sum4 = 0;
int student::fail1 = 0; int student::fail2 = 0; int student::fail3 = 0;
void main()
{
char a[32], b[32], a1[32], b1[32];
float c, d, e, c1, d1, e1;
cin >> a >> b >> c >> d >> e;
student stu1(a, b, c, d, e);
stu1.show_basic();
stu1.show_addition();
stu1.panduan();
cout << endl << endl;
cin >> a1 >> b1 >> c1 >> d1 >> e1;
student stu2(a1, b1, c1, d1, e1);
stu2.show_basic();
stu2.show_addition();
stu2.panduan();
}
#include<string>
using namespace std;
class student
{
public:
student(char *name1, char *num1, float score_a, float score_b, float score_c);
~student();
void panduan();
void show_basic();
void student::show_addition();
private:
char *name;
char *num;
float score1; float score2; float score3;
static int sum; static float avep; static float ave1; static float ave2; static float ave3;
static float sum1; static float sum2; static float sum3; static float sum4;
static int fail1, fail2, fail3;
};
student::student(char *name1, char *num1, float score_a, float score_b, float score_c)
{
name = new char[strlen(name1) + 1];
strcpy(name, name1);
num = new char[strlen(num1) + 1];
strcpy(num, num1);
score1 = score_a; score2 = score_b; score3 = score_c;
++sum;
sum1 = score1 + score2 + score3; //计算个人总分
sum2 = sum2 + score1; //计算全部人第1科总分
sum3 = sum3 + score2; //计算全部人第2科总分
sum4 = sum4 + score3; //计算全部人第3科总分
avep = sum1 / 3; //计算个人平均分
ave1 = sum2 / sum; ave2 = sum3 / sum; ave3 = sum4 / sum; //计算各科平均分
}
student::~student()
{
delete[]name;
delete[]num;
}
void student::show_basic()
{
cout << “姓名:” << name << endl;
cout << “学号:” << num << endl;
cout << “程序设计:” << score1 << endl;
cout << “信号处理:” << score2 << endl;
cout << “数据结构:” << score3 << endl;
}
void student::show_addition()
{
cout << “学生人数:” << sum << endl;
cout << “个人平均成绩” << avep << endl;
cout << “程序设计平均成绩:” << ave1 << endl;
cout << “信号处理平均成绩:” << ave2 << endl;
cout << “数据结构平均成绩:” << ave3 << endl;
}
void student::panduan()
{
if (score1 < 60)
fail1++;
cout << “程序设计不及格人数” << fail1 << endl;
if (score2 < 60)
fail2++;
cout << “信号处理不及格人数” << fail2 << endl;
if (score3 < 60)
fail3++;
cout << “数据结构不及格人数” << fail3 << endl;
}
int student::sum = 0; float student::avep = 0; float student::ave1 = 0; float student::ave2 = 0; float student::ave3 = 0;
float student::sum1 = 0; float student::sum2 = 0; float student::sum3 = 0; float student::sum4 = 0;
int student::fail1 = 0; int student::fail2 = 0; int student::fail3 = 0;
void main()
{
char a[32], b[32], a1[32], b1[32];
float c, d, e, c1, d1, e1;
cin >> a >> b >> c >> d >> e;
student stu1(a, b, c, d, e);
stu1.show_basic();
stu1.show_addition();
stu1.panduan();
cout << endl << endl;
cin >> a1 >> b1 >> c1 >> d1 >> e1;
student stu2(a1, b1, c1, d1, e1);
stu2.show_basic();
stu2.show_addition();
stu2.panduan();
}