#include <iostream>
#include <iomanip>
using namespace std;
class YakitMaliyet {
friend ostream& operator<<(ostream& out, const YakitMaliyet& obj) {
out << setprecision(2) << fixed << right;
out << "Yol uzunlugu: " << setw(24) << obj.distance << endl;
out << "Normal yakit tuketimi: " << setw(15) << obj.fuel << endl;
out << "Ruzgara karsi yakit tuketimi: " << setw(8) << obj.getRuzgarEngeli() + obj.fuel << endl;
out << "Ruzgar destekli yakit tuketimi: " << setw(6) << obj.getRuzgarDestegi() + obj.fuel << endl;
out << "Ruzgar engeli: " << setw(23) << obj.getRuzgarEngeli() << endl;
out << "Ruzgar destegi: " << setw(22) << obj.getRuzgarDestegi() << endl;
out << "Gidiste harcanan yakit: " << setw(14) << obj.gidisHesapla() << endl;
out << "Geliste harcanan yakit: " << setw(14) << obj.gelisHesapla() << endl;
out << "Toplam harcanan yakit: " << setw(15) << obj.gidisGelisHesapla() << endl << endl;
return out;
}
public:
YakitMaliyet(int fuel = 80, int distance = 100, bool windy = false) {
if (0 > distance) {
throw invalid_argument("Mesafe sifirdan kucuk olamaz.");
}
if (0 > fuel)
throw invalid_argument("Yakit tuketimi sifirdan kucuk olamaz.");
this->distance = distance;
this->fuel = fuel;
this->windy = windy;
}
YakitMaliyet& operator=(const YakitMaliyet& other) {
this->distance = distance;
this->fuel = fuel;
this->windy = windy;
}
/*friend void yakitHesapla() {
}*/
//rüzgarlı ise hep gidiş durumunda aleyhe işleyecek şekilde kabul ettim
double gidisHesapla() const {
if (windy) {
return (static_cast<double>(distance) * fuel + WIND_BLOCK * distance);
}
else {
return (static_cast<double>(distance) * fuel);
}
}
double gelisHesapla() const {
if (windy) {
return (static_cast<double>(distance) * fuel + WIND_SUPPORT * distance);
}
else {
return (static_cast<double>(distance) * fuel);
}
}
double gidisGelisHesapla() const {
return (gidisHesapla() + gelisHesapla());
}
double getRuzgarDestegi() const {
if (windy) {
return (WIND_SUPPORT * distance);
}
else {
return 0;
}
}
double getRuzgarEngeli() const {
if (windy) {
return (WIND_BLOCK * distance);
}
else {
return 0;
}
}
void setDistance(int distance) {
this->distance = distance;
}
int getDistance() const {
return distance;
}
void setFuel(int fuel) {
this->fuel = fuel;
}
int getFuel() const {
return fuel;
}
void setWindy(bool windy) {
this->windy = windy;
}
const bool getWindy() const {
return windy;
}
private:
int distance;
int fuel;
bool windy;
static constexpr auto WIND_SUPPORT{ 10.0 / 100 };
static constexpr auto WIND_BLOCK{ -15.0 / 100 };
};
int main() {
YakitMaliyet araba1;
YakitMaliyet araba2{ 65, 137, true };
YakitMaliyet araba3{ 23, 41, false };
YakitMaliyet araba4 = araba3;
cout << araba1 << araba2 << araba3 << araba4 << endl;
return 0;
}