Question

1 2 3 #include <iostream> #include <string> using namespace std; float getAmount (float & pricep, string item, int & howmany)

Which of the options below correctly reflects the situation after Line 29 has been executed? Option 1 Line 29 price 12 item

4 29 10 pencil 40 fee 16

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: Option 2) Price = 12, item = "birthday card", howmany = 50, fee = 37

Reason:

Debugging Function: getAmount(float & priceP, string itemP, int & howmanyP)

As we can see, the variables priceP and howamny are passed by reference and itemp is passed by value.

So, inside the function, when the line 6 executes, we get total = 10, next line 9 executes and value of priceP is updated to 12. Then, total is updated to 22 by adding priceP to it in line 11.Then, Line 12 executes and sets the value of itemP to "pencil", but as it is passed by value, item inside the main() remains the same. Then line 15 returns the value of total.

After the line 24 executes, we get the updated value of fee equal to 22, price = 12, howmany = 50 and item = "birthday card". The as the item is neither a book or a pencil, so statement 29 executes and the value of fee is incremented by 15, i.e fee = 37.

So, Option 2 is correct and all other options 1, 3 and 4 are wrong.

Add a comment
Know the answer?
Add Answer to:
1 2 3 #include <iostream> #include <string> using namespace std; float getAmount (float & pricep, string...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT