Chapter 4 IM Answers

Chapter 4 IM Answers - An Introduction to Programming with...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
An Introduction to Programming with C++: Fifth Edition 978-1-4188-3618-4 Chapter 4 Answers CONCEPT LESSON REVIEW QUESTIONS 1. c a memory location whose value can change while the program is running 2. d all of the above 3. a int numItems = 0; 4. c amt_Sold 5. a float 6. b initial = ‘H’; 7. c the number 0 8. c double rate = 0.0; 9. a payRate = static_cast<float>(3.56); 10. d none of the above 11. b const double RATE = 16.5; 12. d 15 13. b 5 14. b FICA (Federal Insurance Contributions Act) tax rate 15. d getline(cin, cityName); 16. d both a and b 17. c averageSales = static_cast<double>(sales1 + sales2 + sales3) / 3.0; 18. a cin.ignore(100); 19. b The int variable’s value will be temporarily converted to float . 20. c getline() function 21. d 3489.127000 22. c 3489.13 23. d all of the above
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
EXERCISES – PENCIL AND PAPER 1. double price = 0.0; price = 16.23; 2. float height = 0.0; float width = 0.0; height = static_cast<float>(4.5); width = static_cast<float>(6.9); 3. int population = 0; population = 60000; 4. char letter = ‘ ’; letter = ‘A’; 5. const double TAXRATE = .15; 6. const int MAXPAY = 20; 7. const char INSURED = ‘Y’; 8. const string PROMPT = “Press any key to continue”; 9. getline(cin, company); 10. tax = taxRate * grossPay; 11. int beginStock = 0; int purchased = 0; int sold = 0; int endStock = 0; endStock = beginStock + purchased – sold; 12. const double RATE = .05; double sales = 0.0; double bonus = 0.0; bonus = sales * RATE; 13. string empName = “”; int hours = 0; double payRate = 0.0; double grossPay = 0.0; grossPay = static_cast<double>(hours) * payRate; 14. cout << fixed << setprecision(2) << totalDue << endl; 15. payRate *= 1.03; EXERCISES – COMPUTER 1. See the Cpp5\Chap04\Ch4ConE01 Solution-IM files. c. warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data d. The number 57 appears in the Command Prompt window. This is the ASCII value for the character ‘9’. e. The compiler displays an error message (error C2440: 'initializing' : cannot convert from 'const char [2]' to 'int'). 2. See the Cpp5\Chap04\Ch4ConE02 Solution-IM files. You can use the increment operator as a shortcut for adding 1 to the contents of a variable. You can use the decrement operator as a shortcut for subtracting 1 from the contents of a variable.
Image of page 2
APPLICATION LESSON EXERCISES – COMPUTER 1. See the Cpp5\Chap04\Ch4AppE01 Solution-IM files. a. Input Processing Output sales rate (.05) Processing items: none Algorithm: 1. enter the sales 2. calculate the bonus by multiplying the sales by the rate 3. display the bonus bonus b. sales rate bonus 330.50 .05 16.525 d. RATE sales bonus .05 0.0 330.50 0.0 16.525 2. See the Cpp5\Chap04\Ch4AppE02 Solution-IM files.
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern