## Norbert Catering is famous for its roast beef sandwiches. The

Norbert Catering is famous for its roast beef sandwiches. The store’s owner wants a program that he can use to estimate the number of pounds of roast beef a customer should purchase, given the desired number of sandwiches and the amount of meat per sandwich. Typically, one sandwich requires two to three ounces of meat, but some customers prefer four or five ounces per sandwich. Complete an IPO chart for this problem. Desk-check the algorithm using 50 as the number of sandwiches and 4 ounces as the amount of meat per sandwich. Then desk-check it using 224 and 2 ounces.

## You have just purchased a new personal computer system. Before

You have just purchased a new personal computer system. Before putting the system components together, you read the instruction booklet that came with the system. The booklet contains a list of the components that you should have received. The booklet advises you to verify that you received all of the components by matching those that you received with those on the list. If a component was received, you should cross its name off the list; otherwise, you should draw a circle around the component name in the list. Using only the instructions listed in Figure 1-11, create an algorithm that shows the steps you should take to verify that you received the correct components. Be sure to indent the instructions appropriately.

## Juan wants a program that calculates and displays the number

Juan wants a program that calculates and displays the number of miles per gallon he drove his car on a recent trip. When he started the trip, the car’s gas tank was full and its odometer read 5500. Before reaching his final destination, Juan stopped at two different gas stations to purchase gas. At the first stop, he purchased 15.5 gallons of gas; at that time, the odometer read 5860. At the second stop, he purchased 18.7 gallons of gas; at that time, the odometer read 6280. First, create an IPO chart for this problem. Although specific values are provided for the odometer readings and gallons of gas, do not use named constants for those values. After creating the IPO chart, desk-check the algorithm twice. For the first desk-check, use the values provided in this exercise. For the second desk-check, use your own set of data. After desk-checking the algorithm, list the input, processing, and output items in a chart similar to the one shown in Figure 3-25, and then enter the appropriate C++ declaration statements.

## Aaron Lakely is going to the grocery store to buy

Aaron Lakely is going to the grocery store to buy some bananas and apples, both of which are sold by the pound. He wants a program that calculates and displays the total cost of his order, including a 3% sales tax. First, create an IPO chart for this problem, and then desk-check the algorithm twice. For the first desk-check, use 2 and 3.5 as the number of pounds of bananas and apples, respectively. And use \$0.99 and \$1.89 as the price per pound of bananas and apples, respectively. For the second desk-check, use your own set of data. After desk-checking the algorithm, list the input, processing, and output items in a chart similar to the one shown in Figure 3-25, and then enter the appropriate C++ declaration statements.

## The payroll clerk at Nosaki Company wants a program that

The payroll clerk at Nosaki Company wants a program that calculates and displays an employee’s gross pay, federal withholding tax (FWT), Social Security and Medicare (FICA) tax, state tax, and net pay. The clerk will enter the hours worked (which is never over 40), hourly pay rate, FWT rate, FICA tax rate, and state income tax rate. Complete an IPO chart for this problem. Desk-check the algorithm using 30, \$10, .2, .08, and .04 as the hours worked, pay rate, FWT rate, FICA rate, and state tax rate, respectively. Then desk-check it using your own set of data.

## Archie wants a program that calculates and displays a team’s

Archie wants a program that calculates and displays a team’s final score in a football game, given the numbers of the team’s field goals, touchdowns, one-point conversions, two-point conversions, and safeties. First, create an IPO chart for this problem, and then desk-check the algorithm twice. For the first desk-check, use 3, 2, 2, 0, and 1 as the numbers of field goals, touchdowns, one-point conversions, two-point conversions, and safeties. For the second desk-check, use your own set of data. After desk-checking the algorithm, list the input, processing, and output items in a chart similar to the one shown in Figure 3-25, and then enter the appropriate C++ declaration statements.

## Gabrielle receives 52 paychecks each year. She always deposits a

Gabrielle receives 52 paychecks each year. She always deposits a specific percentage of her gross pay into her savings account. She also receives a bonus check, which is always more than \$250, at the end of the year. She always deposits \$150 of her bonus into her savings account. Gabrielle wants a program that calculates and displays the total amount she deposited during the year. Complete an IPO chart for this problem. Desk-check the algorithm twice, using your own sets of data. After desk-checking the algorithm, list the input, processing, and output items in a chart similar to the one shown in Figure 3-25, and then enter the appropriate C++ declaration statements.

## Cranston Berries sells three types of berries: strawberries, blueberries, and

Cranston Berries sells three types of berries: strawberries, blueberries, and raspberries. Sales have been booming this year and are expected to increase next year. The sales manager wants a program that allows him to enter the projected increase (expressed as a decimal number) in berry sales for the following year. He will also enter the current year’s sales for each type of berry. The program should display the projected sales for each berry type. Complete an IPO chart for this problem. Desk-check the algorithm twice, using your own sets of data. After desk-checking the algorithm, list the input, processing, and output items in a chart similar to the one shown in Figure 3-25, and then enter the appropriate C++ declaration statements.

## As you learned in the chapter, you must be careful

As you learned in the chapter, you must be careful when comparing two real numbers for either equality or inequality because some real numbers cannot be stored precisely in memory. To determine whether two real numbers are either equal or unequal, you should test that the difference between both numbers is less than some acceptable small value, such as 0.00001.

a. Start your C++ development tool, and view the Advanced16.cpp file. The file is contained in either the Cpp8Chap05Advanced16 Project folder or the Cpp8Chap05 folder. (Depending on your C++ development tool, you may need to open this exercise’s solution/project file first.) The code divides the contents of the num1 variable (10.0) by the contents of the num2 variable (3.0), storing the result (approximately 3.33333) in the quotient variable. An if statement is used to compare the contents of the quotient variable with the number 3.33333. The if statement displays a message that indicates whether the numbers are equal.

b. Run the program. Even though the message on the screen states that the quotient is 3.33333, the message indicates that this value is not equal to 3.33333. Close the Command Prompt window.

c. If you need to compare two real numbers for equality or inequality, first find the difference between both numbers, and then compare the absolute value of that difference to a small number, such as 0.00001. The absolute value of a number is a positive number that represents the distance the number is from 0 on the number line. For example, the absolute value of the number 5 is 5, and so is the absolute value of the number –5; both numbers are an equal distance from 0 on the number line. You can use the C++ fabs function to find the absolute value of a real number; however, your program must contain the #include  directive. Modify the program appropriately. Save and then run the program. This time, the message “Yes, the quotient 3.33333 is equal to 3.33333.” appears.