用C++编写程序
功能:声明一个共同的基类Person,它包含了所有派生类共有的数据,职工类Employee和大学生类Student为虚基类Person的派生类,在职大学生类E_stude...
功能:声明一个共同的基类Person,它包含了所有派生类共有的数据,职工类Employee和大学生类Student为虚基类Person的派生类,在职大学生类E_student是职工类Employee的派生类。每类人员具有的数据如下:
职工类:姓名、性别、年龄、部门
大学生类:姓名、性别、年龄、专业
在职大学生类:姓名、性别、年龄、部门、导师
要求:
1.用继承和虚基类来实现;
2. 请严格按照下面的格式进行输入输出。输入输出格式:
Please input a student information:
Name Age Sex Major
aa 21 m 计算机
Please input a employee information:
Name Age Sex Department
bb 45 f 工学院
Please input a working student:
Name Age Sex Department Tutor
cc 36 m 工学院 dd
*********Student Information**************
Name Age Sex Major
aa m 21 计算机
*********************************
***********Employee Information**************
Name Age Sex Department
bb f 45 工学院
*********************************
**********Working Student Information*********
Name Age Sex Department Tutor
cc m 36 工学院 dd
********************************* 展开
职工类:姓名、性别、年龄、部门
大学生类:姓名、性别、年龄、专业
在职大学生类:姓名、性别、年龄、部门、导师
要求:
1.用继承和虚基类来实现;
2. 请严格按照下面的格式进行输入输出。输入输出格式:
Please input a student information:
Name Age Sex Major
aa 21 m 计算机
Please input a employee information:
Name Age Sex Department
bb 45 f 工学院
Please input a working student:
Name Age Sex Department Tutor
cc 36 m 工学院 dd
*********Student Information**************
Name Age Sex Major
aa m 21 计算机
*********************************
***********Employee Information**************
Name Age Sex Department
bb f 45 工学院
*********************************
**********Working Student Information*********
Name Age Sex Department Tutor
cc m 36 工学院 dd
********************************* 展开
2个回答
展开全部
#include "iostream"#include "cstring"using namespace std;class Pen{public: Pen(double price=0,char *name=NULL,char *color=NULL); ~Pen();private: double price; char name[20]; char color[20];};Pen::Pen(double price,char *name,char *color){ this->price=price; if(name!=NULL) strncpy(this->name,name,strlen(name)); if(color!=NULL) strncpy(this->color,color,strlen(color)); cout<<"Constructor:"<<endl; cout<<"price:"<<price<<endl; if(name!=NULL) cout<<"name:"<<name<<endl; if(color!=NULL) cout<<"color:"<<color<<endl;}Pen::~Pen(){ cout<<"Dis-constructor"<<endl;}int main(){ Pen one,two(20),three(10,NULL,"red"),four(12,"heoo","black");
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
#include <string>
using namespace std;
class Persion
{
public:
virtual void input() = 0;
virtual void output() = 0;
public:
stringname;
intage;
charsex;
};
class Employee : public Persion
{
public:
void input()
{
cout<<"Please input a employee information:\nName Age Sex Department"<<endl;
cin>>name>>age>>sex>>department;
};
void output()
{
cout<<"***********Employee Information**************\nName Age Sex Department"<<endl;
cout<<name<<" "<<age<<" "<<sex<<" "<<department<<endl;
cout<<"*********************************"<<endl;
};
public:
string department;
};
class Student : public Persion
{
public:
void input()
{
cout<<"Please input a student information:\nName Age Sex Major"<<endl;
cin>>name>>age>>sex>>major;
};
void output()
{
cout<<"***********Employee Information**************\nName Age Sex Major"<<endl;
cout<<name<<" "<<age<<" "<<sex<<" "<<major<<endl;
cout<<"*********************************"<<endl;
};
public:
string major;
};
class E_student : public Employee
{
public:
void input()
{
cout<<"Please input a working student information:\nName Age Sex Department Tutor"<<endl;
cin>>name>>age>>sex>>department>>tutor;
};
void output()
{
cout<<"*********Working Student Information**************\nName Age Sex Department Tutor"<<endl;
cout<<name<<" "<<age<<" "<<sex<<" "<<department<<" "<<tutor<<endl;
cout<<"*********************************"<<endl;
};
public:
string tutor;
};
int main(int argc, char ** argv)
{
Student t1;
t1.input();
Employee e1;
e1.input();
E_student et1;
et1.input();
t1.output();
e1.output();
et1.output();
system("pause");
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询