#include
#include
using namespace std;
class Student
{
public:
Student(int number = 0, const char* name = "", float score = 0.0);//对于字符串,此处必须加const
Student(const Student& Stu);
~Student();
void show(void);
friend void Average(const Student* p, int length);
friend void SetProperty(Student* p, int length);
private:
int number;
char name[20];
float score;
};
Student::Student(int number, const char* name, float score)
{
this->number = number;
strcpy_s(this->name, strlen(name) + 1, name);
this->score = score;
}
Student::Student(const Student& Stu)
{
this->number = Stu.number;
strcpy_s(this->name, strlen(Stu.name) + 1, Stu.name);
this->score = Stu.score;
}
void Student::show(void) {
cout << "学号:" << number << " 姓名:" << name << " 分数" << score << endl;
}
void Average(const Student* p, int length) {
double sum = 0;
for (int i = 0; i < length; i++) {
sum = sum + (p + i)->score;
}
cout<<"平均分"<number = i;
cout << "学号:" << i << endl;
cout << "姓名:";
cin >> (p + i)->name;
cout << "分数:";
cin >> (p + i)->score;
cout << endl;
}
}
Student::~Student()
{
}
int main(void) {
//Student S[3] = { Student(202001, "张三", 98),Student(202002, "李四", 88),Student(202003, "王五", 78)};
//cout << average(S);
Student* p = new Student[3];
SetProperty(p, 3);
Average(p,3);
for (int i = 0; i < 3; i++) {
(p + i)->show();
}
delete []p;
return 0;
}