![]() |
#2
qlc002009-11-03 22:29
# include<iostream>
using namespace std; class Teacher{ int tn; char *pt; char *ml; public: void SetTN(int tn); void SetPT(char *pt); void SetML(char *ml); int GetTN(); char *GetPT(); char *GetML(); }; class Student{ int sn; char *sf; char *grade; public: void SetSN(int sn); void SetSF(char *sf); void SetGRADE(char *grade); int GetSN(); char *GetSF(); char *GetGRADE(); }; class PostGraduate:public Teacher,public Student{ char *name; int age; public: void SetName(char *name); void SetAge(int age); char *GetName(); int GetAge(); }; void Teacher::SetTN(int tn){ this->tn=tn; } void Teacher::SetPT(char *pt){ this->pt=pt; } void Teacher::SetML(char *ml){ this->ml=ml; } int Teacher::GetTN(){ return this->tn; } char *Teacher::GetPT(){ return this->pt; } char *Teacher::GetML(){ return this->ml; } void Student::SetSN(int sn){ this->sn=sn; } void Student::SetSF(char *sf){ this->sf=sf; } void Student::SetGRADE(char *grade){ this->grade=grade; } int Student::GetSN(){ return this->sn; } char *Student::GetSF(){ return this->sf; } char *Student::GetGRADE(){//这里少一对括号 return this->grade; } void PostGraduate::SetName(char *name){ this->name=name; } void PostGraduate::SetAge(int age){ this->age=age; } char *PostGraduate::GetName(){ return this->name; } int PostGraduate::GetAge(){ return this->age; } void main(){ int sn,tn,age; char *pt,*ml,*sf,*grade,*name; PostGraduate pg; cout<<"请输入学号:"<<endl; cin>>sn; cout<<"请输入教工号:"<<endl; cin>>tn; cout<<"请输入姓名:"<<endl; cin>>name; cout<<"请输入年龄:"<<endl; cin>>age; cout<<"请输入班级:"<<endl; cin>>grade; cout<<"请输入专业:"<<endl; cin>>sf ;//这里少一个分号 cout<<"请输入主修课程:"<<endl; cin>>ml;//这里少一个分号 cout<<"请输入职称:"<<endl; cin>>pt; pg.Student::SetSN(sn); pg.Teacher::SetTN(tn); pg.SetName(name); pg.SetAge(age); pg.Student::SetGRADE(grade); pg.Student::SetSF(sf); pg.Teacher::SetML(ml); pg.Teacher::SetPT(pt); cout<<pg.Student::GetSN()<<endl; cout<<pg.Teacher::GetTN()<<endl; cout<<pg.GetName()<<endl; cout<<pg.GetAge()<<endl; cout<<pg.Student::GetGRADE()<<endl; cout<<pg.Student::GetSF()<<endl; cout<<pg.Teacher::GetML()<<endl; cout<<pg.Teacher::GetPT()<<endl; } |
# include<iostream>
using namespace std;
class Teacher{
int tn;
char *pt;
char *ml;
public:
void SetTN(int tn);
void SetPT(char *pt);
void SetML(char *ml);
int GetTN();
char *GetPT();
char *GetML();
};
class Student{
int sn;
char *sf;
char *grade;
public:
void SetSN(int sn);
void SetSF(char *sf);
void SetGRADE(char *grade);
int GetSN();
char *GetSF();
char *GetGRADE();
};
class PostGraduate:public Teacher,public Student{
char *name;
int age;
public:
void SetName(char *name);
void SetAge(int age);
char *GetName();
int GetAge();
};
void Teacher::SetTN(int tn){
this->tn=tn;
}
void Teacher::SetPT(char *pt){
this->pt=pt;
}
void Teacher::SetML(char *ml){
this->ml=ml;
}
int Teacher::GetTN(){
return this->tn;
}
char *Teacher::GetPT(){
return this->pt;
}
char *Teacher::GetML(){
return this->ml;
}
void Student::SetSN(int sn){
this->sn=sn;
}
void Student::SetSF(char *sf){
this->sf=sf;
}
void Student::SetGRADE(char *grade){
this->grade=grade;
}
int Student::GetSN(){
return this->sn;
}
char *Student::GetSF(){
return this->sf;
}
char *Student::GetGRADE{
return this->grade;
}
void PostGraduate::SetName(char *name){
this->name=name;
}
void PostGraduate::SetAge(int age){
this->age=age;
}
char *PostGraduate::GetName(){
return this->name;
}
int PostGraduate::GetAge(){
return this->age;
}
void main(){
int sn,tn,age;
char *pt,*ml,*sf,*grade,*name;
PostGraduate pg;
cout<<"请输入学号:"<<endl;
cin>>sn;
cout<<"请输入教工号:"<<endl;
cin>>tn;
cout<<"请输入姓名:"<<endl;
cin>>name;
cout<<"请输入年龄:"<<endl;
cin>>age;
cout<<"请输入班级:"<<endl;
cin>>grade;
cout<<"请输入专业:"<<endl;
cin>>sf
cout<<"请输入主修课程:"<<endl;
cin>>ml
cout<<"请输入职称:"<<endl;
cin>>pt;
pg.Student::SetSN(sn);
pg.Teacher::SetTN(tn);
pg.SetName(name);
pg.SetAge(age);
pg.Student::SetGRADE(grade);
pg.Student::SetSF(sf);
pg.Teacher::SetML(ml);
pg.Teacher::SetPT(pt);
cout<<pg.Student::GetSN()<<endl;
cout<<pg.Teacher::GetTN()<<endl;
cout<<pg.GetName()<<endl;
cout<<pg.GetAge()<<endl;
cout<<pg.Student::GetGRADE()<<endl;
cout<<pg.Student::GetSF()<<endl;
cout<<pg.Teacher::GetML()<<endl;
cout<<pg.Teacher::GetPT()<<endl;
}
编译后:
--------------------Configuration: PostGraduateObject - Win32 Debug--------------------
Compiling...
PostGraduateClass.cpp
F:\vc++\vc++程序\MyObject\PostGraduateObject\PostGraduateClass.cpp(74) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
执行 cl.exe 时出错.
PostGraduateClass.obj - 1 error(s), 0 warning(s)