程序要求输出学生、老师、研究生的档案//档案管理.cpp#include<iostream.h>#include<string.h>class Person{char *name;char sex;int age;public:Person(char *na,char sx,int ag){age=ag;sex=sx;name=new char[strlen(na)+1];strcpy(name,na);}void print()const{cout<<" "<<name<<":";cout<<age<<":";cout<<sex<<endl;}~Person(){delete[]name;}};class Student:public Person{int number;char department[50];public:Student(char*na,char sx,int ag,int num,char*dep){ number=num;strcpy(department,dep);}void print()const{Person::print();cout<<" number:"<<number<<endl;cout<<" department:"<<department<<endl;}};class Teacher:public Person{char post[20],course[30];public:Teacher(char*na,char sx,int ag,char*po,char*co):person(na,sx,ag){strcpy(post,po);strcpy(course,co);}void print()const{Person::print();cout<<" post:"<<post<<endl; cout<<" course:"<<course<<endl;}};class Graduatestudent:public Student{char advisor[30];public:Graduatestudent(char*na,char sx,int ag,int num,char*dep,char*ad):student(na,sx,ag,num,dep){strcpy(advisor,ad);}void print()const{Student::print();cout<<" advisor:"<<advisor<<endl;}};void main(){Person per1("zhang",'F',23),per2("chen",'M',37);Student stu1("li",'M',22,1001,"comp"),stu2("cui",'F',21,1002,"math");Teacher teach1("meng",'M',46,"professor","english");Graduatestudent grastu("zhou",'M',25,1011,"comp","liu");cout<<"===per1.print()==>name,age,sex"<<endl;per1.print();cout<<"===per2.print()==>name,age,sex"<<endl;per2.print();cout<<"===stu1.print()==>name,age,sex,number,department,advisor"<<endl;grastu.Graduatestudent::print();}这个程序运行时总是说Student(char*na,char sx,int ag,int num,char*dep)这一行error C2512: 'Person' : no appropriate default constructor available。
查看完整描述