Question

In: Computer Science

Write code to define a function named mymath. The function has three arguments in the following...

Write code to define a function named mymath. The function has three arguments in the following order: Boolean, Integer, and Integer. It returns an Integer.
The function will return a value as follows:

1. If the Boolean variable is True, the function returns the sum of the two integers.
2. If the Boolean is False, then the function returns the value of the first integer - the value of the second Integer.

Solutions

Expert Solution

The answer to this question is as follows:

The code is as follows:

#include <iostream>

using namespace std;
//Decalring the function mymath that takes three parameters
int mymath(bool value,int a,int b)
{
if(value==true)
{
//if the boolean value is true return sum
return a+b;
}
//otherwise return first value - second value
else
{
return a-b;
}
}

int main() {
int x=10;
int y=25;
bool val=true;
//calling the function and printg the output
cout<<"The ouput is "<<mymath(val,x,y);
}

The input and output is provided in the screenshot below:


Related Solutions

Write python 3 code to define a function that uses three arguments, and returns a result....
Write python 3 code to define a function that uses three arguments, and returns a result. The function returns True if the first argument is more than or equal to the second argument and less than or equal to the third argument, otherwise it returns False. Write a python 3 code for function main, that does the following: creates a variable and assign it the value True. uses a while loop which runs as long as the variable of the...
a splitting function, split_by Write a splitting function named split_by that takes three arguments an equality...
a splitting function, split_by Write a splitting function named split_by that takes three arguments an equality checking function that takes two values and returns a value of type bool, a list of values that are to be separated, and a list of separators values. This function will split the second list into a list of lists. If the checking function indicates that an element of the first list (the second argument) is an element of the second list (the third...
Make a python code. Write a function named max that accepts two integer values as arguments...
Make a python code. Write a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is the greater of the two. Write the program as a loop that...
2 Write a function named equivalentArrays that has two array arguments and returns 1 if the...
2 Write a function named equivalentArrays that has two array arguments and returns 1 if the two arrays contain the same values (but not necessarily in the same order), otherwise it returns 0. Your solution must not sort either array or a copy of either array! Also you must not modify either array, i.e., the values in the arrays upon return from the function must be the same as when the function was called. Note that the arrays do not...
(python) Write a function that involves two arguments, named changeTheCase(myFile, case),thattakes, as arguments, the name of...
(python) Write a function that involves two arguments, named changeTheCase(myFile, case),thattakes, as arguments, the name of a file, myFile, and the case, which will either be"upper"or"lower".If case is equal to "upper" the function will open the file, convert all characters on each line to upper case, write each line to a new file, named "upperCase.txt", and return the string "Converted file to upper case."If case is equal to "lower" the function will open the file, convert all characters on each...
Write a function named hasNValues which takes an array and an integer n as arguments. It...
Write a function named hasNValues which takes an array and an integer n as arguments. It returns true if all the elements of the array are one of n different values. If you are writing in Java or C#, the function signature is int hasNValues(int[ ] a, int n) If you are writing in C or C++, the function signature is int hasNValues(int a[ ], int n, int len) where len is the length of a Note that an array...
(a) Write an R function rnormmax that has three arguments, n, mu, and sigm, # and...
(a) Write an R function rnormmax that has three arguments, n, mu, and sigm, # and returns the maximum of a vector of n random numbers from the normal distribution # with mean mu and standard deviation sigm. Make the arguments mu and sigm optional # with default values of 0 and 1, respectively. # (b) Write an R code that replicates rnormmax(n=1000) hundred thousand times and creates # a histogram of the resulting vector via standard hist function.
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,...
Write a boolean function named isMember that takes two arguments: an array of type char and...
Write a boolean function named isMember that takes two arguments: an array of type char and a value. It should return true if the value is found in the array, or false if the value is not found in the array. PLEASE WRITE FULL PROGRAM IN C++ AND USE RECURSION AND DO NOT USE LOOPS
1. define a class that has three different constructors. 2. write code that overrides the following...
1. define a class that has three different constructors. 2. write code that overrides the following method public double sqr(double num1) { return num1*num1; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT