40 ostream&
operator<<(ostream &s,
const vector<shared_ptr<Fahrzeug>>& v);
49 bool fuel_consumption(
const shared_ptr<Fahrzeug>& a,
const shared_ptr<Fahrzeug>& b);
53 return a->verbrauch() < b->verbrauch();
63 float add_fuel(
float x,
const shared_ptr<Fahrzeug>& y);
65 float add_fuel(
float x,
const shared_ptr<Fahrzeug>& y)
67 return x + y->verbrauch();
73 cout <<
" -------- New in v_10c_shared --------------\n";
86 vector<shared_ptr<Fahrzeug>> v{
87 make_shared<Raba>(3600, 4000), make_shared<Opel>(1450), make_shared<MAN>(1200, 12000),
88 make_shared<Smart>(950), make_shared<Smart>(1100)
94 cout <<
" -------- after sort (standard --> incorrect) -------------\n";
95 sort(v.begin(),v.end());
98 cout <<
" -------- only the pointers have been compared -------------\n";
100 cout <<
" -------- after sort (compare regarding fuel consumption) -------------\n";
104 cout <<
" -------- correct-------------\n";
109 for (
unsigned int i=0; i<v.size(); ++i)
111 sum += v[i]->verbrauch();
113 cout <<
"konv: durchschnittlicher Verbrauch: " << sum/v.size() << endl;
116 float sum2 =accumulate(v.begin(), v.end(), 0.0f,
add_fuel);
117 cout <<
"accu: durchschnittlicher Verbrauch: " << sum2/v.size() << endl;
120 cout <<
" -------- sort using lambda function for 'operator>' -------------\n";
123 sort(v.begin(),v.end(),
124 [](
const shared_ptr<Fahrzeug>& aa,
const shared_ptr<Fahrzeug>& cc) ->
bool
126 return aa->verbrauch() > cc->verbrauch();
150 ostream&
operator<<(ostream &s,
const vector<shared_ptr<Fahrzeug>>& v)
152 for (
const auto& it: v)
virtual float verbrauch() const =0
virtual std::string classname() const
Class name.
bool fuel_consumption(const shared_ptr< Fahrzeug > &a, const shared_ptr< Fahrzeug > &b)
Compares the fuel consumption between two vehicles.
ostream & operator<<(ostream &s, const Fahrzeug &p)
Prints some info from a vehicle.
float add_fuel(float x, const shared_ptr< Fahrzeug > &y)
Adds the fuel consumption of a vehicle y to quantity x.