Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- template<typename Tip>
- int findLongestGrowth(Tip *array, int size)
- {
- int maxGrowth = 0;
- int currentGrowth;
- for (int i = 0; i < size; i++)
- {
- currentGrowth = 1;
- for (int j = i + 1; array[j] > array[j-1]; j++)
- {
- currentGrowth++;
- }
- if (currentGrowth > maxGrowth)
- {
- maxGrowth = currentGrowth;
- }
- }
- return maxGrowth;
- }
- class Battery
- {
- private:
- double capacityMah, percentageFull;
- public:
- Battery() : capacityMah(0), percentageFull(0) {}
- Battery(double capacity) : capacityMah(capacity), percentageFull(0){}
- Battery(double mCapacityMah, double mPercentageFull) : capacityMah(mCapacityMah), percentageFull(mPercentageFull) {}
- friend bool operator> (const Battery&, const Battery&);
- friend ostream& operator<< (ostream&, const Battery&);
- };
- bool operator> (const Battery& b1, const Battery& b2)
- {
- return b1.capacityMah > b2.capacityMah && b1.percentageFull > b2.percentageFull;
- }
- ostream& operator<< (ostream& izlaz, const Battery& b)
- {
- izlaz << b.capacityMah << ", " << b.percentageFull << endl;
- return izlaz;
- }
- class Taximeter
- {
- protected:
- double pricePerKm;
- double startPrice;
- public:
- Taximeter() : pricePerKm(0), startPrice(0){}
- Taximeter(double mPricePerKg, double mStartPrice) : pricePerKm(mPricePerKg), startPrice(mStartPrice)
- {
- if (pricePerKm < 0)
- {
- pricePerKm *= -1; //apolutna vrijednost
- }
- if (startPrice < 0)
- {
- startPrice *= -1;
- }
- }
- void setChangePricePerKm(double newPrice)
- {
- pricePerKm = newPrice;
- }
- friend ostream& operator<< (ostream&, const Taximeter&);
- double ridePrice(double distance)
- {
- if (distance < 5)
- {
- return 5 + startPrice;
- }
- if (distance > 20)
- {
- return (pricePerKm * distance) + startPrice;
- }
- else
- {
- return (pricePerKm * 0.9 * distance) + startPrice;
- }
- }
- double averagePrice(double *distances, int n, int size)
- {
- int sum = 0;
- for (int i = 0; i < size; i++)
- {
- if ((i + 1) % n == 0)
- {
- break;
- }
- sum += ridePrice(distances[i]);
- }
- return sum / size;
- }
- };
- ostream& operator<< (ostream& izlaz, const Taximeter& taxi)
- {
- izlaz << taxi.pricePerKm << ", " << taxi.startPrice << endl;
- return izlaz;
- }
- class BusTaximeter : Taximeter
- {
- private:
- int passengerNumber;
- bool outOfCityRide;
- public:
- BusTaximeter() : passengerNumber(0), outOfCityRide(0){}
- BusTaximeter(int mPassangerNumber, bool mOutOfCityRide): passengerNumber(mPassangerNumber), outOfCityRide(mOutOfCityRide){}
- void setOutOfCityRide(bool outOfCity)
- {
- outOfCityRide = outOfCity;
- }
- double ridePrice(double distance)
- {
- double discount;
- if (passengerNumber >= 20)
- {
- discount = 0.8;
- }
- else
- {
- discount = 1 - (passengerNumber * 2 / 100);
- }
- if (outOfCityRide)
- {
- return discount * pricePerKm * distance * 2;
- }
- else
- {
- return discount * pricePerKm * distance;
- }
- }
- };
- int main()
- {
- int array[] = { 1,2,1,2,3 };
- cout << findLongestGrowth(array, 5) << endl;
- Battery batteries[] = { Battery(), Battery(1566), Battery(4000), Battery(1500) };
- if (findLongestGrowth(batteries, 4) == 1)
- {
- cout << batteries[0] << endl;
- }
- system("pause");
- }
Add Comment
Please, Sign In to add comment