Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // 3. zadatak
- class Garage {
- private:
- friend int IzracunSati(Garage, double, int);
- protected:
- int mTotalPlaces; // > 0
- int mOccupiedPlaces; // >= 0
- double mHourlyRate; // > 0
- public:
- Garage(int, double);
- bool isFull() const;
- void parkCar();
- double Izracun() const;
- };
- Garage::Garage(int totalplaces, double hourlyrate) {
- if (totalplaces > 0 && hourlyrate > 0) {
- mTotalPlaces = totalplaces;
- mHourlyRate = hourlyrate;
- }
- }
- bool Garage::isFull() const {
- if (mOccupiedPlaces == mTotalPlaces) {
- return true;
- }
- return false;
- }
- void Garage::parkCar() {
- if (isFull()) {
- return;
- }
- else {
- mOccupiedPlaces++;
- }
- }
- void runExample() {
- Garage garage(100, 2.50);
- if (garage.isFull()) {
- cout << "No space left." << endl;
- }
- else {
- garage.parkCar();
- }
- }
- // 4. zadatak
- double Garage::Izracun() const {
- return (mOccupiedPlaces * mHourlyRate * 24) / mTotalPlaces;
- }
- // 5. zadatak
- int IzracunSati(Garage garage, double percent, int cars) {
- int time = 0;
- while ((garage.mOccupiedPlaces / garage.mTotalPlaces) < percent) {
- garage.mOccupiedPlaces += cars;
- time++;
- }
- return time;
- }
- // 6. zadatak
- class DvotarifnaGarage : Garage {
- private:
- bool mTarifa; // true = noc, false = dan
- double mHourlyRate;
- public:
- DvotarifnaGarage(bool, double, int, double);
- void PromjeniTarifu();
- double Izracun() const;
- };
- DvotarifnaGarage::DvotarifnaGarage(bool tarifa, double hourlyratenight, int totalplaces, double hourlyrateday) : mTarifa(tarifa), Garage(totalplaces, hourlyrateday) {
- if (hourlyratenight > 0) {
- this->mHourlyRate = hourlyratenight;
- }
- }
- void DvotarifnaGarage::PromjeniTarifu() {
- if (mTarifa == true) {
- mTarifa = false;
- }
- else {
- mTarifa = true;
- }
- }
- // 7. zadatak
- double DvotarifnaGarage::Izracun() const {
- return (((mOccupiedPlaces / 2) * Garage::mHourlyRate * 24) + ((mOccupiedPlaces / 2) * DvotarifnaGarage::mHourlyRate * 24)) / mTotalPlaces;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement