虚基类-在职读书的教师类

Problem Description

定义并描述一个人员类Person,它派生出学生类Student和教师类Teacher,学生类和教师类又共同派生出在职读书的教师类StuTech。人员类有姓名、性别、身份证号、出生年月等信息;学生类除继承来的以外有学号、成绩等信息;教师类有职称等信息。要求:将相应的类定义完整,并在main函数中定义StuTech的对象,输出对象的所有信息。

 Input

输入包括多组测试数据,每组数据包括:姓名,性别,身份证,出生年,月,学号,成绩,职称

 Output

每组测试数据输出多行

 Sample Input

Tom Man 350100198505020035 1985 5 2011010230 85 Lecturer

 Sample Output

The imformation of study-teacher is:
Name:Tom Sex:Man Identity card:350100198505020035 Birthday:1985.5
Num:2011010230 Score:85
profession:Lecturer

 Author

wj

 Source

14信管期末复习上机练习A

 Recommend

zh

**************************************************************************************************************************************************************

#include<iostream>

using namespace std;
class Person{
private:
char*pname;
char*sex;
char *id;
int year;
int month;
public:
Person( char*name,char*sex1,char *id1,int year,int month)
{
pname=new char[strlen(name)+1];
strcpy(pname,name);
sex=new char[strlen(sex1)+1];
strcpy(sex,sex1);
id=new char[strlen(id1)+1];
strcpy(id,id1);
this->year=year;
this->month=month;
}
void show()
{
cout<<"Name:"<<pname<<" "<<"Sex:"<<sex<<" "<<"Identity card:"<<id<<" "<<"Birthday:"<<year<<"."<<month<<endl;
}


~Person()
{}
};
class Student:public Person{
private:
char *num;
int score;
public:
Student(char*name,char*sex1,char *id1,int year,int month,char*n,int score):Person(name,sex1,id1,year,month)
{
num=new char[strlen(n)+1];
strcpy(num,n);
this->score=score;
}
void show()
{


Person::show();
cout<<"Num:"<<num<<" "<<"Score:"<<score<<endl;
}
~Student()
{}
};
class Teacher:public Person{
private:
char *pro;
public:
Teacher(char*name,char*sex1,char *id1,int year,int month,char*p):Person(name,sex1,id1,year,month)
{
pro=new char[strlen(p)+1];
strcpy(pro,p);
}
void show1()
{
cout<<"profession:"<<pro<<endl;
}
};
class StuTech:public Student,public Teacher{
public:
StuTech(char*name,char*sex1,char *id1,int year,int month,char*n,int score,char*p):Student(name,sex1,id1,year,month,n,score),Teacher(name,sex1,id1,year,month,p)
{
}
void show()
{
cout<<"The imformation of study-teacher is:"<<endl;
Student::show();
Teacher::show1();
}
};
int main()
{
char a[25];
char b[25];
char c[25];
int d,f;
char g[100];
int h;
char t[100];
while(cin>>a>>b>>c>>d>>f>>g>>h>>t)
{
StuTech f(a,b,c,d,f,g,h,t);
f.show();
}
return 0;

}





完整不是水的!!!!

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

饭九钦vlog

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值