Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by asrori on 06/03/18.
- //
- #ifndef PRAKTIKUM2_MOBIL_H
- #define PRAKTIKUM2_MOBIL_H
- #include <iostream>
- class Mobil{
- private:
- int kecepatan;
- int bensin;
- public:
- Mobil(){
- this->bensin = 100;
- this->kecepatan = 0;
- }
- bool berkendara(int kecepatan){
- bool adaBensin = cekBensin(kecepatan);
- if (adaBensin) {
- (kecepatan < 50) ? this->bensin = this->bensin - 20 : this->bensin = this->bensin - 40;
- return true;
- } else {
- return false;
- }
- }
- bool cekBensin(int kecepatan){
- if (kecepatan < 50)
- if ((this->bensin - 20) < 0) return false;
- if (kecepatan >= 50)
- if ((this->bensin - 40) < 0) return false;
- return true;
- }
- bool bensinPenuh(){
- if (this->bensin == 100) {
- return true;
- } else {
- this->bensin = this->bensin + 20;
- return false;
- };
- }
- int getKecepatan() const {
- return kecepatan;
- }
- int getBensin() const {
- return bensin;
- }
- };
- #endif //PRAKTIKUM2_MOBIL_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement