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 = 10; final double TAXRATE2 = 5.5; double subtotal = price * (1 + TAXRATE1) / 100; 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.
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 = 10; final double TAXRATE2 = 5.5; double subtotal = price * (1 + TAXRATE1) / 100; 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
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 14PE
Related questions
Question
ASAP pls
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning