Question

Part 3. Write a function called totalCost that takes three parameters (shipping cost, cost of one...

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.

Homework Answers

Answer #1

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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1. Write a function called compute_discount which takes a float as the cost and a Boolean...
1. Write a function called compute_discount which takes a float as the cost and a Boolean value to indicate membership. If the customer is a member, give him/her a 10% discount. If the customer is not a member, she/he will not receive a discount. Give all customers a 5% discount, since it is Cyber Tuesday. Return the discounted cost. Do not prompt the user for input or print within the compute_discount function. Call the function from within main() and pass...
Design, code, and test a program that includes a function of type double called divbaby that...
Design, code, and test a program that includes a function of type double called divbaby that accepts two double arguments (you must write the divbaby function). When called, your function will return the first argument divided by the second argument. Make sure your function includes a decision statement so that it can't divide by 0--if the caller attempts to divide by 0 the function should return a value of -2.0. Your program should call divbaby then display the value returned...
Function Example: Write a Python function that receives two integer arguments and writes out their sum...
Function Example: Write a Python function that receives two integer arguments and writes out their sum and their product. Assume no global variables. def writer(n1, n2): sum = n1 + n2 product = n1*n2 print("For the numbers", n1, "and", n2) print("the sum is", sum) print("and the product is", product) ... 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both...
Write the functions which are called in the main function given. YOU MAY ASSUME THAT THE...
Write the functions which are called in the main function given. YOU MAY ASSUME THAT THE USER ENTERS A VALID INTEGER. printDouble should accept one value and should print the value of that number times 2. printEndMessage should not accept any values and should print a message indicating that the program has finished. def main(): num1 = int(input("Please enter your number ")) printDouble(num1) printEndMessage() main()
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns the index of the first occurance of the smallest value in the array. Your function must be able to process all the elements in the array. Create a function prototype and function definition (after the main function). Your main function should declare a 100 element integer array. Prompt the user for the number of integers to enter and then prompt the user for each...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an array of ints, an int value named element, and an int value named end. Return a bool based on whether the element appears in the array starting from index 0 and up to but not including the end index. Generate Random Array Write a function that takes as parameters an array of integers and another integer for the size of the array. Create a...
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will implement Queue Abstract Data Type with the following functions/methods.  Any build-in/pre-defined Queue function/library (e.g., java.util.Queue in Java) is NOT allowed to use in your code. push(Element):  insert the input Element (e.g., String or Integer in Java) to the end of the queue. pop(): remove the head element of the queue and print the head element on screen. count():  return the total number of elements in the queue...
Python Jupyter Notebook Write a python function called profit that takes the number of meals (n)...
Python Jupyter Notebook Write a python function called profit that takes the number of meals (n) sold by a restaurant in a month and calculates the monthly profit given the following information: The selling price of each meal is 12 USD (same for all meals) There is a fixed cost of 2500 USD per month regardless of the number of meals sold. There is a variable cost of 6 USD per each meal sold profit= total revenue- total cost =...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to N. The function calculateSum has one parameter N of type integer and returns an integer which represents the sum from -1 to N, inclusive. Write another function calculateAverage that calculates an average. This function will have two parameters: the sum and the number of items. It returns the average (of type float). The main function should be responsible for all inputs and outputs. Your...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT