123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 | #include <iostream> #include <cmath> #include <string> using namespace std; class Alko{ public: string nazwa_typu; int procent; int volume; void setvalues(string nazwa, int p, int vol) { this->nazwa_typu = nazwa; this->procent = p; this->volume = vol; } void show() { cout << this->nazwa_typu << endl; } static Alko fun(Alko tab[],int n) { Alko *truj_max = &tab[0]; for (int i = 0; i < n; i++) if (*truj_max < tab[i]) { truj_max = &tab[i]; } return *truj_max; } bool operator<(const Alko &a) { return (1.0*this->procent/100) * this->volume < (1.0*a.procent/100) * a.volume; } }; ostream& operator<<(ostream & out, const Alko & a) { return out << a.nazwa_typu << " " << a.procent << "%" << " " << a.volume << endl; } int main() { Alko alkohole[4]; alkohole[1].setvalues("perla", 5, 8*500); alkohole[2].setvalues("amunsen", 40, 750); alkohole[3].setvalues("bimber",80,100); alkohole[0].setvalues("amarena",16,2000); Alko w = Alko::fun(alkohole, 4); w.show(); cout << (alkohole[2] < alkohole[1]); cout << alkohole[3]; } |