给大家我写的,大一的请进!!//C++第二版__十一章习题 1
//C++第二版__十一章习题 1#include<iostream>
#include<cstring>
using namespace std;
class Person
{
char Name[10];
char Sex;
int Age;
public:
void Register1(char *name,int age, char sex)
{
strcpy(Name,name);
Age=age;
Sex=(sex=='m'?'m':'f');
}
void ShowMe()
{
cout<<"姓名:"<<Name<<endl;
cout<<"性别:"<<(Sex=='m'?"男":"女")<<endl;
cout<<"年龄:"<<Age<<endl;
}
};
class Teacher:public Person //继承PERSON类
{
char Profession[10];
char Title[10];
char Course[10];
public:
void Register(char *name,int age,char sex,char *profession,char *title,char *course)
{
Person::Register1(name,age,sex);
strcpy(Profession,profession);
strcpy(Title,title);
strcpy(Course,course);
}
void ShowMe()
{
Person::ShowMe();
cout<<"专业:"<<Profession<<endl;
cout<<"职称:"<<Title<<endl;
cout<<"主讲课程:"<<Course<<endl;
}
};
int main() //测试
{
Teacher teacher;
teacher.Register("李木子",28,'女',"软件工程","教师","C++");
teacher.ShowMe();
return 0;
}