1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <iostream>
using namespace std;
class box{
public:
box(int a = 0, int b = 0, int c = 0) : h(a), l(b), w(c) {}
double volume() const { return l*h*w; }
bool operator > (const box& a) const { return volume() > a.volume(); }
friend ostream& operator<<(ostream&os, const box& b);
private:
double h;
double l;
double w;
};
ostream& operator<<(ostream& os, const box& b)
{
return os << b.h << " x " << b.l << " x " << b.w;
}
int main(){
//Question #2
box x(1, 2, 3), g;
box f(7, 8, 120), m(8, 6, 4);
cout << "Comparing g (" << g << ") and x (" << x << ")\n";
cout << " g (" << g.volume() << ") ";
if (g > x)
cout << "is greater ";
else
cout << "is not greater ";
cout << "than x (" << x.volume() << ")\n";
cout << "\nComparing m (" << m << ") and f (" << f << ")\n";
cout << "m (" << m.volume() << ") ";
if (m > f)
cout << "is greater " ;
else
cout << "is not greater " ;
cout << "than f (" << f.volume() << ")\n";
}
|