大学管理系统,编译通过,但是不知哪里出现问题,高手来调试下
#include<iostream.h>#include<string.h>
//
// 一个简单的大学管理系统,其中有学生和职工,职工中有教师。
// 类 data_rec 是虚基类,它包含了所有派生类共有的数据成员,
// 职工类 Employee 和学生类 Student 为虚基类 Data_roc 的派
// 生类,教师类 Teacher为职工 Employee 的派生类,在职大学生
// E_student 是职工类 Employee 和学生类 Student 的共同派生
// 类。
//
//
const char null='\0'; // 定义null为常数据成语空字符
static char *strsave(char *s) // 给一个指针赋值
{
char *p;
p=new char[strlen(s)+1];
strcpy(p,s);
return p;
}
class Data_rec { // 定义一个虚基类Data_rec,包括姓名和id编号
protected:
char *name;
char *id_number;
public:
Data_rec() // 用析构函数初始化
{
name=null;
id_number=null;
}
Data_rec(char *name1,char *id_number1) // 用析构函数进行取数
{
name=strsave(name1);
id_number=strsave(id_number1);
}
~Data_rec()
{
delete []name;
delete []id_number;
}
void print() // 输出名子和id号
{
cout<<"\n"<<"name: "<<name<<endl;
cout<<"\n"<<"id_number: "<<id_number<<endl;
}
};
//
// 虚基类的派生类 Student
class Student: virtual public Data_rec {
protected:
char *major; // 主要学科
long int stu_no; // 学生学号
int level; // 年纪
public:
Student(char *name1,char *id_number1,char *major1,long int
stu_no1,int level1): Data_rec(name1,id_number1)
{
major=strsave(major1);
stu_no=stu_no1;
level=level1;
}
~Student()
{ delete []major; }
void print(); // 输出学生姓名,id号,科目,学号,年纪
};
// 定义输出学生的函数print()
void Student::print()
{
Data_rec::print();
cout<<"Major: "<<major<<endl;
cout<<"stu_no: "<<stu_no<<endl;
cout<<"level: "<<level<<endl;
}
// 虚基类派生类 Employee,部门,薪水
class Employee: virtual public Data_rec {
protected:
char *dept;
double salary;
public:
Employee(char *name1,char *id_number1,char *dept1,double salary1)
: Data_rec(name1,id_number1)
{
dept=strsave(dept1);
salary=salary1;
}
~Employee()
{ delete []dept; }
void print(); // 输出职工的数据
};
// 定义职工输出函数
void Employee::print()
{
Data_rec::print();
cout<<"Department: "<<dept<<endl;
cout<<"salary: "<<salary<<endl;
}
// Employee 类派生类 Teacher,有职位
class Teacher: virtual public Employee {
protected:
char *title;
public:
Teacher(char *name1,char *id_number1, char *dept1,double salary1,
char *title1): Data_rec(name1,id_number1),Employee(name1,id_number1,dept1,salary1)
{ title=strsave(title1); }
~Teacher()
{ delete []title; }
void print(); // 输出老师的数据
};
// 定义输出老师的函数
void Teacher::print()
{
Employee::print();
cout<<"title: "<<title<<endl;
}
// 多继承派生类 _Student 继承两个基类 Employee 和 Student
class E_Student: public Employee,public Student {
public:
E_Student(char *name1,char *id_number1,char *major1,long int stu_no1,int level1,
char *dept1,double salary1): Data_rec(name1,id_number),Employee(name1,id_number1,
dept1,salary1),Student(name1,id_number1,major1,stu_no1,level1) { }
void print(); // 输出在职学生的数据
};
// 定义输出在职学生的函数
void E_Student::print()
{
Student::print();
cout<<"Department: "<<dept<<endl;
cout<<"salary: "<<salary<<endl;
}
//
// 创建对象
int main()
{
Student my_student("zhangming","0101234567891","Computer_science",1234,4);
Employee my_employee("chandaiwei","01043453543","Electrical",7.20);
Teacher my_teacher("lixiaoping","010234445412","computer",12.34,"professor");
E_Student my_e_student("zhangming","0101234567","Computer",203478,3,"Electtical",7.20);
cout<<"\n";
//my_student.print();
//cout<<"\n";
//my_employee.print();
//cout<<"\n";
my_teacher.print();
cout<<"\n\n";
my_e_student.print();
return 0;
}