以下是C++实现代码:
```cpp
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Person {
protected:
string lastName;
string firstName;
string gender;
int age;
string occupation;
public:
Person(string lName, string fName, string gen, int a, string occ)
: lastName(lName), firstName(fName), gender(gen), age(a), occupation(occ) {}
void display() {
cout << "Last Name: " << lastName << endl;
cout << "First Name: " << firstName << endl;
cout << "Gender: " << gender << endl;
cout << "Age: " << age << endl;
cout << "Occupation: " << occupation << endl;
}
};
class Family : public Person {
private:
Person husband;
Person wife;
vector<Person> children;
public:
Family(string hLastName, string hFirstName, string hGen, int hAge, string hOcc,
string wLastName, string wFirstName, string wGen, int wAge, string wOcc,
vector<Person> c)
: Person(hLastName, hFirstName, hGen, hAge, hOcc), husband(hLastName, hFirstName, hGen, hAge, hOcc),
wife(wLastName, wFirstName, wGen, wAge, wOcc), children(c) {}
void displayHusband() {
husband.display();
}
void displayWife() {
wife.display();
}
void displayChildren() {
for (Person child : children) {
child.display();
}
}
};
int main() {
Person father("Smith", "John", "Male", 40, "Engineer");
Person mother("Johnson", "Mary", "Female", 35, "Teacher");
vector<Person> children = {Person("Smith", "Tom", "Male", 10, ""), Person("Smith", "Kate", "Female", 8, "")};
Family family("Smith", "John", "Male", 40, "Engineer", "Johnson", "Mary", "Female", 35, "Teacher", children);
cout << "Husband: " << endl;
family.displayHusband();
cout << "Wife: " << endl;
family.displayWife();
cout << "Children: " << endl;
family.displayChildren();
return 0;
}
```
运行结果:
```
Husband:
Last Name: Smith
First Name: John
Gender: Male
Age: 40
Occupation: Engineer
Wife:
Last Name: Johnson
First Name: Mary
Gender: Female
Age: 35
Occupation: Teacher
Children:
Last Name: Smith
First Name: Tom
Gender: Male
Age: 10
Occupation:
Last Name: Smith
First Name: Kate
Gender: Female
Age: 8
Occupation:
```