sos,一道c++编程题
#include<iostream>using namespace std;
class Teacher{
private:
char *name;
int age;
char *title;
public:
Teacher(char *name=0,int age=0,char *title=0){
}
void get(){
name=new char[10];
title=new char[10];
cout<<"input name"<<endl;
cin>>name;
cout<<"input age"<<endl;
cin>>age;
cout<<"input title"<<endl;
cin>>title;
};
~Teacher(){delete[] name;delete[] title;}
void display(){
cout<<"the name is"<<name<<endl;
cout<<"the age is"<<age<<endl;
cout<<"the title is"<<title<<endl;
}
};
class Cadre{
public:
Cadre(char *name=0,int age=0,char *post=0){}
get(){
name=new char[10];
post=new char[10];
cout<<"input name"<<endl;
cin>>name;
cout<<"input age"<<endl;
cin>>age;
cout<<"input post"<<endl;
cin>>post;
}
~Cadre(){delete[] name;delete[] post;}
display(){
cout<<"the post is"<<post<<endl;
}
private:
char *name;
int age;
char *post;
};
class Teacher_Cadre:public Teacher,public Cadre{
private:
int wage;
public:
Teacher_Cadre(int wage=0){}
void show(){
Teacher::display();
}
getwage(){
cout<<"input wage"<<endl;
cin>>wage;
}
put(){
cout<<"the wage is"<<wage<<endl;
cout<<"the post is"<<endl;
Cadre::display();
}
};
main(){
Teacher_Cadre tc;
Teacher t1;
t1.get();
Cadre c1;
c1.get();
tc.getwage();
tc.show();
tc.put();
}
调试时可以输进去数字,但到输出时显示内存错误了