Programming Logic and Design, 8th Edition(Chapter 1 to 4 Answers) - Programming Logic and Design 8th Ed Chapter 1 Review Questions 1 a b c d 2 a b c d 3

Programming Logic and Design, 8th Edition(Chapter 1 to 4 Answers)

This preview shows page 1 out of 909 pages.

Unformatted text preview: Programming Logic and Design, 8th Ed Chapter 1 Review Questions 1 a. b. c. d. 2 a. b. c. d. 3 a. b. c. d. 4 a. b. c. d. 5 a. b. c. d. 6 a. b. c. d. 7 a. b. c. d. 8 a. b. c. d. 9 a. b. c. d. 10 a. b. c. d. 11 a. b. c. d. 12 a. b. c. d. 13 a. b. c. d. 14 a. b. c. d. 15 a. b. c. d. 16 a. b. c. d. 17 a. b. c. d. 18 a. b. c. d. 19 a. b. c. d. 20 a. b. c. d. Programming Exerci 1. Match the definit 1 2 3 4 5 Answer: 1 2 3 4 5 2. In your own wor Answer: The programmer mu 3. Match the term w Answer: 1 2 3 4 5 4. Draw a flowchar Answer: Flowchart Pseudocode start stop 5. Draw a flowchar Answer: Flowchart Pseudocode start set surfaceArea set volume = ed stop 6. Draw a flowchar Answer: Flowchart Pseudocode start stop 7. a. Draw a flowch Answer: Flowchart Pseudocode start stop b. Modify the progra Answer: Flowchart Pseudocode start stop (Please note th 8. a. Draw a flowch Answer: Flowchart Pseudocode start stop b. Modify the progra Answer: Flowchart Pseudocode start stop c. Modify the progra Answer: Flowchart Pseudocode start stop 9. Research current Answer: Flowchart Pseudocode start stop (Please note th 10. Draw a flowchar Answer: Flowchart Pseudocode start stop 11. A consignment sh Answer: Flowchart Pseudocode start stop 12. A mobile phone Answer: (Please note this s Flowchart Pseudocode start stop Performing Maintena 1. In this chapter yo Answer: // This program acce // and rent, utilities, a // and displays the am // (which might be ne // Modify the program // as well as the rema start input pay input rent input utilities input groceries set bills = rent + ut set discretionary = output pay output bills output discretionar stop Find the Bugs 1. Your downloadab slashes) that describe introductory commen Answer: DEBUG01-01 // This pseudocode is // computing the pric start input origPrice set discount = origP set finalPrice = orig output finalPrice stop DEBUG01-02 // This pseudocode is // the number of mile start input milesTravele input gallonsOfGas set milesPerGallon // milesPerGallon output milesPerGa // the P is milesPe stop // Program should e DEBUG01-03 // This pseudocode is // computing the per // in a 30-day month start input rent set costPerDay = re // Comment indic output costPerDay // output should b stop 2. Your downloadab Answer: Game Zone 1. Create the logic f Answer: Students’ answers wi start input input input input word1 word2 word3 word4 stop Up for Discussion 1. Which is the bett Answer: Answers will vary. M 2. What is the imag Answer: The programmer is o gic and Design, 8th Edition Chapter 1 Review Questions Computer programs also are known as _____. hardware software data information The major computer operations include _____. hardware and software input, processing, and output sequence and looping spreadsheets, word processing, and data communications Visual Basic, C++, and Java are all examples of computer _____. operating systems hardware machine languages programming languages A programming language’s rules are its _____. syntax logic format options The most important task of a compiler or interpreter is to _____. create the rules for a programming language translate English statements into a language such as Java translate programming language statements into machine language execute machine language programs to perform useful tasks Which of the following is temporary, internal storage? CPU hard disk keyboard memory Which of the following pairs of steps in the programming process is in the correct order? code the program, plan the logic test the program, translate it into machine language put the program into production, understand the problem code the program, translate it into machine language A programmer’s most important task before planning the logic of a program is to _____. decide which programming language to use code the problem train the users of the program understand the problem The two most commonly used tools for planning a program’s logic are _____. flowcharts and pseudocode ASCII and EBCDIC Java and Visual Basic word processors and spreadsheets Writing a program in a language such as C++ or Java is known as _____ the program. translating coding interpreting compiling An English-like programming language such as Java or Visual Basic is a _____ programming language. machine-level low-level high-level binary-level Which of the following is an example of a syntax error? producing output before accepting input subtracting when you meant to add misspelling a programming language word all of the above Which of the following is an example of a logical error? performing arithmetic with a value before inputting it accepting two input values when a program requires only one dividing by 3 when you meant to divide by 30 all of the above The parallelogram is the flowchart symbol representing _____. input output either a or b none of the above In a flowchart, a rectangle represents _____. input a sentinel a question processing In flowcharts, the decision symbol is a _____. parallelogram rectangle lozenge diamond The term “eof” represents _____. a standard input device a generic sentinel value a condition in which no more memory is available for storage the logical flow in a program When you use an IDE, as opposed to a simple text editor, to develop a program, _____. the logic is more complicated the logic is simpler the syntax is different some help is provided When you write a program that will run in a GUI environment as opposed to a command-line environment, _____. the logic is very different some syntax is different you do not need to plan the logic users are more confused As compared to procedural programming, with object-oriented programming, _____. the programmer’s focus differs you cannot use some languages, such as Java you do not accept input you do not code calculations; they are created automatically Programming Exercises 1. Match the definition with the appropriate term. Compute r system a. compiler devices Another word for programs b. syntax Languag e rules c. logic Order of instructio ns d. hardware Languag e translator e. software Compute r system equipme nt → d. hardware Another word for → programs e. software Languag → e rules b. syntax Order of instructio → ns c. logic Languag e → translator a. compiler 2. In your own words, describe the steps to writing a computer program. The programmer must understand the problem that the user is trying to solve. Next, the programmer plans the logic, often 3. Match the term with the appropriate shape. Input → Processin → g Output → Decision → Terminal → B. A. B. D. C. 4. Draw a flowchart or write pseudocode to represent the logic of a program that allows the user to enter a value. The pro Flowchart Pseudocode start input myNumber set myAnswer = myNumber / 2 output myAnswer stop 5. Draw a flowchart or write pseudocode to represent the logic of a program that allows the user to enter a value for one Flowchart Pseudocode start input edge set sideArea = edge * edge set surfaceArea = 6 * sideArea set volume = edge * edge * edge output sideArea output surfaceArea output volume stop 6. Draw a flowchart or write pseudocode to represent the logic of a program that allows the user to enter two values. The Flowchart Pseudocode start input firstValue input secondValue set answer = firstValue * secondValue output answer stop 7. a. Draw a flowchart or write pseudocode to represent the logic of a program that allows the user to enter values for the Flowchart Pseudocode start input roomWidth input roomLength set roomArea = roomWidth * roomLength output roomArea stop b. Modify the program that computes floor area to compute and output the number of 6-inch square tiles needed to tile the Flowchart Pseudocode start input roomWidth input roomLength set roomArea = roomWidth * roomLength set tileSquareFeet = (6 / 12) * (6 / 12) set numOfTiles = roomArea / tileSquareFeet output numOfTiles stop (Please note that the student could also have the size of the tile in inches entered by t 8. a. Draw a flowchart or write pseudocode to represent the logic of a program that allows the user to enter values for the Flowchart Pseudocode start input wallWidth input wallLength set wallArea = wallWidth * wallLength output wallArea stop b. Modify the program that computes wall area to allow the user to enter the price of a gallon of paint. Assume that a gallo Flowchart Pseudocode start input wallWidth input wallLength input gallonPrice set wallArea = wallWidth * wallLength set numGallons = wallArea / 350 set cost = numGallons * gallonPrice output numGallons, cost stop c. Modify the program that computes paint cost to allow the user to enter the number of doorways that do not have to be p Flowchart Pseudocode start input wallWidth input wallLength input gallonPrice input numDoorways set wallArea = (wallWidth * wallLength) – (numDoorways * 14) set numGallons = wallArea / 350 set cost = numGallons * gallonPrice output numGallons, cost stop 9. Research current rates of monetary exchange. Draw a flowchart or write pseudocode to represent the logic of a program Flowchart Pseudocode start input numDollars set numEuros = numDollars * 0.77 set numYen = numDollars * 101.78 output numEuros, numYen stop (Please note that these exchange rates are valid as of the time of this writing) 10. Draw a flowchart or write pseudocode to represent the logic of a program that allows the user to enter values for a sale Flowchart Pseudocode start input baseSalary input totalSales input commissionRate set pay = baseSalary + totalSales * commissionRate output pay stop 11. A consignment shop accepts a product for sale and sets an initial price. Each month that the item doesn’t sell, the price Flowchart Pseudocode start input originalPrice set price = originalPrice set month = 1 while month <= 3 set ownerCut = price * 0.60 set shopCut = price * 0.40 output price, ownerCut, shopCut set price = price * 0.80 set month = month + 1 endwhile stop 12. A mobile phone app allows a user to press a button that starts a timer that counts seconds. When the user presses the b Answer: (Please note this solution assumes minutes is an integer and has been truncated.) Flowchart Pseudocode start input elapsedTime set minutes = elapsedTime / 60 set seconds = elapsedTime – (minutes * 60) output minutes, seconds stop Performing Maintenance 1. In this chapter you learned that some of the tasks assigned to new programmers frequently involve maintenance—mak // This program accepts a user's monthly pay // and rent, utilities, and grocery bills // and displays the amount available for discretionary spending // (which might be negative) // Modify the program to output the pay and the total bills // as well as the remaining discretionary amount start input pay input rent input utilities input groceries set bills = rent + utilities + groceries set discretionary = pay - bills output pay output bills output discretionary Find the Bugs 1. Your downloadable files for Chapter 1 include DEBUG01-01.txt, DEBUG01-02.txt, and DEBUG01-03.txt. Each file s slashes) that describe the program. Examine the pseudocode that follows the introductory comments, then find and correct all the bugs. DEBUG01-01 // This pseudocode is intended to describe // computing the price of an item on sale for 20% off start input origPrice set discount = origPrice * 0.20 // use origPrice instead of price set finalPrice = origPrice – discount // use discount instead of discnt output finalPrice DEBUG01-02 // This pseudocode is intended to describe computing // the number of miles per gallon you get with your automobile. start input milesTraveled input gallonsOfGasUsed set milesPerGallon = milesTraveled / gallonsOfGasUsed // milesPerGallon is computed using division output milesPerGallon // the P is milesPerGallon should be uppercase // Program should end with stop DEBUG01-03 // This pseudocode is intended to describe // computing the per day cost of your rent // in a 30-day month start input rent set costPerDay = rent / 30 // Comment indicates 30-day month output costPerDay // output should be costPerDay 2. Your downloadable files for Chapter 1 include a file named DEBUG01-04.jpeg that contains a flowchart that contains Game Zone 1. Create the logic for a Mad Lib program that accepts five words from input, then creates and displays a short story or n Students’ answers will vary. But a simple solution could be: start input input input input word1 word2 word3 word4 input word5 output “Jack and Jill went up the ”, word1, “ to fetch a pail of ”, word2, “. “Jack ”, word3, “ down and broke his ”, word4, “ and Jill came ”, word5, “ after.” stop Up for Discussion 1. Which is the better tool for learning programming—flowcharts or pseudocode? Cite any educational research you can Answers will vary. Many educators like the visual feedback flowcharts provide. This article contains research results: 2. What is the image of the computer programmer in popular culture? Is the image different in books than in TV shows a The programmer is often seen as an anti-social nerd with tape around his glasses, a pocket protector, and the inability to fo ment, _____. mmer plans the logic, often using a flowchart or pseudocode. Then, the program is coded in a language, such as Visual Basic or J ser to enter a value. The program divides the value by 2 and outputs the result. ser to enter a value for one edge of a cube. The program calculates the surface area of one side of the cube, the surface area of the ser to enter two values. The program outputs the product of the two values. user to enter values for the width and length of a room’s floor in feet. The program outputs the area of the floor in square feet. quare tiles needed to tile the floor. n inches entered by the user, rather than hard code the value 6; this was not specified in the user to enter values for the width and length of a wall in feet. The program outputs the area of the wall in square feet. f paint. Assume that a gallon of paint covers 350 square feet of a wall. The program outputs the number of gallons needed and th ays that do not have to be painted. Assume each doorway is 14 square feet. Output the number of gallons needed and the cost of resent the logic of a program that allows the user to enter a number of dollars and convert it to Euros and Japanese yen. his writing) ser to enter values for a salesperson’s base salary, total sales, and commission rate. The program computes and outputs the salesp e item doesn’t sell, the price is reduced by 20 percent. When the item sells, the item’s owner receives 60 percent of the sale price, When the user presses the button again, the timer stops. Draw a flowchart or write pseudocode that accepts the elapsed time in se involve maintenance—making changes to existing programs because of new requirements. A file named MAINTENANCE01-01 EBUG01-03.txt. Each file starts with some comments (lines that begin with two ns a flowchart that contains syntax and/or logical errors. Examine the flowchart and then find and correct all the bugs. d displays a short story or nursery rhyme that uses them. ucational research you can find. ntains research results: 51&part=Proceedings&WantType=Proceedings&title=ACM%20Annual%20Computer%20Science%20Conference n books than in TV shows and movies? Would you like that image for yourself? ector, and the inability to form social relationships. In some movies however, the computer-savvy programmer can save the day. e, such as Visual Basic or Java, and translated to machine language using a compiler or interpreter. Finally, the program is tested cube, the surface area of the cube, and its volume. The program outputs all the results. of the floor in square feet. not specified in the exercise) all in square feet. ber of gallons needed and the cost of the job. (For this exercise, assume that you do not need to account for windows or doors, an ons needed and the cost of the job. and Japanese yen. putes and outputs the salesperson’s pay by adding the base salary to the product of the total sales and commission rate. 60 percent of the sale price, and the shop gets 40 percent. Draw a flowchart or write pseudocode to represent the logic of a progra cepts the elapsed time in seconds and displays the value in minutes and remaining seconds. For example, if the elapsed time was med MAINTENANCE01-01.txt is included with your downloadable student files. Assume that this program is a working program rect all the bugs. grammer can save the day. High school aged programmers, in particular, are often portrayed as Robin Hood-type rebels. Movie p nally, the program is tested and then put into production and maintained over the ensuing months or years. nt for windows or doors, and that you can purchase partial gallons of paint.) commission rate. present the logic of a program that allows the user to enter an original product price. The output is the sale price, the owner’s cut, ple, if the elapsed time was 130 seconds, the output would be 2 minutes and 10 seconds. ogram is a working program in your organization and that it needs modifications as described in the comments (lines that begin w Hood-type rebels. Movie plots tend to concentrate on “good” programmers versus “evil” programmers. The programmer is virtu sale price, the owner’s cut, and the shop’s cut each month for the first three months the item is on sale. omments (lines that begin with two slashes) at the beginning of the file. Your job is to alter the program to meet the new specifica ers. The programmer is virtually always seen as smart. m to meet the new specifications. ming Logic and Design, 8th Edition Chapter 2 Review Questions 1 2 3 4 5 6 7 8 9 What does a declaration provide for a variable? a. a name b. a data type c. both of the above d. none of the above A variable’s data type describes all of the following except _____. a. what values the variable can hold b. how the variable is stored in memory c. what operations can be performed with the variable d. the scope of the variable The value stored in an uninitialized variable is _____. a. garbage b. null c. compost d. its identifier The value 3 is a _____. a. numeric variable b. numeric constant c. string variable d. string constant The assignment operator _____. a. is a binary operator b. has left-to-right associativity c. is most often represented by a colon d. two of the above Which of the following is true about arithmetic precedence? a. Multiplication has a higher precedence than division. b. Operators with the lowest precedence always have left-to-right associativity. c. Division has higher precedence than subtraction. d. all of the above Which of the following is a term used as a synonym for module in some programming languages? a. method b. procedure c. both of these d. none of these Which of the following is a reason to use modularization? a. Modularization avoids abstraction. b. Modularization reduces overhead. c. Modularization allows you to more easily reuse your work. d. Modularization eliminates the need for syntax. What is the name for the process of paying attention to important properties while ignoring nonessential details? a. abstraction b. extraction c. extinction d. 10 11 12 13 14 15 16 17 18 19 modularization Every module has all of the following except _____. a. a header b. local variables c. a body a return statement d. Programmers say that one module can _____ another, meaning that the first module causes the second module to exec a. declare b. define c. enact d. call The more that a module’s statements contribute to the same job, the greater the _____ of the module. a. structure b. modularity c. functional cohesion d. size In most modern programming languages, a variable or constant that is declared in a module is _____ in that module. a. global b. invisible c. in scope d. undefined Which of the following is not a typical housekeeping task? a. displaying instructions b. printing summaries c. opening files d. displaying report headings Which module in a ty...
View Full Document

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture