How Do Programmers Solve Problems

How Do Programmers Solve Problems
Dr.NaveenBansal Profile Pic
Dr.NaveenBansal,India,Teacher
Published Date:25-10-2017
Your Website URL(Optional)
Comment
12 CHAPTER 2 First You Need to Plan the Party (ProblemSolving Process) How Do Programmers Solve Problems? Figure2-1liststhestepsthatcomputerprogrammersfollowwhensolvingproblemsthatrequire a computer solution. 1. Analyze the problem 2. Plan the algorithm 3. Desk-check the algorithm 4. Create the user interface 5. Code the algorithm into a program 6. Desk-check the program 7. Rigorously test the program using the computer Figure 2-1 Steps for solving a problem using a computer This chapter covers the first three steps in the problem-solving process shown in Figure 2-1. The fourth step, which is to create the user interface, is covered in Chapters 3 and 4. The last three steps are explored in the remaining chapters. Step 1—Analyze the Problem You cannot solve a problem unless you understand it, and you cannot understand a problem unless you analyze it—in other words, unless you identify its important components. The two most important components of any problem are the problem’s output and its input. The output is the goal of solving the problem, and the input is the item or items needed to achieve the goal. When analyzing a problem, you always search first for the output and then for the input. The first problem specification analyzed in this chapter is shown in Figure 2-2. As a salesperson at J & J Sales, Addison Smith receives an annual commission, which is calculated by multiplying her annual sales by a commission rate. Addison wants a program that will both calculate and display the amount of her annual commission. Figure 2-2 Problem specification for Addison Smith A helpful way to identify the output is to search the problem specification for an answer to the following question: What does the user want to see printed on paper, displayed on the screen, or stored in a file? The answer to this question typically is stated as nouns and adjectives in the problemspecification.Forinstance,theproblemspecification showninFigure2-2indicatesthat Addison (the program’s user) wants to see the amount of her annual commission displayed on the screen; therefore, the output is the annual commission. In this context, the word annual is an adjective, and the word commission is a noun. After determining the output, you then determine the input. A helpful way to identify the input istosearchtheproblemspecificationforananswertothefollowingquestion: What information will the computer need to know to print, display, or store the output items? Like the output, the input typically is stated as nouns and adjectives in the problem specification. When determining the input, it helps to think about the information that you would need to solve the problem manually, because the computer will need to know the same information. In this case, to13 How Do Programmers Solve Problems? determine Addison’s annual commission, both you and the computer need to know her annual sales and the commission rate; both of these items, therefore, are the input. In this context, annual and commission are adjectives, and sales and rate are nouns. This completes the analysis step for the Addison Smith problem. Figure 2-3 summarizes the problem’s output and input items. Output: annual commission Input: annual sales commission rate Figure 2-3 Output and input items for the Addison Smith problem Now you will analyze the problem specification shown in Figure 2-4. Aiden Turner is paid every Friday. He is scheduled to receive a raise next week; however, he isn’t sure of the exact raise percentage. Aiden wants a program that will both calculate and display the amount of his new weekly pay. Figure 2-4 Problem specification for Aiden Turner First, answer the following question: What does the user want to see printed on paper, displayedonthescreen,orstoredinafile? In this case, Aiden wants to see his new weekly pay displayed on the screen; therefore, the output is the new weekly pay. In this context, the words new and weekly are adjectives, and the word pay is a noun. Now answer the following question: What information will the computer need to know to print, display, or store the output items? To determine Aiden’s new weekly pay, the computer needs to know Aiden’s current weekly pay and his raise percentage; both of these items, therefore, are the input. In this context, current, weekly,and raise are adjectives, and pay and percentage are nouns. You have completed the analysis step for the Aiden Turner problem. The problem’s output and input items are listed in Figure 2-5. Output: new weekly pay Input: current weekly pay raise percentage Figure 2-5 Output and input items for the Aiden Turner problem Unfortunately, analyzing real-world problems is not always as easy as analyzing the problems found in a textbook. The analysis step is the most difficult of the problem-solving steps, and it requires a lot of time, patience, and effort. If you are having trouble analyzing a problem, try reading the problem specification several times, as it is easy to miss information during the first reading. If the problem still is unclear to you, do not be shy about asking the user for more information. Remember, the more you understand a problem, the easier it will be for you to write a correct and efficient solution to the problem.14 CHAPTER 2 First You Need to Plan the Party (ProblemSolving Process) Mini-Quiz 2-1 See Appendix B for the answers. 1. Treyson Liverpool pays a state income tax on his yearly taxable wages. He wants a program that allows him to enter the amount of his yearly taxable wages. The program then should calculate and display the amount of his state income tax. Identify the output and the input. For more 2. Max Jones belongs to a CD (compact disc) club that allows him to buy CDs at a much examples of analyzing lower price than charged at his local music store. He wants to know how much he problems, saves by buying all of his CDs through the club rather than through the music store. see the Identify the output and the input. Analyzing Problems 3. Suman Patel saves the same amount of money each day. She wants to know the total section in the Ch2WantMore.pdf file. amount she saves during a specific month. Identify the output and the input. Step 2—Plan the Algorithm The second step in the problem-solving processistoplanthealgorithm,whichisthesetof instructions that, when followed, will transform the problem’s input into its output. Most algorithms begin with an instruction that enters the input items into the computer. Next, you usually record instructions to process the input items to achieve the problem’soutput. The processing typically involves performing one or more calculations on the input items. Most algorithms end with an instruction to print, display, or store the output items. Display, print,and store refer to the computer screen, the printer, and a file on a disk, respectively. Figure 2-6 shows the output, input, and algorithm for the Addison Smith problem. The algorithm begins by entering the input items. It then uses the input items to calculate the output item. Notice that the algorithm states both what is to be calculated and how to calculate it. In this case, the annual commission is to be calculated by multiplying the annual sales by the commission rate. The last instruction in the algorithm displays the output item. To avoid confusion, it is important that the algorithm is consistent when referring to the input and output items. For example, if the input item is listed as annual sales, then the algorithm should refer to the item as annual sales, rather than using a different name, such as sales or yearly sales. Output: annual commission Input: annual sales commission rate Algorithm: 1. enter the annual sales and commission rate 2. calculate the annual commission by multiplying the annual sales by the commission rate 3. display the annual commission Figure 2-6 Output, input, and algorithm for the Addison Smith problem15 How Do Programmers Solve Problems? The algorithm in Figure 2-6 is composed of short phrases, referred to as pseudocode. The word pseudocode means false code.It’s called false code because, although it resembles programming language instructions, pseudocode cannot be understood by a computer. Programmers use pseudocode to help them while they are planning an algorithm. It allows them to jot down their ideas using a human-readable language without having to worry about the syntax of the programming language itself. Pseudocode is not standardized; every programmer has his or her own version, but you will find some similarities among the various versions. Programmers use the pseudocode as a guide when coding the algorithm, which is the fifth step in the problem-solving process. Besidesusingpseudocode,programmersalsouseflowchartswhenplanningalgorithms.Unlike pseudocode, a flowchart uses standardized symbols to visually depict an algorithm. You can draw the flowchart symbols by hand; or, you can use the drawing or shapes feature in a word processor. You also can use a flowcharting program, such as SmartDraw or Visio. Figure 2-7 shows the Addison Smith problem’s algorithm in flowchart form. The flowchart contains three different symbols: an oval, a parallelogram, and a rectangle. The symbols are connected with lines, called flowlines. The oval symbol is called the start/stop symbol.Thestartoval indicates the beginning of the flowchart, and the stop oval indicates the end of the flowchart. Between the start and stop ovals are two parallelograms, called input/output symbols. You use the input/output symbol to represent input tasks (such as getting information from the user) and output tasks (such as displaying, printing, or storing information). The first parallelogram in Figure 2-7 represents an input task, while the last parallelogram represents an output task. The rectangle in a flowchart is called the process symbolandisusedto represent tasks such as calculations. Output: annual commission Input: annual sales commission rate Algorithm: start enter annual sales and commission rate annual commission = annual sales times commission rate display annual commission stop Figure 2-7 Flowchart for the Addison Smith problem’s algorithm When planning an algorithm, you do not need to create both a flowchart and pseudocode; you need to use only one of these planning tools. The tool you use is really a matter of personal preference. For simple algorithms, pseudocode works just fine. When an algorithm becomes16 CHAPTER 2 First You Need to Plan the Party (ProblemSolving Process) more complex, however, the program’s logic may be easier to see in a flowchart. As the old adage goes, a picture is sometimes worth a thousand words. Figure 2-8 shows the output, input, and algorithm for the Aiden Turner problem. Here too, the algorithm begins by entering the input items. It then uses both input items to calculate the output item. Again, notice that the calculation instructions state both what is to be calculated and how to calculate it. The last instruction in the algorithm displays the output item. Output: new weekly pay Input: current weekly pay raise percentage Algorithm: 1. enter the current weekly pay and raise percentage 2. calculate the new weekly pay by multiplying the current weekly pay by the raise percentage, and then adding the result to the current weekly pay 3. display the new weekly pay Figure 2-8 Output, input, and algorithm for the Aiden Turner problem Even a very simple problem can have more than one solution. For example, Figure 2-9 shows a different solution totheAidenTurner problem. In this solution,the weekly raiseis calculatedin a separate instruction rather than in the instruction that calculates the new weekly pay. The weekly raiseisneitheraninputitem(becauseit’snotprovidedbytheuser)noranoutputitem(becauseit won’tbedisplayed,printed,orstoredinafile).Instead,theweeklyraiseisaspecialitem,commonly referred to as a processing item. A processingitem represents an intermediate value that the algorithmuses whenprocessingtheinput intothe output. In this case,the algorithmusesthetwo inputitems tocalculatetheweeklyraise(anintermediatevalue),whichthealgorithmthen usesto compute the new weekly pay. Keep in mind that not all algorithms require a processing item. Output: new weekly pay Processing: weekly raise Input: current weekly pay raise percentage Algorithm: 1. enter the current weekly pay and raise percentage 2. calculate the weekly raise by multiplying the current weekly pay by the raise percentage 3. calculate the new weekly pay by adding the weekly raise to the current weekly pay 4. display the new weekly pay Figure 2-9 A different solution to the Aiden Turner problem The solutions shown in Figures 2-8 and 2-9 produce the same result and simply represent two different ways of solving the same problem. Figure 2-10 shows Figure 2-9’s algorithm in flowchart form.17 How Do Programmers Solve Problems? Output: new weekly pay Processing: weekly raise Input: current weekly pay raise percentage Algorithm: start enter current weekly pay and raise percentage calculate weekly raise = current weekly pay times raise percentage calculate new weekly pay = weekly raise + current weekly pay display new weekly pay stop Figure 2-10 Flowchart for the algorithm shown in Figure 2-9 Mini-Quiz 2-2 See Appendix B for the answers. 1. Treyson Liverpool pays a state income tax on his yearly taxable wages. He wants a program that both calculates and displays the amount of state income tax he must pay. The output is the annual state income tax. The input is the yearly taxable wages and the state income tax rate. Write the algorithm using pseudocode. 2. Rewrite Question 1’s algorithm using a flowchart. For more 3. Max Jones belongs to a CD (compact disc) club that allows him to buy CDs at a much examples lower price than charged at his local music store. He wants to know how much he of planning saves by buying all of his CDs through the club rather than through the music store. algorithms, The output is the savings. The input is the number of CDs purchased, the club CD see the price, and the store CD price. The algorithm should use two processing items: one for Planning Algorithms the cost of buying the CDs through the club, and the other for the cost of buying the section in the CDs through the store. Write the algorithm using pseudocode. Ch2WantMore.pdf file.18 CHAPTER 2 First You Need to Plan the Party (ProblemSolving Process) Step 3—Desk-Check the Algorithm After analyzing a problem and planning its algorithm, you then desk-check the algorithm. The term desk-checking refers to the fact that the programmer reviews the algorithm while seated at his or her desk rather than in front of the computer. Desk-checking is also called hand-tracing, because the programmer uses a pencil and paper to follow each of the algorithm’s instructions by hand. You desk-check an algorithm to verify that it is not missing any steps, and that the existing steps are correct and in the proper order. Before you begin the desk-check, you first choose a set of sample data for the input values, which you then use to manually compute the expected output values. For the Addison Smith solution, you will use input values of 85000 and .08 (8%) as Addison’s annual sales and commission rate, respectively. Addison’s annual commission should be 6800 (85000 times .08); therefore, 6800 is the expected output value. You now use the sample input values to desk-check the algorithm, which should result in the expected output value. It is helpful to use a desk-check table when desk-checking an algorithm. The table should contain one column for each input item, as well as one column for each output item and one column for each processing item (if any). You can perform the desk-check using either the algorithm’s pseudocode or its flowchart. Figure 2-11 shows the Addison Smith solution along with an appropriate desk-check table. (The flowchart for this solution is shown earlier in Figure 2-7.) Output: annual commission Input: annual sales commission rate Algorithm: 1. enter the annual sales and commission rate 2. calculate the annual commission by multiplying the annual sales by the commission rate 3. display the annual commission Desk check table: Figure 2-11 Addison Smith solution and desk-check table The first instruction in the algorithm is to enter the input values: 85000 for the annual sales and .08 for the commission rate. You record the results of this instruction by writing 85000 and .08 in the annual sales and commission rate columns, respectively, in the desk-check table, as shown in Figure 2-12. 85000 .08 Figure 2-12 Input values entered in the desk-check table www.allitebooks.com 19 How Do Programmers Solve Problems? The second instruction in the algorithm is to calculate the annual commission by multiplying the annual sales by the commission rate. The desk-check table shows that the annual sales are 85000 and the commission rate is .08. Notice that you use the table to determine the annual sales and commission rate values; this helps to verify the accuracy of the algorithm. If, for example, the table did not show any amount in the commission rate column, you would know that your algorithm missed a step; in this case, it would have missed entering the commission rate. When you multiply the annual sales (85000) by the commission rate (.08), you get 6800. You record the number 6800 in the annual commission column, as shown in Figure 2-13. 85000 .08 6800 Figure 2-13 Output value entered in the desk-check table The last instruction in the algorithm is to display the annual commission. In this case, the number 6800 will be displayed because that is what appears in the annual commission column. Notice that this amount agrees with the manual calculation you performed prior to desk- checking the algorithm, so the algorithm appears to be correct. The only way to know for sure, however, is to test the algorithm a few more times with different input values. For the second desk-check, you will test the algorithm with annual sales of 3000 and a commission rate of .1 (10%). The annual commission should be 300. Recall that the first instruction in the algorithm is to enter the annual sales and commission rate. Therefore, you write 3000 in the annual sales column and .1 in the commission rate column, as shown in Figure 2-14. Notice that you cross out the previous values of these two items in the table before recording the new values; this is because each column should contain only one value at any time. 85000 .08 6800 3000 .1 Figure 2-14 Second set of input values included in the desk-check table Next,youneedtocalculatetheannualcommissionbymultiplyingtheannualsales(3000)bythe commissionrate(.1);thisresultsinanannualcommissionof300.Soyoucrossoutthe6800that appears in the annual commission column in the desk-check table and write 300 immediately below it, as shown in Figure 2-15. The last instruction in the algorithm is to display the annual commission. In this case, the number 300 will be displayed, which agrees with the manual calculation you performed earlier. 85000 .08 6800 3000 .1 300 Figure 2-15 Results of the second desk-check included in the desk-check table Next, youwilldesk-checkthe AidenTurneralgorithmtwice,firstusing400 and.03 (3%)asthe current weekly pay and raise percentage, respectively, and then using 600 and .15 (15%). The20 CHAPTER 2 First You Need to Plan the Party (ProblemSolving Process) new weekly pay for the first desk-check should be 412. The new weekly pay for the second desk-check should be 690. The Aiden Turner solution and completed desk-check table are shown in Figure 2-16. (The pseudocode is shown earlier in Figure 2-9.) Output: new weekly pay Processing: weekly raise Input: current weekly pay raise percentage Algorithm: start enter current weekly pay and raise percentage calculate weekly raise = current weekly pay times raise percentage calculate new weekly pay = weekly raise + current weekly pay display new weekly pay stop 400 .03 12 412 600 .15 90 690 Figure 2-16 Aiden Turner solution and desk-check table The amounts in the table agree with the manual calculations you performed earlier, so the algorithm appears to be correct. To be sure, however, you should desk-check it several more times, using both valid and invalid data. Valid data is data that the algorithm is expecting the user to enter. The Aiden Turner algorithm, for example, expects the user to provide positive numbers for the input values (current weekly pay and raise percentage). Invaliddata is data that the algorithm is not expecting the user to enter. You should test an algorithm with invalid data because users sometimes make mistakes when entering data. The Aiden Turner algorithm, for instance,isnotexpectingtheusertoenteranegativevalueasthecurrentweeklypay.Anegative weekly pay is obviously an input error, because an employee cannot earn a negative amount for the week. In later chapters in this book, you will learn how to write algorithms that correctly handle input errors. You also will learn more about selecting good test data. For now, however, you can assume that the user of the program will always enter valid data.21 Summary Mini-Quiz 2-3 See Appendix B for the answers. 1. Desk-check the following algorithm twice. First, use a yearly taxable wage of 23000 anda3%stateincometaxrate.Thenuseayearlytaxablewageof14000anda2%state income tax. Algorithm: 1. enter the yearly taxable wages and state income tax rate 2. calculate the annual state income tax by multiplying the yearly taxable wages by the state income tax rate 3. display the annual state income tax For more examples 2. Desk-check the following algorithm twice. First, use 20, 10.50, and 14.99 as the of desk- number of CDs purchased, the club CD price, and the store CD price, respectively. checking Then use 5, 9.99, and 11. algorithms, see the Desk-Checking Algorithm: Algorithms section in the 1. enter the number of CDs purchased, the club CD price, and the store CD price Ch2WantMore.pdf file. 2. calculatetheclubcostbymultiplyingthenumberofCDspurchasedbytheclubCDprice It’stimeto 3. calculate the store cost by multiplying the number of CDs purchased by the store CD view the price Ch2-Planning 4. calculate the savings by subtracting the club cost from the store cost Algorithms video. 5. display the savings Summary l The first three steps in the problem-solving process are to analyze the problem, plan the algorithm, and desk-check the algorithm. l When analyzing a problem description, the programmer first determines the output, which is the goal or purpose of solving the problem. The programmer then determines the input, which is the information needed to reach the goal. Some algorithms use intermediate values, called processing items. l Programmers use tools, such as pseudocode and flowcharts, to organize their thoughts as they analyze problems and develop algorithms. These tools are used when coding the algorithm into a program, which is the fifth step in the problem-solving process. l Most algorithms begin by entering data (the input items), followed by processing the data (usually by performing some calculations), followed by displaying, printing, or storing data (the output items). l The calculation instructions in an algorithm should specify both what is to be calculated and how to perform the calculation. l After completing the analysis and planning steps, a programmer then desk-checks the algorithm to determine whether it works as intended.22 CHAPTER 2 First You Need to Plan the Party (ProblemSolving Process) Key Terms Desk-checking—theprocessofmanuallywalkingthrougheachofthestepsinanalgorithm;also called hand-tracing Flowchart—a tool that programmers use when planning an algorithm; consists of standardized symbols Flowlines—the lines connecting the symbols in a flowchart Hand-tracing—another term for desk-checking Input—the items an algorithm needs to achieve the output Input/outputsymbol—theparallelograminaflowchart;usedtorepresentinputandoutputtasks Invalid data—data that an algorithm is not expecting the user to enter Output—the goal or purpose of solving a problem Process symbol—the rectangle in a flowchart; used to represent tasks such as calculations Processing item—an intermediate value that an algorithm uses when transforming the input into the output Pseudocode—a tool that programmers use when planning an algorithm; consists of short phrases Start/stop symbol—the oval in a flowchart; used to mark the beginning and end of the flowchart Valid data—data that an algorithm is expecting the user to enter Review Questions ___________ 1. Programmers refer to the items needed to reach a problem’s goal as the . a. input c. processing b. output d. purpose ___________ 2. The calculation instructions in an algorithm should state . a. only what is to be calculated b. only how to calculate something c. both what is to be calculated and how to calculate it d. both what is to be calculated and why it is calculated ___________ 3. Most algorithms follow the format of . a. entering the input items; then displaying, printing, or storing the output items; and then processing the output items b. entering the input items; then processing the output items; and then displaying, printing, or storing the output items c. entering the input items; then processing the input items; and then displaying, printing, or storing the output items d. entering the output items; then processing the input items; and then displaying, printing, or storing the output items23 Exercises ___________ 4. In a flowchart, the symbol is used to represent an instruction that gets information from the user. a. enter c. process b. input/output d. start/stop ___________ 5. When desk-checking an algorithm, you should set up a table that contains . a. one column for each input item and one column for each output item b. one column for each input item and one column for each processing item c. one column for each processing item and one column for each output item d. one column for each input item, one column for each processing item, and one column for each output item ___________ 6. The instruction sales tax sales times tax rate would appear in a(n) in a flowchart. a. oval c. rectangle b. parallelogram d. square 7. What is the purpose of a processing item in an algorithm? Exercises 1. Jerry Feingold wants a program that will help him calculate the amount to tip a waiter at TRY THIS a restaurant. The program should subtract any liquor charge from the total bill and then calculate the tip (using a percentage) on the remainder. Finally, the program should display the tip on the screen. Desk-check your solution’s algorithm using 85 as the total bill,20astheliquorcharge,and20%asthetippercentage.Thendesk-checkitusing35 as the total bill, 0 as the liquor charge, and 15% as the tip percentage. (See Appendix B for the answer.) TRY THIS 2. Party-On sells individual hot/cold cups and dessert plates for parties. Sue Chen wants a programthatallowshertoenterthepriceofacup,thepriceofaplate,thenumberofcups purchased, and the number of plates purchased. The program should then calculate the total cost of the purchase, including the sales tax. Finally, the program should display the totalcostonthescreen.Desk-checkyoursolution’salgorithmusing.50asthecupprice,1 as the plate price, 35 as the number of cups, 35 as the number of plates, and 2% as the tax rate. Then desk-check it using .25, .75, 20, 10, and 6%. (See Appendix B for the answer.) 3. Modify the answer to Exercise 1 as follows. Jerry will be charging the total bill, including MODIFY THIS the tip, to his credit card. Modify the solution so that, in addition to calculating and displaying the appropriate tip, it also calculates and displays the amount charged to Jerry’s credit card. Desk-check the algorithm using 50 as the total bill, 5 as the liquor charge,and20%asthetippercentage.Thendesk-checkitusing15asthetotalbill,0as the liquor charge, and 15% as the tip percentage. INTRODUCTORY 4. Wilma Peterson is paid by the hour. She would like a program that both calculates and displays her weekly gross pay. For this exercise, you do not need to worry about overtime pay, as Wilma never works more than 40 hours in a week. Desk-check your solution’s algorithmusing10asthehourlypayand35asthenumberofhoursworked.Thendesk- check it using 15 as the hourly pay and 25 as the number of hours worked. 5. When Jacob Steinberg began his trip from California to Vermont, he filled his car’s tank INTRODUCTORY with gas and reset its trip meter to zero. After traveling 324 miles, Jacob stopped at a gas station to refuel; the gas tank required 17 gallons. Jacob wants a program that calculates his car’s gas mileage at any time during the trip. The gas mileage is the number of miles24 CHAPTER 2 First You Need to Plan the Party (ProblemSolving Process) his car can be driven per gallon of gas. The program should display the gas mileage on thescreen.Desk-checkyoursolution’salgorithmusing324asthenumberofmilesdriven and 17 as the number of gallons used. Then desk-check it using 280 and 15. INTERMEDIATE 6. JennaWilliamsispaid based on anannual salaryrather than anhourly wage. Shewants a program that both calculates and displays the amount of money she should receive each pay period. Desk-check your solution’s algorithm twice, using your own set of data. INTERMEDIATE 7. Rent A Van wants a program that calculates the total cost of renting a van. Customers pay a base fee plus a charge per mile. Currently, the base fee and charge per mile are 50 and .20, respectively; however, the program should allow the user to enter both items. The program should display the total cost on the screen. Desk-check your solution’s algorithm twice, using your own set of data. 8. To celebrate her birthday, Sydney Pomeroy is taking a group of friends (adults and INTERMEDIATE children)toamovie.Iftheyattendthematineeshowing,thepriceforadultsandchildren is 7; otherwise, it is 12 for adults and 7 for children. Sydney wants a program that calculates how much less it would cost to take her friends to the matinee showing. Desk- check your solution’s algorithm twice, using your own set of data. 9. The manager of Mama Calari’s Pizza Palace wants a program that both calculates and INTERMEDIATE displays the number of pizza slices into which a circular pizza can be divided. The managerwillentertheradiusoftheentirepizza.Forthisexercise,use14.13astheareaof a pizza slice, and use 3.14 as the value of pi. Desk-check your solution’s algorithm twice. For the first desk-check, use 10 as the pizza’s radius; use 8 for the second desk-check. (Hint: For the first desk-check, the number of pizza slices should be a little over 22.) ADVANCED 10. The River Bend Hotel needs a program that both calculates and displays a customer’s total bill. Each customer pays a room charge that is based on a per-night rate. For example, if the per-night rate is 55 and the customer stays two nights, the room charge is 110. Customers also may incur room service charges and telephone charges. In addition, each customer pays an entertainment tax, which is a percentage of the room charge only. Desk-check your solution’s algorithm twice, using your own set of data. ADVANCED 11. The Paper Tree store wants a program that both calculates and displays the number of single rolls of wallpaper needed to cover a room. The salesclerk will provide the room’s length, width, andceilingheight,in feet. Heorshealso willprovidethe numberofsquare feet a single roll will cover. Desk-check your solution’s algorithm twice, using your own set of data. 12. The manager of a video store wants a program that calculates the amount a customer FIGURE THIS OUT owes when he or she returns a video. A customer can return only one video at a time. The rental fee is 3.50 for four days. Customers are charged a late fee (currently, 2) per day when the video is returned after the due date. Study the algorithm and desk-check table shown in Figure 2-17, and then answer the questions. a. What will the algorithm display when the user enters 3 as the number of late days? What will it display when the user enters 0 as the number of late days? b. How would you modify the solution and desk-check table to include the total late charge as a processing item? c. How would you modify the solution from Question b to also display the total late charge?25 Exercises Output: amount due Input: number of late days daily late fee Algorithm: 1. enter the number of late days and daily late fee 2. calculate the amount due by multiplying the number of late days by the daily late fee, and then adding 3.50 to the result 3. display the amount due Desk-check table: 3 2 9.50 0 2 3.50 Figure 2-17 Algorithm and desk-check table for Exercise 12 13. Correct the algorithm shown in Figure 2-18. The algorithm should calculate the SWAT THE BUGS average of three numbers. Output: average Processing: sum Input: first number second number third number Algorithm: 1. enter the first number, second number, and third number 2. calculate the average by dividing the sum by 3 3. display the average number Figure 2-18 Algorithm for Exercise 13This page intentionally left blank

Advise: Why You Wasting Money in Costly SEO Tools, Use World's Best Free SEO Tool Ubersuggest.