碰到难处了,大家帮帮忙!!
#include<iostream>
#include<cstring>
using namespace std;
class Person
{
public:
Person(){}
Person(const char* n, const char* s, const int a)
{
name = new char[strlen(n)+1];
strcpy(name,n);
sex = new char[strlen(s)+1];
strcpy(sex,s);
age = a;
}
void print() const
{
cout<<"Name:"<<name<<" "
<<"Sex:"<<sex<<" "
<<"Age:"<<age<<endl;
}
~Person()
{ delete [] name;
delete [] sex;
}
protected:
har* name;
char* sex;
int age;
};
class Student: public Person
{
public:
Student(const char* n, const char* s, const int a,
const char*sc, const int id) : Person(n,s,a)
{
schoolclass = new char[strlen(sc)+1];
strcpy(schoolclass, sc);
ID = id;
}
void print() const
{
Person::print();
cout<<"SchoolClass:"<<schoolclass<<" "
<<"ID:"<<ID<<endl;
}
protected:
char* schoolclass;
int ID;
};
class SchoolClass: public Student
{
public:
SchoolClass(const int id, const char* n)
{
ID = id;
name = new char[strlen(n)+1];
strcpy(name, n);
}
protected:
int ID;
char* name;
};
void main()
{
Student student("wang","男",28,"23班",35);
student.print();
return;
}
=======================================
我想让一个班级最多只能有40名学生,当然也可以少于40人拉.请教该怎么添加代码呢?