Siddique, In Class Assignment 1 Revised

docx

School

SUNY Buffalo State College *

*We aren’t endorsed by this school

Course

151

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

2

Uploaded by LieutenantUniverseElephant42

Report
CIS 251 - In Class Assignment 1 Download and copy the following program , INCLASS01.cpp , from Brightspace: /* This program computes the amount of tax on two items and the total cost including tax of the two items given the cost of the items and the tax rate. Written by: Sadid Siddique Date: February 1, 2023 */ #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; double compute_tax (double item1_cost, double item2_cost, double tax_rate); int main( ) { double item1_cost; // cost of the first item entered by the user double item2_cost; // cost of the second item entered by the user double tax_rate; // percent tax rate double tax; // tax on the given item double total_cost; // cost of item plus tax cout << "Enter the cost of item 1: $"; cin >> item1_cost; cout << "Enter the cost of item 2: $"; cin >> item2_cost; cout << "Enter the tax rate (percent): "; cin >> tax_rate; // call to your function here total_cost = item1_cost + item2_cost + tax; cout << showpoint << fixed << setprecision (2); cout << "\nThe tax on your items is: $" << tax; cout << "\nThe total cost of the items is: $" << total_cost << "\n\n"; return 0; } // define the compute_tax function definition here // compute_tax returns the tax on the sum of the items given the cost of // the two items and the tax rate as parameters. Continue on Back Continue on Back
1. Write a call to the function compute_tax in the main program where indicated (refer to the prototype for the proper return value and parameters). The return value should be placed in the variable tax . 2. Write the compute_tax function definition where indicated. Your program should compile and run when done. 3. Change the name of the variable item1_cost to the_cost in all places in main (only!). Run your program. What does this tell you about the names of parameters that are being passed? It tells me that the name of parameters in a function call do not matter as long as the name change remains consistent throughout the program. Change the name back to item1_cost in all places in main. 4. Switch the order of the parameters item2_cost and tax_rate in the function call . Run your program. What does this tell you about the order of parameters in a function call? It tells me that the order of parameters in a function call do affect the program. After the order of the parameters item2_cost and tax_rate in the function call they showed wrong results. 5. Does C++ pay attention to the names or the order of parameters? C++ only pays attention on the order of parameters. Change the order of parameters in the call back to the way it was. 6. Hopefully, you assigned the variable tax to the function call in main : tax = compute_tax ( … Remove “ tax =” from the call in main. Compile and run your program. What does this tell you about communication of answers back from a value returning function? This tells me that if the value returning function is not properly called to it won't do its job and the tax will not added with the total cost and the returning value needs to be saved to calculate the total cost of items.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help