@@ -8,53 +8,89 @@ class House
8
8
House ()=default ;
9
9
House (int const sqftP, const Vector2D& vec)
10
10
:sqft(sqftP), coord(vec){};
11
- virtual ~House ()=default ;
11
+ ~House ()=default ;
12
12
void printHouse ()const
13
13
{
14
14
std::cout<<" Sqft: " << sqft << " \n " << " Coordinates: " << coord.x << " " << coord.y << std::endl;
15
15
}
16
-
16
+ public:
17
17
int sqft{};
18
18
Vector2D coord;
19
19
};
20
20
class Family : public House
21
21
{
22
22
public:
23
- Family ()= default ;
23
+ Family ():members( 0 ),head( " unkown head " ), wealth_status( " unkown " ){} ;
24
24
Family (int const membersP, std::string headP): members(membersP), head(std::move(headP)){};
25
- Family (int const membersP, std::string headP, const House& house )
26
- :members(membersP), head(std::move(headP))
25
+ Family ( const House& houseP, int const membersP, std::string headP)
26
+ :House(houseP), members(membersP), head(std::move(headP))
27
27
{
28
- if (house .sqft < 1000 )
28
+ if (houseP .sqft < 1000 )
29
29
{
30
30
wealth_status = " poor" ;
31
31
}else
32
32
{
33
33
wealth_status = " wealthy" ;
34
34
}
35
35
};
36
+
36
37
void printFamilyInfo () const
37
38
{
38
39
std::cout << " Head Of House: " << head << " \n Total Members: " << members << std::endl;
39
40
House::printHouse ();
40
41
std::cout << " Status: " << wealth_status << std::endl;
41
42
}
42
43
43
- protected :
44
+ public :
44
45
int members{};
45
46
std::string head{};
46
47
std::string wealth_status{};
47
48
};
48
49
50
+ class ExtendedFamily final : public Family{
51
+ public:
52
+ ExtendedFamily ()
53
+ :grandpa(" unkown" ), grandma(" unknown" ){};
54
+
55
+ ExtendedFamily (std::string grandpaP, std::string grandmaP)
56
+ :grandpa(std::move(grandpaP)), grandma(std::move(grandmaP)){};
57
+
58
+ ExtendedFamily (const Family& familyP, std::string grandpaP, std::string grandmaP)
59
+ :Family(familyP), grandpa(std::move(grandpaP)), grandma(std::move(grandmaP)){};
60
+
61
+
62
+ void wholeFamily ()const
63
+ {
64
+ std::cout << " Grandparents: " << grandpa << " " << grandma << " \n Son of grandparents: " << head << std::endl;
65
+ }
66
+
67
+ public:
68
+ std::string grandpa{};
69
+ std::string grandma{};
70
+ };
71
+ void getFamilyInfo (string& headP, string& grandFatherP, string& grandmotherP, int & familyCount)
72
+ {
73
+ std::cout << " Enter Head of house and Total count of family members : " ;
74
+ std::getline (std::cin, headP);
75
+ std::cin >>familyCount;
76
+ std:: cout << " Enter the head of households parents starting with Dad and then Mom" << std::endl;
77
+ std::cin.ignore ();
78
+ std::getline (std::cin, grandFatherP);
79
+ std::getline (std::cin, grandmotherP);
80
+ }
49
81
int main () {
50
82
std::string headOfHouse{};
83
+ std::string grandFather{};
84
+ std::string grandmother{};
51
85
int familyCount{};
52
- std::cout << " Enter Head of house and Total count of family members : " ;
53
- std::cin >> headOfHouse >> familyCount;
86
+ getFamilyInfo (headOfHouse, grandFather, grandmother, familyCount);
54
87
const Vector2D coordinates{1700 , 1500 };
55
88
House const house{1001 ,coordinates};
56
- Family const family{familyCount, headOfHouse, house };
57
-
89
+ Family const family{house, familyCount, headOfHouse };
90
+ ExtendedFamily const extendedFamily{family, grandFather, grandmother};
58
91
family.printFamilyInfo ();
92
+ extendedFamily.wholeFamily ();
93
+ extendedFamily.printFamilyInfo ();
94
+
59
95
60
96
}
0 commit comments