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

Comparing m (8 x 6 x 4) and f (7 x 8 x 120)
m (192) is not greater than f (6720)