(This problem was partly made by someone else.)
In C++, what will the program print? Sum all the printed fractions, then add the numerator and denominator of the resulting (simplified) fraction, then square the sum.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Note that in the definition of
harmCharacter
, the first argument has typecharacter
instead ofcharacter*
(a pointer to acharacter
). Thus the whole struct is copied, and only the copy is modified; the original is left untouched. Likewise withhealCharacter
. Thus in all cases,player
is never modified, and thus there will be five lines of10/15
. The sum of them is 3 1 0 .This is most certainly a bug, as
harmCharacter
andhealCharacter
would do nothing this way. The fix is to change the arguments into of typecharacter*
instead, so that we have a pointer to the originalplayer
and thus we can modify it in the functions.