CJCoding With Joseph
15per day

Distance Add-Assign and Add (operator+= and operator+)

You are tracking total distance across multiple runs.

Create a class Distance that stores TWO ints: kilometers and meters.
- meters should always be 0..999 (normalize after operations).

Requirements:
1) Constructor Distance(int kilometers, int meters)
2) int getMeters() const  (return TOTAL meters)
3) operator+= adds another Distance to this one and returns *this
4) operator+ returns a NEW Distance using operator+= internally

Do NOT write a main function.

Expected Output:

350
15
Topics:
ClassesOperator Overloading
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.