📄 stu_tea.cpp
字号:
#include<iostream>
using namespace std;
#include<string>
class teacher;
class student
{
private:
string name;
int no;
int E_mark;
int M_mark;
teacher* te;
public :
student(string na=" ",int n=0,int e=0,int m=0,teacher* t=NULL);
~student();
void set_info();
virtual void display_self();
void display_teacher();
student& operator=(student& stu);
};
class software_student: public student
{
private:
int S_mark;
int P_mark;
string Design;
public:
software_student(int s=0,int p=0,string des="none",string na=" ",int n=0,int e=0,int m=0,teacher* t=NULL);
~software_student();
void set_info();
void display_self();
void display_teacher();
};
class elec_student :public student
{
private:
int elec_mark;
int d_mark;
string Design;
public:
elec_student(int elec=0,int d=0,string des="none",string na=" ",int n=0,int e=0,int m=0,teacher* t=NULL);
~elec_student();
void set_info();
void display_self();
void display_teacher();
};
class teacher{
private:
string name;
string duty;
student stu[2];
public:
teacher(string na=" ",string du=" ");
teacher(string na,string du,student& s1,student& s2);
~teacher();
void display_self();
void set_info();
void set_teinfo();
void display_stu();
teacher& operator=(teacher& te);
};
teacher& teacher::operator=(teacher& te){
if(this==&te)
return *this;
name=te.name ;
duty=te.duty ;
stu[0]=te.stu [0];
stu[1]=te.stu [1];
return *this;
}
teacher::teacher(string na,string du){
name=na;
duty=du;
}
teacher::teacher(string na,string du,student& s1,student& s2){
name=na;
duty=du;
stu[0]=s1;
stu[1]=s2;
}
teacher::~teacher(){
}
void teacher::display_self(){
cout<<"\n姓名:"<<name<<"\n"<<"职称:"<<duty<<endl;
}
void teacher::set_teinfo(){
cout<<"姓名:";
cin>>name;
cout<<"职称:";
cin>>duty;
char ch;
cout<<"指导学生信息(无指导学生输入0,否则输入任一数字):\n";
cin>>ch;
if(ch!='0')
{
stu[1].set_info ();
stu[2].set_info ();
}
}
void teacher::set_info(){
cout<<"姓名:";
cin>>name;
cout<<"职称:";
cin>>duty;
// stu[1].set_info ();
// stu[2].set_info ();
}
void teacher::display_stu(){
// cout<<"姓名:"<<name<<"\n"<<"职称:"<<duty<<endl;
cout<<"\n毕业设计学生1:"<<endl;
stu[0].display_self ();
cout<<"\n毕业设计学生2:"<<endl;
stu[1].display_self ();
}
student::student(string na,int n,int e,int m,teacher* t){
name=na;
no=n;
E_mark=e;
M_mark=m;
te=t;
}
student& student::operator=(student& stu){
if(this==&stu)
return *this;
name=stu.name ;
no=stu.no;
E_mark=stu.E_mark ;
M_mark=stu.M_mark ;
te=stu.te ;
return *this;
}
student::~student(){
}
void student::display_self(){
cout<<"\n姓名:"<<name<<"\n"<<"学号:"<<no<<endl;
cout<<"英语:"<<E_mark<<endl;
cout<<"高数:"<<M_mark<<endl;
cout<<"指导教师:"<<endl;
if(te!=NULL)
(*te).display_self ();
else
cout<<"没有制定指导教师\n";
}
void student::set_info(){
cout<<"姓名:";
cin>>name;
cout<<"学号:";
cin>>no;
cout<<"英语成绩:";
cin>>E_mark;
cout<<"高数成绩:";
cin>>M_mark;
char ch;
cout<<"指导教师信息(无指导教师输入0,否则输入任一数字):"<<endl;
cin>>ch;
if(ch!='0'){
if(te==NULL)
te=new teacher();
(*te).set_info ();
}
}
void student::display_teacher(){
if(te!=NULL)
(*te).display_self ();
else
cout<<"没有制定指导教师\n";
}
software_student::software_student(int s,int p,string des,string na,int n,int e,int m,teacher* t)
:student(na,n,e,m,t){
S_mark=s;
P_mark=p;
Design=des;
}
software_student::~software_student(){}
void software_student::set_info(){
student::set_info ();
cout<<"软件工程成绩:";
cin>>S_mark;
cout<<"数据结构成绩:";
cin>>P_mark;
cout<<"毕业设计题目:";
cin>>Design;
}
void software_student::display_self(){
student::display_self ();
cout<<"软件工程成绩:"<<S_mark<<endl;
cout<<"数据结构成绩:"<<P_mark<<endl;
cout<<"毕业设计题目:"<<Design<<endl;
}
void software_student::display_teacher(){
student::display_teacher ();
}
elec_student::elec_student(int elec,int d,string des,string na,int n,int e,int m,teacher* t)
:student(na,n,e,m,t){
elec_mark=elec;
d_mark=d;
Design=des;
}
elec_student::~elec_student(){
}
void elec_student::set_info(){
student::set_info ();
cout<<"电路原理成绩:";
cin>>elec_mark;
cout<<"数字电路成绩:";
cin>>d_mark;
cout<<"毕业设计题目:";
cin>>Design;
}
void elec_student::display_self(){
student::display_self ();
cout<<"电路原理成绩:"<<elec_mark<<endl;
cout<<"数字电路成绩:"<<d_mark<<endl;
cout<<"毕业设计题目:"<<Design<<endl;
}
void elec_student::display_teacher(){
student::display_teacher ();
}
int main()
{
teacher t1("任远方","教授"),t2("王雨","副教授");
software_student s1(98,86,"约瑟夫环","张力",1,86,90,&t2);
software_student s2(94,96,"平衡二叉树","陈志勇",2,89,98,&t1);
elec_student e3(84,86,"电路设计","李红",3,79,78,&t1);
elec_student e4(85,82,"电路设计","李红",4,89,88,&t2);
teacher te1("任远方","教授",e3,s2);
teacher te2("王雨","副教授",s1,e4);
/* s1.display_self ();
s1.display_teacher ();
te1.display_self ();
te1.display_stu ();
*/
int c1;
cout<<"选择查询信息:\n";
cout<<"0.退出查询\n";
cout<<"1.教师信息\t"<<"2.学生信息\n选择:";
cin>>c1;
while(c1!=0){
switch(c1){
case 2:{
int c2;
cout<<"选择学号(1~4):\n选择学号:";
cin>>c2;
switch(c2){
case 1:{
cout<<"\n学生个人信息:\n";
cout<<"---------------------";
s1.display_self();
cout<<"\n指导教师信息:\n";
cout<<"---------------------";
s1.display_teacher ();
break;
}
case 2:{
cout<<"\n学生个人信息:\n";
cout<<"---------------------";
s2.display_self();
cout<<"\n指导教师信息:\n";
cout<<"---------------------";
s2.display_teacher ();
break;
}
case 3:{
cout<<"\n学生个人信息:\n";
cout<<"---------------------";
e3.display_self();
cout<<"\n指导教师信息:\n";
cout<<"---------------------";
e3.display_teacher ();
break;
}
case 4:{
cout<<"\n学生个人信息:\n";
cout<<"---------------------";
e4.display_self();
cout<<"\n指导教师信息:\n";
cout<<"---------------------";
e4.display_teacher ();
break;
}
default:{
cout<<"输入有误\n";
}
}
break;
}
case 1:{
int c2;
cout<<"选择教师(1~2):\n教师:";
cin>>c2;
switch(c2){
case 1:{
cout<<"\n教师个人信息:\n";
cout<<"---------------------";
te1.display_self ();
cout<<"\n毕业设计学生信息:\n";
cout<<"---------------------";
te1.display_stu ();
break;
}
case 2:{
cout<<"\n教师个人信息:\n";
cout<<"---------------------";
te2.display_self ();
cout<<"\n毕业设计学生信息:\n";
cout<<"---------------------";
te2.display_stu ();
break;
}
default:{
cout<<"输入有误\n";
}
}
break;
}
}
cout<<"*****************************\n";
cout<<"选择查询信息:\n";
cout<<"0.退出查询\n";
cout<<"1.教师信息\t"<<"2.学生信息\n选择:";
cin>>c1;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -