Thanks....
Quote:
Originally Posted by Banfa
Well the class Sales_item implements the compound operator += (line 52 of attached file) so the answer can't be that it is an invalid operation.
oh yes...I now understand atleast some part of Sales_item.h file.
Quote:
Originally Posted by Banfa
I guess we would need to see the calling code although the main reason for using + rather than += is you need to keep the original value of the lhs of the equation.
I read some C long time ago, but I dont get what you mean by "using + rather than += is you need to keep the original value of the lhs of the equation". Can you please explain this to me?
Anyways, here's the code:
- #include <iostream>
-
#include "Sales_item.h"
-
-
int main()
-
{
-
// declare variables to hold running sum and data for the next record
-
Sales_item total, trans;
-
// is there data to process?
-
if (std::cin >> total) {
-
// if so, read the transaction records
-
while (std::cin >> trans)
-
if (total.same_isbn(trans))
-
// match: update the running total
-
total = total + trans;
-
else {
-
// no match: print & assign to total
-
std::cout << total << std::endl;
-
total = trans;
-
}
-
// remember to print last record
-
std::cout << total << std::endl;
-
} else {
-
// no input!, warn the user
-
std::cout << "No data?!" << std::endl;
-
return -1; // indicate failure
-
}
-
return 0;
-
}
Line 14 has got the statement that is our present matter of discussion.
Thanks again for you input.