主题:简单的院校人员管理系统有问题
[b]这个小程序编译链接没有问题,但运行最后一个类“在职进修教师”时结果有问题,求助[/b]//编写一个用于院校人事管理的程序,要求能够输入、显示各类人员的信息。
//假设院校有四类人员:学生,教师,员工和在职进修教师,他们都有姓名,性别、电话等共同信息
//学生具有年级、专业课程和各科成绩的信息,员工具有所在部门、工资的信息
//教师具有所在部门、工资和所授课程的信息,在职进修教师兼有教师和学生两类信息
#include<iostream>
#include<string>
using namespace std;
class College_person{
protected:
string name;
string sex;
int phone; //其实电话号码应该用string类型,不应该用int型,C对数值越界不报错
string duty;
public:
College_person(string tempduty="学生"):duty(tempduty)
{
cout<<duty<<endl;
cout<<"姓名:";
cin>>name;
cout<<"性别:";
cin>>sex;
cout<<"电话:";
cin>>phone;
}
void display()
{
cout<<"职务:"<<duty<<" 姓名:"<<name<<" 性别:"<<sex<<" 电话:"<<phone<<endl;
}
};
class Student:public College_person{
protected:
int grade;
string study_class[3];
int score[3];
int i;
public:
Student():College_person("学生") //像这种派生类没有参数基类有参数的是默认构造函数还是自定义的构造函数
{
cout<<"年级:";
cin>>grade;
cout<<"专业课程:";
for(i=0;i<3;i++)
cin>>study_class[i];
cout<<"各科成绩:";
for(i=0;i<3;i++)
cin>>score[i];
}
void show()
{
College_person::display();
cout<<"年级:"<<grade<<" 专业课程:";
for(i=0;i<3;i++)
cout<<study_class[i]<<" ";
cout<<" 各科成绩: ";
for(i=0;i<3;i++)
cout<<score[i]<<" ";
cout<<endl;
}
};
class Workers:virtual public College_person{
protected:
string department;
float salary;
public:
Workers():College_person("员工")
{
cout<<"部门:";
cin>>department;
cout<<"工资:";
cin>>salary;
}
void show()
{
College_person::display();
cout<<"部门:"<<department<<" 工资:"<<salary;
cout<<endl;
}
};
class Teachers:public Workers{
protected:
int i;
string teach_class[3];
public:
Teachers():Workers(),College_person("教师")
{
cout<<"所授课程:";
for(i=0;i<3;i++)
cin>>teach_class[i];
}
void show()
{
Workers::show();
cout<<"所授课程:";
for(i=0;i<3;i++)
cout<<teach_class[i]<<" ";
cout<<endl;
}
};
class Advanced_teacher:public Student,public Teachers{ //这个多继承老是有问题,调用了间接基类的构造函数但是没有调用直接基类的构造函数和显示函数
public:
Advanced_teacher():Student(),Teachers(),College_person("在职进修教师")
{}
void show()
{
Student::show();
Teachers::show();
cout<<"输出完毕。";
}
};
void main()
{
Student a;
a.show();
Workers b;
b.show();
Teachers c;
c.show();
Advanced_teacher d;
d.show();
}
//假设院校有四类人员:学生,教师,员工和在职进修教师,他们都有姓名,性别、电话等共同信息
//学生具有年级、专业课程和各科成绩的信息,员工具有所在部门、工资的信息
//教师具有所在部门、工资和所授课程的信息,在职进修教师兼有教师和学生两类信息
#include<iostream>
#include<string>
using namespace std;
class College_person{
protected:
string name;
string sex;
int phone; //其实电话号码应该用string类型,不应该用int型,C对数值越界不报错
string duty;
public:
College_person(string tempduty="学生"):duty(tempduty)
{
cout<<duty<<endl;
cout<<"姓名:";
cin>>name;
cout<<"性别:";
cin>>sex;
cout<<"电话:";
cin>>phone;
}
void display()
{
cout<<"职务:"<<duty<<" 姓名:"<<name<<" 性别:"<<sex<<" 电话:"<<phone<<endl;
}
};
class Student:public College_person{
protected:
int grade;
string study_class[3];
int score[3];
int i;
public:
Student():College_person("学生") //像这种派生类没有参数基类有参数的是默认构造函数还是自定义的构造函数
{
cout<<"年级:";
cin>>grade;
cout<<"专业课程:";
for(i=0;i<3;i++)
cin>>study_class[i];
cout<<"各科成绩:";
for(i=0;i<3;i++)
cin>>score[i];
}
void show()
{
College_person::display();
cout<<"年级:"<<grade<<" 专业课程:";
for(i=0;i<3;i++)
cout<<study_class[i]<<" ";
cout<<" 各科成绩: ";
for(i=0;i<3;i++)
cout<<score[i]<<" ";
cout<<endl;
}
};
class Workers:virtual public College_person{
protected:
string department;
float salary;
public:
Workers():College_person("员工")
{
cout<<"部门:";
cin>>department;
cout<<"工资:";
cin>>salary;
}
void show()
{
College_person::display();
cout<<"部门:"<<department<<" 工资:"<<salary;
cout<<endl;
}
};
class Teachers:public Workers{
protected:
int i;
string teach_class[3];
public:
Teachers():Workers(),College_person("教师")
{
cout<<"所授课程:";
for(i=0;i<3;i++)
cin>>teach_class[i];
}
void show()
{
Workers::show();
cout<<"所授课程:";
for(i=0;i<3;i++)
cout<<teach_class[i]<<" ";
cout<<endl;
}
};
class Advanced_teacher:public Student,public Teachers{ //这个多继承老是有问题,调用了间接基类的构造函数但是没有调用直接基类的构造函数和显示函数
public:
Advanced_teacher():Student(),Teachers(),College_person("在职进修教师")
{}
void show()
{
Student::show();
Teachers::show();
cout<<"输出完毕。";
}
};
void main()
{
Student a;
a.show();
Workers b;
b.show();
Teachers c;
c.show();
Advanced_teacher d;
d.show();
}