Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- //27.08.2019.
- /*
- template<typename Tip>
- Tip findRarest(Tip* polje, int vel) {
- int brojac = 1;
- int rare = vel;
- int minIndex = 0;
- for (int i = 0; i < vel; i++) {
- for (int j = i + 1; j < vel; j++) {
- if (polje[i] == polje[j]) {
- brojac++;
- }
- }
- if (brojac < rare) {
- rare = brojac;
- minIndex = i;
- }
- brojac = 1;
- while (polje[i] == polje[i + 1]) {
- i++;
- }
- }
- return polje[minIndex];
- }
- class Coordinate {
- float x, y;
- public:
- Coordinate(float a, float b) : x(a), y(b) {}
- Coordinate() : x(0), y(0) {}
- friend bool operator==(const Coordinate& ref1, const Coordinate& ref2) {
- return ref1.x == ref2.x && ref1.y == ref2.y;
- }
- };*/
- class Garage {
- protected:
- int mTotalPlaces;
- int mOccupiedPlaces;
- double mHourlyRate;
- public:
- Garage(int total, int occupied, double hour) : mTotalPlaces(total), mOccupiedPlaces(occupied), mHourlyRate(hour) {}
- Garage() : mTotalPlaces(0), mOccupiedPlaces(0), mHourlyRate(0) {}
- Garage(int total, double hour) : mTotalPlaces(total), mOccupiedPlaces(total), mHourlyRate(hour) {}
- bool isFull() {
- return (mTotalPlaces == mOccupiedPlaces);
- }
- void parkCar(){
- mOccupiedPlaces++;
- }
- double DailyIncome() {
- double produkt = mOccupiedPlaces * mHourlyRate * 24;
- return produkt / mTotalPlaces;
- }
- friend double TimeTillFull(double postotak, int NewCarPerHour, Garage G1);
- friend ostream& operator<< (Garage& ref1, ostream& izlaz) {
- izlaz << ref1.mHourlyRate << ", " << ref1.mTotalPlaces << endl;
- return izlaz;
- }
- };
- double TimeTillFull(double postotak, int NewCarPerHour, Garage G1){
- double noviBr = G1.mTotalPlaces * postotak;
- noviBr = noviBr - G1.mOccupiedPlaces;
- return noviBr / NewCarPerHour;
- }
- void runExample() {
- Garage garage(100, 2.50);
- if (garage.isFull())
- cout << "No space left." << endl;
- else
- garage.parkCar();
- }
- class TwoTariffeGarage : public Garage {
- double mNightlyRate;
- bool mDayOrNight;
- public:
- TwoTariffeGarage(double nightly, bool dayornight, int total, int occupied, double hour): mNightlyRate(nightly), mDayOrNight(dayornight), Garage(total, occupied, hour){}
- void SetDayOrNight(bool Change){
- mDayOrNight = Change;
- }
- double DailyIncome() {
- double produkt = (mOccupiedPlaces * mHourlyRate * 12) + (mOccupiedPlaces * mNightlyRate * 12);
- return produkt / mTotalPlaces;
- }
- };
- void swap(Garage* garage1, Garage* garage2) {
- Garage temp = *garage1;
- *garage1 = *garage2;
- *garage2 = temp;
- }
- void Sort(Garage* polje, int vel, string FileName) {
- ofstream izlaznaDat(FileName);
- for (int i = 0; i < vel; i++) {
- for (int j = i + 1; j < vel; j++) {
- if (polje[i].DailyIncome() < polje[j].DailyIncome()) {
- swap(polje[i], polje[j]);
- }
- }
- izlaznaDat << polje[i] << endl;
- }
- izlaznaDat.close();
- }
- int main() {
- int n;
- runExample();
- //int polje[] = { 2,2,2,4,4,9,9 };
- //cout << findRarest(polje, 7);
- //int data[] = { 1,2,3,3,3,4 };
- //cout << findRarest(data, 6) << endl;
- //Coordinate coordinates[] = { Coordinate(18.695, 45.555), Coordinate(0.0, 0.0), Coordinate(18.695, 45.555) };
- //cout << findRarest(coordinates, 3) << endl;
- cin >> n;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement