您好,我正在嘗試對學校系統進行一點模擬。朋友功能可以創建新對象嗎? C++
我想知道如果我有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);
}
另外我想問一下,如果它可以做到以下幾點:我願做約束,這將允許只有一個對象類的主體存在。如果可能的話你能解釋我該怎麼做嗎?
預先感謝您。
P.S 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);
}
如果您只想要一個單一實例,則將Principal設置爲單例類,但這是有問題的。否則,在Teacher類中引入靜態Principal對象。 – DumbCoder 2012-04-25 18:22:00
在附註上,通過使用'std :: string'而不是'char *'來讓自己的生活更輕鬆。 – juanchopanza 2012-04-25 18:27:25
我不明白你要從中刪除教師。從某種容器? – thb 2012-04-25 18:40:37