-
Notifications
You must be signed in to change notification settings - Fork 0
/
Boat.cpp
172 lines (146 loc) · 3.54 KB
/
Boat.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "Boat.h"
#include "HelperFunctions.h"
Boat::Boat()
{
// assign default values to class properties
boat_name_ = owner_name_ = "";
length_ = depth_ = 0;
booking_duration_ = 0;
}
Boat::Boat(const bool ask_details)
{
if (ask_details)
{
bool invalid_length, invalid_depth;
Marina* marina = Marina::get_instance();
do
{
invalid_length = false;
cout << "\nPlease enter the length of the boat (max " << marina->get_max_boat_length() << "):\n> ";
const string boat_length = HelperFunctions::get_string_input();
if (HelperFunctions::check_if_string_is_float(boat_length))
{
length_ = HelperFunctions::convert_string_to_float(boat_length);
}
else
{
HelperFunctions::print_invalid_input_message();
invalid_length = true;
}
} while (invalid_length);
do
{
invalid_depth = false;
cout << "\nPlease enter the depth of the boat (max " << marina->get_max_boat_depth() << "):\n> ";
const string boat_depth = HelperFunctions::get_string_input();
if (HelperFunctions::check_if_string_is_float(boat_depth))
{
depth_ = HelperFunctions::convert_string_to_float(boat_depth);
}
else
{
HelperFunctions::print_invalid_input_message();
invalid_depth = true;
}
} while (invalid_depth);
// assign default value to not initialized property
booking_duration_ = 0;
}
else
{
// don't ask user for details (e.g. call default constructor)
Boat();
}
}
Boat::~Boat()
{
}
float Boat::get_length() const
{
return length_;
}
float Boat::get_depth() const
{
return depth_;
}
string Boat::get_boat_name() const
{
return boat_name_;
}
void Boat::set_boat_name(const string boat_name_input)
{
boat_name_ = boat_name_input;
}
void Boat::ask_and_set_boat_name()
{
cout << "\nPlease enter the name of the boat:\n> ";
set_boat_name(HelperFunctions::get_string_input());
}
string Boat::get_owner_name() const
{
return owner_name_;
}
void Boat::set_owner_name(const string owner_name_input)
{
owner_name_ = owner_name_input;
}
int Boat::get_booking_duration() const
{
return booking_duration_;
}
void Boat::set_booking_duration(const int booking_duration_input)
{
booking_duration_ = booking_duration_input;
}
void Boat::ask_and_set_booking_duration()
{
bool invalid_duration;
do
{
invalid_duration = false;
cout << "\nPlease enter the duration (in whole months) of the booking:\n> ";
const string booking_duration_input = HelperFunctions::get_string_input();
if (HelperFunctions::check_if_string_is_integer(booking_duration_input))
{
booking_duration_ = HelperFunctions::convert_string_to_integer(booking_duration_input);
}
else
{
HelperFunctions::print_invalid_input_message();
invalid_duration = true;
}
}
while (invalid_duration);
}
void Boat::ask_and_set_owner_name()
{
cout << "\nPlease enter the name of the boat's owner:\n> ";
set_owner_name(HelperFunctions::get_string_input());
}
void Boat::display_measures() const
{
cout << "Boat length: " << length_ << "m | " << "Boat depth: " << depth_ << "m" << endl;
}
void Boat::display_boat_name() const
{
cout << "Boat Name: " << boat_name_ << endl;
}
void Boat::display_owner_name() const
{
cout << "Owner Name: " << owner_name_ << endl;
}
void Boat::display_boat_and_owner_names() const
{
cout << "Boat Name: " << boat_name_ << " | " << "Owner Name: " << owner_name_ << endl;
}
void Boat::display_booking_duration() const
{
cout << "Booking duration: " << booking_duration_ << " months" << endl;
}
void Boat::display_info()
{
display_measures();
display_boat_and_owner_names();
display_booking_duration();
cout << "\n";
}