Advertisement
amarek

Garage

Jul 3rd, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. //27.08.2019.
  7. /*
  8. template<typename Tip>
  9. Tip findRarest(Tip* polje, int vel) {
  10.     int brojac = 1;
  11.     int rare = vel;
  12.     int minIndex = 0;
  13.     for (int i = 0; i < vel; i++) {
  14.         for (int j = i + 1; j < vel; j++) {
  15.             if (polje[i] == polje[j]) {
  16.                 brojac++;
  17.             }
  18.         }
  19.         if (brojac < rare) {
  20.             rare = brojac;
  21.             minIndex = i;
  22.         }
  23.         brojac = 1;
  24.         while (polje[i] == polje[i + 1]) {
  25.             i++;
  26.         }
  27.     }
  28.     return polje[minIndex];
  29. }
  30.  
  31. class Coordinate {
  32.     float x, y;
  33. public:
  34.     Coordinate(float a, float b) : x(a), y(b) {}
  35.     Coordinate() : x(0), y(0) {}
  36.     friend bool operator==(const Coordinate& ref1, const Coordinate& ref2) {
  37.         return ref1.x == ref2.x && ref1.y == ref2.y;
  38.     }
  39. };*/
  40.  
  41. class Garage {
  42. protected:
  43.     int mTotalPlaces;
  44.     int mOccupiedPlaces;
  45.     double mHourlyRate;
  46. public:
  47.     Garage(int total, int occupied, double hour) : mTotalPlaces(total), mOccupiedPlaces(occupied), mHourlyRate(hour) {}
  48.     Garage() : mTotalPlaces(0), mOccupiedPlaces(0), mHourlyRate(0) {}
  49.     Garage(int total, double hour) : mTotalPlaces(total), mOccupiedPlaces(total), mHourlyRate(hour) {}
  50.  
  51.     bool isFull() {
  52.         return (mTotalPlaces == mOccupiedPlaces);
  53.     }
  54.  
  55.     void parkCar(){
  56.         mOccupiedPlaces++;
  57.     }
  58.  
  59.     double DailyIncome() {
  60.         double produkt = mOccupiedPlaces * mHourlyRate * 24;
  61.         return produkt / mTotalPlaces;
  62.     }
  63.  
  64.     friend double TimeTillFull(double postotak, int NewCarPerHour, Garage G1);
  65.  
  66.     friend ostream& operator<< (Garage& ref1, ostream& izlaz) {
  67.         izlaz << ref1.mHourlyRate << ", " << ref1.mTotalPlaces << endl;
  68.         return izlaz;
  69.     }
  70. };
  71.  
  72. double TimeTillFull(double postotak, int NewCarPerHour, Garage G1){
  73.     double noviBr = G1.mTotalPlaces * postotak;
  74.     noviBr = noviBr - G1.mOccupiedPlaces;
  75.     return noviBr / NewCarPerHour;
  76. }
  77.  
  78. void runExample() {
  79.     Garage garage(100, 2.50);
  80.     if (garage.isFull())
  81.         cout << "No space left." << endl;
  82.     else
  83.         garage.parkCar();
  84. }
  85.  
  86. class TwoTariffeGarage : public Garage {
  87.     double mNightlyRate;
  88.     bool mDayOrNight;
  89. public:
  90.     TwoTariffeGarage(double nightly, bool dayornight, int total, int occupied, double hour): mNightlyRate(nightly), mDayOrNight(dayornight), Garage(total, occupied, hour){}
  91.     void SetDayOrNight(bool Change){
  92.         mDayOrNight = Change;
  93.     }
  94.  
  95.     double DailyIncome() {
  96.         double produkt = (mOccupiedPlaces * mHourlyRate * 12) + (mOccupiedPlaces * mNightlyRate * 12);
  97.         return produkt / mTotalPlaces;
  98.     }
  99. };
  100.  
  101. void swap(Garage* garage1, Garage* garage2) {
  102.     Garage temp = *garage1;
  103.     *garage1 = *garage2;
  104.     *garage2 = temp;
  105. }
  106.  
  107. void Sort(Garage* polje, int vel, string FileName) {
  108.     ofstream izlaznaDat(FileName);
  109.  
  110.     for (int i = 0; i < vel; i++) {
  111.         for (int j = i + 1; j < vel; j++) {
  112.             if (polje[i].DailyIncome() < polje[j].DailyIncome()) {
  113.                 swap(polje[i], polje[j]);
  114.             }
  115.         }
  116.         izlaznaDat << polje[i] << endl;
  117.     }
  118.     izlaznaDat.close();
  119. }
  120.  
  121. int main() {
  122.     int n;
  123.     runExample();
  124.     //int polje[] = { 2,2,2,4,4,9,9 };
  125.     //cout << findRarest(polje, 7);
  126.    
  127.     //int data[] = { 1,2,3,3,3,4 };
  128.     //cout << findRarest(data, 6) << endl;
  129.     //Coordinate coordinates[] = { Coordinate(18.695, 45.555), Coordinate(0.0, 0.0), Coordinate(18.695, 45.555) };
  130.     //cout << findRarest(coordinates, 3) << endl;
  131.  
  132.     cin >> n;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement