Chapter 10 IM Answers

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

Info iconThis preview shows pages 1–3. 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 10 Answers CONCEPT LESSON REVIEW QUESTIONS 1. c A void function cannot receive any items of information when it is called. 2. d displayHeading(companyName); 3. a void calcEndingBalance(int, int); 4. d 5. c calcEndingInventory(beginInventory, sales, purchases, endingInventory); 6. d by value 7. c by reference 8. c function header, function prototype 9. b The function header is considered a C++ statement, so it must end with a semicolon. 10. d displayName(); 11. c void displayName(); 12. c the statement immediately below the one that called the function 13. a True 14. b local 15. d To pass a variable by reference in C++, you place an ampersand (&) before the variable’s name in the statement that calls the function. 16. c void calcNewPrice(double, double &); 17. d calcNewPrice(oldPrice, newPrice); 18. a The names of the formal parameters in the function header must be identical to the names of the actual arguments in the function call. EXERCISES – PENCIL AND PAPER 1. void halveNumber(int num) { cout << num / 2 << endl; } //end of halveNumber function 2. void getItemName(string item) { cout << “Enter the item name: ”; getline(cin, item); } //end of getItemName function 3. { n3 = n1 + n2; n4 = n1 – n2; } //end of calcSumAndDiff function 4. { n3 = n1 / n2; } //end of getQuotient function 5. void displayName(string name) { cout << name << endl; } //end of displayName function
Background image of page 1

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

View Full DocumentRight Arrow Icon
6. Desk-check table after the first four statements in the main() function are processed: begVal purchase sale endVal 1000 500 200 0 Desk-check table after the calcEnd() function is processed: begVal purchase sale endVal [ main() ] ending [ calcEnd() ] beg pur sale 1000 500 200 0 1300 1000 500 200 Desk-check table after the calcEnd() function ends: begVal purchase sale endVal beg pur sale 1000 500 200 0 1300 1000 500 200 EXERCISES – COMPUTER 1. See the Cpp5\Chap10\Ch10ConE01 Solution-IM files. 2. See the Cpp5\Chap10\Ch10ConE02 Solution-IM files. 3. See the Cpp5\Chap10\Ch10ConE03 Solution-IM files. To debug the program, enter the function prototype void getName(string &); above int main() in the program. Also, change the function header to . 4. See the Cpp5\Chap10\Ch10ConE04 Solution-IM files. To debug the program, enter a semicolon at the end of each function prototype. In addition, remove the ampersand from the two statements that call the getNumber() function. Also change the calcSum() function’s prototype to void calcSum(int, int, int &); , and change its header to
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

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

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online