作业1
创建类
1.Eployee类,继承与Person类
c++
#include <iostream>
using namespace std;
class Person
{
private:
string firstName;
string middleName;
string lastName;
int age;
public:
Person();
Person(string str1,string str2,string str3,int i){
this->firstName = str1;
this->middleName = str2;
this->lastName = str3;
this->age = i;
}
~Person();
string getFirstName(){
return firstName;
}
void setFirstName(string str){
this->firstName = str;
}
string getMiddleName(){
return middleName;
}
void setMiddleName(string str){
this->middleName=str;
}
string getLastName(){
return lastName;
}
void setLastName(string str){
this->lastName=str;
}
int getAge(){
return age;
}
void setAge(int i){
this->age=i;
}
};
class Employee:public Person
{
private:
int hireYear;
public:
Employee();
Employee(int i){
this->hireYear=i;
}
~Employee();
int getHireYear(){
return hireYear;
}
void setHireYear(int i){
this->hireYear=i;
}
};
int main(){
Person *p = new Person();
p->setFirstName("hong");
p->setAge(24);
p->setMiddleName("hao");
p->setLastName("ran");
int i = p->getAge();
string str2 = p->getLastName();
string str3=p->getMiddleName();
string str = p->getFirstName();
cout<<str<<str2<<str3<<i<<endl;
}