fork download
  1. #include <iostream>
  2.  
  3. struct volume
  4. {
  5. int lit ;
  6. int ml ;
  7. };
  8.  
  9. volume operator+ ( volume a, volume b )
  10. {
  11. const int ml = a.ml + b.ml ;
  12. return { a.lit + b.lit + ml/1000, ml%1000 } ;
  13. }
  14.  
  15. std::ostream& operator<< ( std::ostream& stm, volume vol )
  16. { return stm << "( " << vol.lit << "L " << vol.ml << "ml )" ; }
  17.  
  18.  
  19. int main()
  20. {
  21. volume a { 12, 650 } ;
  22. volume b { 29, 723 } ;
  23. std::cout << a << " + " << b << " == " << a+b << '\n' ;
  24. }
  25.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
( 12L 650ml ) + ( 29L 723ml ) == ( 42L 373ml )