File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,3 +10,4 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1010add_executable (date_time "date_time.cpp" )
1111add_executable (coloured_circle "coloured_circle.cpp" )
1212add_executable (modern_coloured_circle "modern_coloured_circle.cpp" )
13+ add_executable (house_boat "house_boat.cpp" )
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+
3+ class house_t {
4+ protected:
5+ int residents{0 };
6+
7+ public:
8+ house_t () = default ;
9+
10+ explicit house_t (int num)
11+ : residents(num) {}
12+
13+ void set_residents (int num) noexcept { residents = num; }
14+
15+ [[nodiscard]]
16+ int get_residents () const noexcept {
17+ return residents;
18+ }
19+ };
20+
21+ class boat_t {
22+ protected:
23+ float max_speed{0 .0f };
24+
25+ public:
26+ boat_t () = default ;
27+
28+ explicit boat_t (float speed)
29+ : max_speed(speed) {}
30+
31+ void set_max_speed (float speed) noexcept { max_speed = speed; }
32+
33+ [[nodiscard]]
34+ float get_max_speed () const noexcept {
35+ return max_speed;
36+ }
37+ };
38+
39+ class house_boat_t : public house_t , public boat_t {
40+ public:
41+ house_boat_t () = default ;
42+
43+ house_boat_t (int residents, float speed)
44+ : house_t (residents)
45+ , boat_t (speed) {}
46+ };
47+
48+ int main () {
49+ house_boat_t hb;
50+ hb.set_residents (4 );
51+ hb.set_max_speed (10 .0f );
52+
53+ std::cout << " This dwelling has " << hb.get_residents () << " residents and a max speed of " << hb.get_max_speed ()
54+ << std::endl;
55+
56+ return 0 ;
57+ }
You can’t perform that action at this time.
0 commit comments