#include <iostream>
#include
<cstring>

using namespace std;

class NameString{
private:
char *str;
public:
NameString(
char *s="...")
{
str
= new char[strlen(s)+1];
strcpy(str,s);
// cout<<"构造 NameString OK!"<<endl;
}

void print()
{
cout
<<str;
}

~NameString()
{
// cout<<"析构 NameString OK!"<<endl;
delete str;
}
};

class Student{
private:
int StudentNO;
NameString Name;
int Scores;
static int total_Scores;
static int total_Num;
public:
Student(
int a,char *b,int c):StudentNO(a),Name(b),Scores(c)
{
total_Scores
+= c;
total_Num
++;
// cout<<"构造 Student OK!"<<endl;
}

void print()
{
cout
<<StudentNO<<'\t';
Name.print();
cout
<<'\t'<<Scores<<endl;
}

void average()
{
cout
<<"Average:"<<total_Scores/total_Num<<endl;
}

static void total_disp()
{
cout
<<"Total_Scores:"<<total_Scores<<endl;
cout
<<"Total_Num:"<<total_Num<<endl;
}

};

int Student::total_Scores = 0;
int Student::total_Num = 0;

int main()
{
Student st1(
1,"wen",94);
Student st2(
2,"hao",100);
Student st3(
3,"lin",100);

cout
<<"学号"<<'\t'<<"姓名"<<'\t'<<"成绩"<<endl;
st1.print();
st2.print();
st3.print();

Student::total_disp();

st1.average();

return 0;

}

相关文章:

  • 2021-06-26
  • 2022-01-04
  • 2022-12-23
  • 2022-02-14
  • 2021-08-23
  • 2022-12-23
  • 2022-01-19
猜你喜欢
  • 2021-08-12
  • 2021-11-23
  • 2021-09-07
  • 2022-02-11
  • 2021-06-03
  • 2022-01-10
  • 2021-07-21
相关资源
相似解决方案