A programmer notices that the following code snippet uses the same algorithm for computing cost after taxes, but with different variables, in the two places as shown below, and in several other places in the program. What could be done to improve the program? final double TAXRATE1 = final double TAXRATE2 = 5.5; double subtotal = price (1 + TAXRATE1) / 100; 10; double total = subtotal + shipping * (1 + TAXRATE2) / 100; Declare the tax rates as variables, not constants. Define a method that looks up tax rates for goods and shipping charges. Define a method that computes the cost after taxes from arguments for the cost before taxes and the tax rate. Define a method that prompts the user for an amount and a tax rate, then returns the total amount including the tax.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 20PE
icon
Related questions
Question
A programmer notices that the following code snippet uses the same algorithm for
computing cost after taxes, but with different variables, in the two places as shown
below, and in several other places in the program. What could be done to improve
the program?
final double TAXRATE1 =
final double TAXRATE2 = 5.5;
double subtotal = price (1 + TAXRATE1) / 100;
10;
double total
= subtotal + shipping *
(1 + TAXRATE2) / 100;
Declare the tax rates as variables, not constants.
Define a method that looks up tax rates for goods and shipping charges.
Define a method that computes the cost after taxes from arguments for the cost
before taxes and the tax rate.
Define a method that prompts the user for an amount and a tax rate, then
returns the total amount including the tax.
Transcribed Image Text:A programmer notices that the following code snippet uses the same algorithm for computing cost after taxes, but with different variables, in the two places as shown below, and in several other places in the program. What could be done to improve the program? final double TAXRATE1 = final double TAXRATE2 = 5.5; double subtotal = price (1 + TAXRATE1) / 100; 10; double total = subtotal + shipping * (1 + TAXRATE2) / 100; Declare the tax rates as variables, not constants. Define a method that looks up tax rates for goods and shipping charges. Define a method that computes the cost after taxes from arguments for the cost before taxes and the tax rate. Define a method that prompts the user for an amount and a tax rate, then returns the total amount including the tax.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr