东南复试(代码笔记)

编写Person类和Name类(内置对象的初始化以及使用)

class Name
{
private:
 string first;
 string middle;
 string last;
public:
 Name(string first_ls,string middle_ls,string last_ls)
 :first(first_ls),middle(middle_ls),last(last_ls){}
 void printName();
};

class Person
{
private:
 Name name;
 string nationality;
 string sex;
public:
 Person(string name_1,string name_2,string name_3,string nationality_ls,string sex_ls)
 :name(name_1,name_2,name_3),nationality(nationality_ls),sex(sex_ls){}
 void printName();
 void printNationality();
 void show();
};
void Person::printName()
{
 name.printName();
}
void Person::printNationality()
{
 cout<
int main()
{
 Name name1("陈","奕","迅");
 Person person1("陈","奕","迅","汉族","男");
 person1.printName();
 person1.printNationality();
 name1.printName();
 cout<<'\n';
 person1.show();
 return 0;
}

运行结果:

东南复试(代码笔记)_第1张图片

你可能感兴趣的:(东南复试(代码笔记))