求教高人!!!一个c++关于继承的问题望帮助~
刚学C++不久,遇到问题不知如何修改,源代码如下,望高手赐教#include"stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class person{
protected:
char *name;
int id;
public:
person(char *n,int i){
name=new char[strlen(n)+1];
strcpy(name,n);
id=i;
}
void display(){
cout<<"人名:"<<name<<"身份证:"<<id<<endl;
}
~person(){ delete name;}
};
class teacher:virtual public person{
public:
teacher(char *n,int i,char *d1,char *d2):person(n,i){
degree=new char[strlen(d1)+1];
strcpy(degree,d1);
dep=new char[strlen(d2)+1];
strcpy(dep,d2);
}
void display(){
person::display();
cout<<endl;
cout<<"学历:"<<degree<<"部门:"<<dep<<endl;
}
protected:
char *degree;
char *dep;
};
class student:virtual public person{
public:
student(char *n,int i,int age,int s):person(n,i){
old=age;
sno=s;
}
void display(){
person::display();
cout<<endl;
cout<<"年龄:"<<old<<"学号:"<<sno<<endl;
}
protected:
int old;
int sno;
};
class stud{
protected:
char *addr;
char *tel;
public:
stud(char *a,char *t){
addr=new char[strlen(a)+1];
strcpy(addr,a);
tel=new char[strlen(t)+1];
strcpy(tel,t);
}
void display(){
cout<<"住址:"<<addr<<"电话:"<<tel<<endl;
}
};
class score:public stud,public student{
public:
score(float m,float e):stud(),student(){
math=m;
eng=e;
}
void display(){
cout<<"数学:"<<math<<"英语:"<<eng<<endl;
}
protected:
float math;
float eng;
}
int main(){
teacher t1("笑",1218,"本科","财大");
score c1(78.5,80.0);
t1.display();
c1.display();
}