0

Hey. I have to write a Fraction class for homework and overload for the Fraction class the operators +, -, *, /, +=, -=, *=, /=, and << (the insertion operator). Can somebody please tell me what exactly the insertion operator is supposed to do? I've googled it and all I could find is when you use if with "cout". What does it have to do with fractions?

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by VernonDozier
0

Hey. I have to write a Fraction class for homework and overload for the Fraction class the operators +, -, *, /, +=, -=, *=, /=, and << (the insertion operator). Can somebody please tell me what exactly the insertion operator is supposed to do? I've googled it and all I could find is when you use if with "cout". What does it have to do with fractions?

A stream is a stream. << should function the same whether it is directing to a file or to the console (cout).

What it has to do with fractions (I imagine) is that if you have a whole number, a numerator, and a denominator, I imagine your function is supposed to send the whole number, then a space, then the numerator, then a slash, then the numerator to the stream. As in if your whole number is 3, your numerator is 4, and your denominator is 5:

  1. insert 3 into stream.
  2. Insert space into stream
  3. Insert 4 into stream
  4. Insert / into stream
  5. Insert 5 into stream

http://cpp.codenewbie.com/articles/cpp/1533/Operator_Overloading-Page_19.html

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.