#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
class Student {
public:
Student(char name[],int age,int scores[],int number) {
this->name = new char[strlen(name)+1];
strcpy(this->name,name);
this->age=age;
for(int i=0; i<number; i++)
this->scores[i]=scores[i];
numOfCourses = number;
cout<<"Student "<<name<<" is created (1)."<<endl;
}
Student(char name[], int age=18) {
this->name = new char[strlen(name)+1];
strcpy(this->name, name);
this->age=age;
numOfCourses = 0;
cout<<"Student "<<name<<" is created (2)."<<endl;
}
void print() {
cout <<name <<"," << age;
cout << ",scores :";
for(int i=0; i<numOfCourses; i++)
cout << " " << scores[i];
cout<<endl;
}
~Student() {
cout<<"Student "<<name<<" is erased."<<endl;
delete[] name;
}
void changeName(char name[]) {
delete [] this->name;
this->name = new char[strlen(name)+1];
strcpy(this->name,name);
}
bool compare(const Student &another) {
double avg1, avg2;
int i;
avg1 = avg2 = 0;
for(i = 0; i < numOfCourses; i++)
avg1 += scores[i];
for(i = 0; i < another.numOfCourses; i++)
avg1 += another.scores[i];
if (numOfCourses > 0)
avg1 /= numOfCourses;
else
avg1 = 0;
avg2 = another.numOfCourses == 0 ? 0 : avg2 / another.numOfCourses;
if (fabs(avg1-avg2)<=0.001) {
return (strcmp(name, another.name)<0);
}
return avg1 > avg2;
}
private:
char *name;
int age;
int scores[10];
int numOfCourses;
};
int main() {
freopen("in.txt","r", stdin);
char str[10];
int data[10];
int age, cnt;
cin >> str;
cin >> age >> cnt;
for(int i=0; i<cnt; i++)
cin >> data[i];
Student wang(str,age,data, cnt);
wang.print();
Student li("LISI",19);
Student zhang("Zhang San");
li.print();
zhang.print();
zhang.changeName("Zhang Zhang");
zhang.print();
return 0;
}