forked from coders-school/Cars
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPetrolEngine.cpp
More file actions
42 lines (33 loc) · 968 Bytes
/
PetrolEngine.cpp
File metadata and controls
42 lines (33 loc) · 968 Bytes
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
#include <iostream>
#include <stdexcept>
#include "Exeptions.hpp"
#include "PetrolEngine.hpp"
PetrolEngine::PetrolEngine(int power, float capacity, int gears)
: power_(power), capacity_(capacity), gears_(gears), currentGear_(0) {
std::cout << __FUNCTION__ << std::endl;
}
void PetrolEngine::changeGear(int gear) {
// TODO: Add checking if gear is between -1 and gears_
// -1 is for REAR
// 0 is for NEUTRAL
if (gear == -1 && currentGear_ != 0) {
throw InvalidGear("Invalid changing gears");
}
if (gear > gears_ || gear < -1) {
throw InvalidGear("There is no so many gears!!!");
}
currentGear_ = gear;
std::cout << __FUNCTION__ << std::endl;
}
int PetrolEngine::getGears() const {
return gears_;
}
int PetrolEngine::getPower() const {
return power_;
}
float PetrolEngine::getCapacity() const {
return capacity_;
}
int PetrolEngine::getCurrentGear() const {
return currentGear_;
}