个人专栏:
算法设计与分析:算法设计与分析_IT闫的博客-CSDN博客
Java基础:Java基础_IT闫的博客-CSDN博客
c语言:c语言_IT闫的博客-CSDN博客
MySQL:数据结构_IT闫的博客-CSDN博客
数据结构:数据结构_IT闫的博客-CSDN博客
C++:C++_IT闫的博客-CSDN博客
C51单片机:C51单片机(STC89C516)_IT闫的博客-CSDN博客
基于HTML5的网页设计及应用:基于HTML5的网页设计及应用_IT闫的博客-CSDN博客
python:python_IT闫的博客-CSDN博客
欢迎收看,希望对大家有用!
目录
第一题:
第二题:
第三题:
答案:
第一题:
第二题:
第三题:
编写一个学生类,学生数据有编号、姓名、年龄、专业和成绩,要求将编号、姓名、年龄数据设计成一个人类Person,并作为学生类Student的基类。创建Student类对象,并使用显示show()函数对数据进行输出。
设计职员类employee,它继承Person类并包含子对象Date类对象。要求将编号、姓名、性别设计成类Person,Date类包含年、月、日;职员类另有部门及职务成员数据。主程序创建职员类对象并输出信息。
已有类Time和Date,要求设计一个派生类Birth,它继承类Time和类Date,并且增加一个数据成员childname用于表示小孩的名字,设计show函数显示信息;主程序创建Birth类对象并调用show()函数显示信息。
#include
using namespace std;
class Person {
private:
string _id;
string _name;
int _age;
public:
Person(string id,string name,int age);
void show();
};
Person::Person(string id,string name,int age) {
_id=id;
_name=name;
_age=age;
}
void Person::show() {
cout<<"编号:"<<_id<
#include
using namespace std;
class Person {
private:
string _id;
string _name;
string _sex;
public:
Person(string id,string name,string sex);
void show();
};
Person::Person(string id,string name,string sex) {
_id=id;
_name=name;
_sex=sex;
}
void Person::show() {
cout<<"编号:"<<_id<
#include
using namespace std;
class Time {
public:
Time(int h,int min,int s) {
hours=h;
minutes=min;
seconds=s;
}
void display() {
cout<<"出生时间:"<