Question

C++ Help: Write one single function that can mutliply either 2, 3, or 4 numbers and...

C++ Help: Write one single function that can mutliply either 2, 3, or 4 numbers and returns the product double res1 = multiply(1.2, 3.4); double res2 = multiply(1.2, 3.4, 5.8); double res3 = multiply(1.2, 3.4, 5.8, 4.7);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:::

#include<iostream>
using namespace std;

double multiply(double a,double b,double c=1, double d=1){
   return a*b*c*d;
}

int main()
{
   cout<<"multiply(1.2, 3.4) : "<<multiply(1.2, 3.4)<<endl;
   cout<<"multiply(1.2, 3.4, 5.8) : "<<multiply(1.2, 3.4, 5.8)<<endl;
   cout<<"multiply(1.2, 3.4, 5.8, 4.7) : "<<multiply(1.2, 3.4, 5.8, 4.7)<<endl;


   return 0;
}

output:

Add a comment
Know the answer?
Add Answer to:
C++ Help: Write one single function that can mutliply either 2, 3, or 4 numbers and...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand....

    In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand. Do not write "#include" and do not write whole "main()" function. Write only the minimal necessary code to accomplish the required task.                                                                                                           Save your answer file with the name: "FinalA.txt" 1) (2 pts) Given this loop                                                                                              int cnt = 1;     do {     cnt += 3;     } while (cnt < 25);     cout << cnt; It runs ________ times    ...

  • Write this function in c++.Use of string and <cstring> is not allowed .You are required to...

    Write this function in c++.Use of string and <cstring> is not allowed .You are required to use char* and implement the use of ** in this question . Gtest case to pass: #include "q1.cpp" #include <gtest/gtest.h> //-------------------Q1_8----------------- TEST(Question1_8, First) { char t1[]="Hello World"; char res1[] = "Hello"; char res2[] = "World"; char** r= StrTok(t1,' '); ASSERT_EQ(0, strcmp(r[0],res1) ); ASSERT_EQ(0, strcmp(r[1],res2) ); } TEST(Question1_8, Second) { char t1[]="Hello?World?OOP"; char res1[] = "Hello"; char res2[] = "World"; char res3[] = "OOP"; char**...

  • Q5 (25pts) Consider the code: int foo(int N){ if (N <= 3) return 2; int res1 = 3*foo(N-4); int...

    Q5 (25pts) Consider the code: int foo(int N){ if (N <= 3) return 2; int res1 = 3*foo(N-4); int res2 = foo(N-2); return res1-res2; } a) (6 points) Write the recurrence formula for the time complexity of this function (including the base cases) for N>=0. You do NOT need to solve it. b) (5 points) Draw the tree that shows the function calls performed in order to compute foo(8) (the root will be foo(8) and it will have a child...

  • C++ 2. (a) Write a function, printdixisors, that takes a single integer parameter and prints all...

    C++ 2. (a) Write a function, printdixisors, that takes a single integer parameter and prints all the numbers less that the parameter that are divisors of the parameter (i.e. divides it without a remainder) including 1. So printdivisors(6) will print 1,2,3. Note you may use a wrapper function or default parameters. (b) Write a function, sumdixisors, that takes a single integer parameter and returns the sum of all the divisors of the parameter (including 1). So sumdivisors(6) will return 6...

  • Needs some help [User-Defined Function] C++ Write a function, readWrite, that reads a set of test...

    Needs some help [User-Defined Function] C++ Write a function, readWrite, that reads a set of test scores stored in a file and calculates and returns the average of the numbers. The function returns a double and has the name of the file as its parameter. If the data is as follows, the average will be 5.66. 3 6 8

  • Python 3: Write a function CharCount, to take a string S and a single character C,...

    Python 3: Write a function CharCount, to take a string S and a single character C, and returns the count of C (one letter) in the string S. If the letter of C is not found in S, the function returns -1. You must write your own function to do this and can not use any built-in counting functions. Use the function in main to get two inputs from the user, a sentence and a character, then show the count...

  • Credit card numbers follow certain patterns. A credit card number must have between 13 and 16...

    Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits. It must start with: 4 for Visa cards 5 for Master cards 37 for American Express cards 6 for Discover cards IBM proposed an algorithm for validating credit card numbers. The algorithm is used to determine if a card number is entered correctly or if a credit card is scanned correctly by a scanner. Almost all credit card numbers are generated following this...

  • Using Blitz3D 1. This function returns the sum of five numbers 2. This function returns the quoti...

    please help this function using Blitz3D Using Blitz3D 1. This function returns the sum of five numbers 2. This function returns the quotient of dividing a smaller number by the larger # 3. This function returns the difference... 4. A product function Eg. start with Function NameOfFunction Code.... here End Function Using Blitz3D 1. This function returns the sum of five numbers 2. This function returns the quotient of dividing a smaller number by the larger # 3. This function...

  • USING C++, write a simple class defining complex numbers USING the FRIEND function (READ BELOW) Write...

    USING C++, write a simple class defining complex numbers USING the FRIEND function (READ BELOW) Write a C++ defining a class for complex numbers. A complex number is a number of the form: a + b ∗ i , where, for our purposes, a and b are numbers of type double, and i is a number that represents the quantity √−1. You should represent a complex number here as two values of type double. You should name the variables real...

  • Average and Standard Deviation of 4 numbers **c++** Write an input function to input 4 doubles....

    Average and Standard Deviation of 4 numbers **c++** Write an input function to input 4 doubles. then write a function that computes the average of 4 doubles and returns the average and the standard deviation. Write a output routine that shows the 6 numbers. Please feel free to use sub-functions to break up your code.    you can name the four variables a1, a2, a3, a4, or something equally simple as long as you are consistent. Average (or mean) is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT