67.4k views
4 votes
c++ Write a function declaration/prototype for a function named addTax. The function has 2 formal parameters: taxRate (which is the amount of sales tax expressed as a percentage, and cost (which is the cost of an item before tax). The function should change the value of cost so that it includes sales tax. )

User WINSergey
by
8.4k points

1 Answer

2 votes

Final answer:

The C++ function prototype for adding sales tax to an item's cost is void addTax(double& taxRate, double& cost);. The function uses pass-by-reference to modify the cost variable.

Step-by-step explanation:

The student is asking for help with writing a C++ function declaration. The function, named addTax, should include two parameters: taxRate and cost. The taxRate is the amount of sales tax expressed as a percentage, and cost is the cost of an item before tax. The function should modify the cost by adding the sales tax to it.

To declare this function in C++, you would write it as follows:

void addTax(double& taxRate, double& cost);

In this function prototype, taxRate and cost are passed by reference, which allows the function to modify the value of cost directly. When implementing this function, you would calculate the amount of sales tax by converting the tax rate percentage to a decimal and multiplying it by the cost. You then add this tax amount to the original cost to get the total cost including tax, as shown in the examples:

For a $150.00 item with a 10% sales tax:

$150.00 × 0.10 = $15.00

For a $65.00 item with a 5% sales tax:

$65.00 × 0.05 = $3.25

User Jadengeller
by
8.8k points