Question

Write in C++ program and write a function named add. It should accept two const double...

Write in C++ program and write a function named add. It should accept two const double type references as arguments. The first argument should be named num1; the second argument should be named num2. The function should return by value of num1 plus num2.

Homework Answers

Answer #1

C++ code:

#include <iostream>
using namespace std;
//initializing add function
double add(const double &num1,const double &num2){
//returning num1+num2
return num1+num2;
}
int main()
{
//initializing a sample value for num1 and num2
double num1=1,num2=2;
//calling add function and printing the result
cout<<add(num1,num2)<<endl;
return 0;
}


Screenshot:


Input and Output:

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
Write in C++ program and write a function named computeCostPlusGST. It should accept two double type...
Write in C++ program and write a function named computeCostPlusGST. It should accept two double type variable as arguments. The first argument should be named cost; the second argument should be named rate. The argument rate should have a default value of 0.15. The function should return by value the value of cost plus the product of cost and rate
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...
Define a function math(num1, num2, operation) that takes three arguments and it should perform math operations...
Define a function math(num1, num2, operation) that takes three arguments and it should perform math operations ( +,-,* and /) on two numbers num1 and num2 based on the operation symbol, and then it should return the result. The main part of the program should prompt users to provide num1, num2, and an operation symbol separately and then call the function with user inputs and display the result back to the user. Function definition should look like this in your...
1) Develop a C++ function that determines the average value of an array of type double...
1) Develop a C++ function that determines the average value of an array of type double elements double GetAverage(double array[], int size) The function should accept as input an array of double values The function should accept as input the number of elements in the array of double values The function should return a double value which is the array's average value 2) Develop a C++ function that determines the variance of an array of type double elements double GetVariance(double...
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the...
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the console calculator is created which perform multiply,divide,sub and add, operation and it accept all type of data (divide by 0 case as well ).Now the main motive is to create the library project from the console calculator project .Than we have to create a unit test project which test the functionality of added library.Make test like Test 1. multiply two positive number,Test 2. Add...
Write a C# source code. Write a function called CircArea() that finds the area of a...
Write a C# source code. Write a function called CircArea() that finds the area of a circle. It should take an argument of type double and return an argument of the same type. Write a Main() method that gets a radius value from the user, calls CircArea(), and displays the result.
write a python program that include a function named activity_selection() and take in two arguments, first...
write a python program that include a function named activity_selection() and take in two arguments, first one would be the number of tasks and the second argument would be a list of activities. Each activity would have an activity number, start time and finish time. Example activity_selection input and output: activity_selection (11, [[1, 1, 4 ], [2, 3, 5], [3, 0, 6], [4, 5, 7], [5, 3, 9], [6, 5, 9],[7, 6, 10], [ 8, 8, 11], [ 9, 8,...
javascript 1.Write a function delay that accepts two arguments, a callback and the wait time in...
javascript 1.Write a function delay that accepts two arguments, a callback and the wait time in milliseconds. Delay should return a function that, when invoked waits for the specified amount of time before executing. HINT - research setTimeout(); 2.Create a function saveOutput that accepts a function (that will accept one argument), and a string (that will act as a password). saveOutput will then return a function that behaves exactly like the passed-in function, except for when the password string is...
Task 1: Program Analysis Write a function cutEdges that removes the first and the last two...
Task 1: Program Analysis Write a function cutEdges that removes the first and the last two items from a list given as its argument.  The existing list should be changed in-place; the function should not return anything..programmed in python
USE C++ Write a function named find that takes a pointer to the beginning and a...
USE C++ Write a function named find that takes a pointer to the beginning and a pointer to the end (1 element past the last) of an array, as well as a value. The function should search for the given value and return a pointer to the first element with that value, or the end pointer if no element was found.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT