Part 3. Write a function called totalCost that takes three parameters (shipping cost, cost of one box, and number of boxes purchased) and returns the total cost which is computed using the following formula: shipping cost + (number of boxes purchased) * (cost of one box). Default values for the parameters are the following: shipping cost is 0, cost of one box is $4, number of boxes is 1. In the main function test your totalCost function with no arguments, 1 argument, 2 arguments, and 3 arguments. Make sure that your output clearly states the number of arguments that is being tested, the values of the arguments, and the total cost value that is returned. Call your program part3.cpp Use program fig15_08.cpp from the textbook as an example of using default arguments.
CODE:-
#include<iostream>
using namespace std;
double totalCost(int shipping_cost=0,int cost_of_one_box=4, int number_of_boxes_purchased=1){ // defining the function woth three default arguements
int total_cost = shipping_cost + (number_of_boxes_purchased) * (cost_of_one_box); // this is the formula to calculate the total cost
return total_cost; // returning the total cost
}
int main() {
cout<< "Testing with one argument and value of argument is 5"<<endl; // testing the function
cout<<"Total Cost Returned: "<<totalCost(5)<<endl; // with different arguments
cout<< "Testing with two argument and value of arguments is 5,10"<<endl;
cout<<"Total Cost Returned: "<<totalCost(5,10)<<endl;
cout<< "Testing with three argument and value of argument is 5,10,15"<<endl;
cout<<"Total Cost Returned: "<<totalCost(5,10,15)<<endl;
}
OUTPUT:-
FOR ANY OTHER QUERY PLEASE COMMENT.
Get Answers For Free
Most questions answered within 1 hours.