#include<iostream>
using namespace std;
class Person
{
private:
const char *name;
int age;
const char *sex;
public:
Person(const char *name,int age,const char *sex)
{
this->name=name;
this->age=age;
this->sex=sex;
cout<<"构造函数:"<<name<<"\n";
}
~Person()
{
cout<<"析构函数:"<<name<<"\n";
}
void display()
{
cout<<"姓名:"<<name<<"\n";
cout<<"年龄:"<<age<<"\n";
cout<<"性别:"<<sex<<"\n";
}
};
class Student:public Person
{
private:
const char *Snumber;
double score;
public:
Student(const char *name,int age,const char *sex,const char *Snumber,double score):Person(name,age,sex)
{
this->Snumber=Snumber;
this->score=score;
cout<<"构造函数:"<<Snumber<<"\n";
}
~Student()
{
cout<<"析构函数:"<<Snumber<<"\n";
}
void display()
{
Person::display();
cout<<"学号:"<<Snumber<<"\n";
cout<<"成绩:"<<score<<"\n";
}
};
class Teacher:public Person
{
private:
const char *Tnumber;
double Tage;
public:
Teacher(const char *name,int age,const char *sex,const char *Tnumber,double Tage):Person(name,age,sex)
{
this->Tnumber=Tnumber;
this->Tage=Tage;
cout<<"构造函数:"<<Tnumber<<"\n";
}
~Teacher()
{
cout<<"析构函数:"<<Tnumber<<"\n";
}
void display()
{
Person::display();
cout<<"工号:"<<Tnumber<<"\n";
cout<<"教龄:"<<Tage<<"\n";
}
};
void main()
{
Teacher t1("Lina",26,"女","18120001",3);
Student s1("Xiaoming",18,"男","10180100",98);
t1.display();
s1.display();
system ("pause");
}
Last modification:December 9th, 2018 at 06:04 pm
© 允许规范转载