-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoat.cpp
More file actions
181 lines (150 loc) · 3.88 KB
/
Boat.cpp
File metadata and controls
181 lines (150 loc) · 3.88 KB
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
173
174
175
176
177
//
// Created by Joey Donohue on 9/30/25.
//
#include "Boat.h"
#include "Engine.h"
//default constructor
Boat::Boat() {
motor_count = 1;
tank_size = 20;
num_passengers = 1;
max_speed = 0;
boat_type= "motorboat";
M_MAX_MOTORS = 5;
M_MAX_TANK = 40;
M_MAX_PPL = 8;
M_MAX_SPEED = 30;
}
//constructor with variable input
Boat::Boat(int motor_cnt, int tank, int num_ppl, string name_p, string boat_t) {
motor_count = motor_cnt;
tank_size = tank;
num_passengers = num_ppl;
max_speed = 0;
name = name_p;
volume = 8;
boat_type = boat_t;
M_MAX_MOTORS = 5;
M_MAX_TANK = 40;
M_MAX_PPL = 8;
M_MAX_SPEED = 30;
}
//getters
int Boat::get_motor_lim() {
return M_MAX_MOTORS;
}
int Boat::get_tank_lim() {
return M_MAX_TANK;
}
int Boat::get_ppl_lim() {
return M_MAX_PPL;
}
int Boat::get_speed_lim() {
return M_MAX_SPEED;
}
int Boat::get_motor_count() {
return motor_count;
}
int Boat::get_tank_size() {
return tank_size;
}
int Boat::get_num_passengers() {
return num_passengers;
}
int Boat::get_max_speed() {
return max_speed;
}
Engine Boat::get_engine() {
return b_engine;
}
void Boat::set_engine(int engine_input) {
if (engine_input == 1) {
b_engine = Engine(10, 6,
false, 6500, true, 8);
}
if (engine_input == 2||engine_input != 1|| engine_input != 3) {
b_engine = Engine(6, 6, true, 6000,
false, 5);
}
if (engine_input == 3) {
b_engine = Engine(4, 4, true,
5000, true, 4);
}
}
//setters
//Each setter ensures that input is less max amount and more than 0
void Boat::set_motor_count(int m_count) {
if(m_count < 1 || m_count > M_MAX_MOTORS) {
m_count = 1;
}
motor_count = m_count;
}
void Boat::set_tank_size(int t_size) {
if(t_size < 1||t_size > M_MAX_TANK) {
t_size = 10;
}
tank_size = t_size;
}
void Boat::set_num_passengers(int n_ppl) {
if(n_ppl < 1||n_ppl > M_MAX_PPL) {
n_ppl = 1;
}
num_passengers = n_ppl;
}
/*
* Takes in the users boat and engine
* Modifies: max_speed
* returns: nothing
*/
void Boat::calc_max_speed(Boat created_boat, Engine& boat_engine) {
float boatHp = boat_engine.get_hp(); //getting hp from engine class
created_boat.calculate_mass(); //calculating mass using function from vehicle class
float boat_mass = created_boat.get_mass() + motor_count * 2;
max_speed = (boatHp * motor_count) / boat_mass*5;
max_speed -= (tank_size* .5 + num_passengers)/ 2;
if(0 > max_speed) {
max_speed = 1;
}
if(max_speed > M_MAX_SPEED) {
max_speed = M_MAX_SPEED;
}
}
int Boat::get_escape_chance() const {
int escape_chance = 0;
if(tank_size > 15)
escape_chance += 5;
if(tank_size > 25)
escape_chance += 10;
if(tank_size > 35)
escape_chance += 20;
escape_chance += (max_speed/ num_passengers)* 1.5;
return min(escape_chance, 99);
}
int Boat::final_escape_chance(Boat created_boat) {
int final_escape_chance;
int vehicle_chance = Boat::get_escape_chance();
final_escape_chance = created_boat.get_escape_chance()+
vehicle_chance;
return min(final_escape_chance, 99);
}
ostream& Boat::print(ostream& outs) {
outs << "Boat: type=" << boat_type
<< " motors=" << motor_count
<< " passengers=" << num_passengers
<< " max speed=" << max_speed;
return outs;
}
string Boat::get_type() const {
return boat_type;
}
void Boat::save(ostream &outs) const {
Vehicle::save(outs);
outs << boat_type << " " << motor_count << " " << tank_size << " " << num_passengers;
}
Boat* Boat::load(stringstream &ss) {
int motor_cnt, tank, num_passengers;
string boat_type, name;
ss >> name >> boat_type >> motor_cnt >> tank >> num_passengers;
Boat* boat = new Boat( motor_cnt, tank, num_passengers, name,boat_type);
return boat;
}