Advertisement
eniodordan

[OOP] ISPIT - 27.08.2019.

Sep 4th, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // 3. zadatak
  6. class Garage {
  7. private:
  8.     friend int IzracunSati(Garage, double, int);
  9. protected:
  10.     int mTotalPlaces; // > 0
  11.     int mOccupiedPlaces; // >= 0
  12.     double mHourlyRate; // > 0
  13. public:
  14.     Garage(int, double);
  15.     bool isFull() const;
  16.     void parkCar();
  17.     double Izracun() const;
  18. };
  19.  
  20. Garage::Garage(int totalplaces, double hourlyrate) {
  21.     if (totalplaces > 0 && hourlyrate > 0) {
  22.         mTotalPlaces = totalplaces;
  23.         mHourlyRate = hourlyrate;
  24.     }
  25. }
  26.  
  27. bool Garage::isFull() const {
  28.     if (mOccupiedPlaces == mTotalPlaces) {
  29.         return true;
  30.     }
  31.     return false;
  32. }
  33.  
  34. void Garage::parkCar() {
  35.     if (isFull()) {
  36.         return;
  37.     }
  38.     else {
  39.         mOccupiedPlaces++;
  40.     }
  41. }
  42.  
  43. void runExample() {
  44.     Garage garage(100, 2.50);
  45.     if (garage.isFull()) {
  46.         cout << "No space left." << endl;
  47.     }
  48.     else {
  49.         garage.parkCar();
  50.     }
  51. }
  52.  
  53. // 4. zadatak
  54. double Garage::Izracun() const {
  55.     return (mOccupiedPlaces * mHourlyRate * 24) / mTotalPlaces;
  56. }
  57.  
  58. // 5. zadatak
  59. int IzracunSati(Garage garage, double percent, int cars) {
  60.     int time = 0;
  61.     while ((garage.mOccupiedPlaces / garage.mTotalPlaces) < percent) {
  62.         garage.mOccupiedPlaces += cars;
  63.         time++;
  64.     }
  65.  
  66.     return time;
  67. }
  68.  
  69. // 6. zadatak
  70. class DvotarifnaGarage : Garage {
  71. private:
  72.     bool mTarifa; // true = noc, false = dan
  73.     double mHourlyRate;
  74. public:
  75.     DvotarifnaGarage(bool, double, int, double);
  76.     void PromjeniTarifu();
  77.     double Izracun() const;
  78. };
  79.  
  80. DvotarifnaGarage::DvotarifnaGarage(bool tarifa, double hourlyratenight, int totalplaces, double hourlyrateday) : mTarifa(tarifa), Garage(totalplaces, hourlyrateday) {
  81.     if (hourlyratenight > 0) {
  82.         this->mHourlyRate = hourlyratenight;
  83.     }
  84. }
  85.  
  86. void DvotarifnaGarage::PromjeniTarifu() {
  87.     if (mTarifa == true) {
  88.         mTarifa = false;
  89.     }
  90.     else {
  91.         mTarifa = true;
  92.     }
  93.  
  94. }
  95.  
  96. // 7. zadatak
  97. double DvotarifnaGarage::Izracun() const {
  98.     return (((mOccupiedPlaces / 2) * Garage::mHourlyRate * 24) + ((mOccupiedPlaces / 2) * DvotarifnaGarage::mHourlyRate * 24)) / mTotalPlaces;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement