您好,我正在尝试对学校系统进行一些模拟。
我想知道我是否有 2 个类: 1:校长 2:教师 那么校长类的方法是否可以创建教师类的新对象?
这是我想做的(方法 AddTeacher):
class PRINCIPAL
{
char* name;
int wage;
unsigned long long id;
public:
void showinfo() const;
PRINCIPAL();//constructor, but there will be overloaded constructors in this class;
~PRINCIPAL();
void addTeacher(char* nameofobject,char* name,char* position,int wage, unsigned long long id);
void removeTeacher(TEACHER& teacher); //method which will remove object of class TEACHER;
void changeTEACHERSsalary(TEACHER& teacher);
void changeTEACHERSposition(TEACHER& teacher);
}
class TEACHER
{
char* name;
char* position;
int wage;
unsigned long long id;
friend class PRINCIPAL;
public:
TEACHER(char* name,char* position,int wage, unsigned long long id);
~TEACHER();
void gradeStudent(STUDENT& s,int grade,char* subject);
void changestudentsgrade(STUDENT& s,char* subjectname,int oldgrade,int newgrade);
void ViewStudentsAverageFromSubject(STUDENT& s, char* subjectname) const;
void ViewStudentsAverage(STUDENT& s) const; // average from all subjects;
void ViewClassAverage(KLASA& k) const; // average from all subjects of whole object KLASA(class);
void ViewClassAverageSubject(KLASA& k,char* subjectname) const; // average from selected subject of whole object KLASA(class);
}
另外我想问一下是否可以做以下事情:我想做一个约束,它只允许 Principal 类的一个对象存在。如果可能的话,你能解释一下怎么做吗?
先感谢您。
PS addTeacher 看起来像这样:
void addTeacher(char* nameofobject,char* name,char* position,int wage, unsigned long long id){
TEACHER nameofobject(char* name,char* position,int wage, unsigned long long id);
}