Question

In: Computer Science

C++ coding plase Given three integer numbers N1, N2 and N3. Write 2 overloaded functions which...

C++ coding plase

Given three integer numbers N1, N2 and N3. Write 2 overloaded functions which perform addition of passed values.

Write two functions inside 'ProblemSolution' class:

Function 1:

solution that accepts two parameters, N1 and N2. A function should return addition of those numbers.

Function 2:

solution that accepts three parameters, N1, N2 and N3. A function should return addition of 3 numbers.

Input
    2
    3
    4

Output
    5
    9

Where,

The first line of output contains addition of N1 and N2.

The second line of output contains addition of N1, N2 and N3.

using this code in the problem

#include <Iostream>

using namespace Std;

Class ProblemSolution

{

// write your code here

}:

int main()

{

int N1,N2,N3;

cin >> n1;

cin >> N2;

cin >> N3;

problemSolution problemSolution;

cout << problemSolution.solution(N!,N2)<<"\n" ;

cout << problemSolution.solution( N1,N2,N3);

return 0;

Solutions

Expert Solution

Solution :

#include <Iostream>
using namespace std;

class ProblemSolution
{
   // write your code here
   public:
       int solution(int a, int b) {
           return a + b;
       }
      
       int solution(int a, int b, int c) {
           return a + b + c;
       }
};

int main()
{
   int N1,N2,N3;
   cin >> N1;
   cin >> N2;
   cin >> N3;

   ProblemSolution problemSolution;
   cout << problemSolution.solution(N1,N2) << "\n" ;
   cout << problemSolution.solution(N1,N2,N3);

   return 0;
}


Note: There some minor Syntactical error in your code ,so i fix it please check it

Screenshot :


Related Solutions

If n1<n2 and n3<n2, which of the following statements are true when it comes to finding...
If n1<n2 and n3<n2, which of the following statements are true when it comes to finding out if you have destructive interference of the reflected rays? You do need to know if n1 is bigger or smaller than n3. You cannot make any calculations unless you know the numerical value of n3. You cannot make any calculations unless you know the numerical value of n2. The reflected ray from the interface between medium 1 and medium 2 will undergo a...
Single inheritance Given two integer numbers N1 and N2, create a class 'ProblemSolution' with following characteristics....
Single inheritance Given two integer numbers N1 and N2, create a class 'ProblemSolution' with following characteristics. Must extend a 'Base' class. Create a method 'solution' with two integer parameters (N1 and N2) and long return type. The 'solution' method should call the addition and subtraction methods of 'Base' class and return multiplication of returned results of addition and subtraction method. Result = (N1 + N2) * (N1 - N2) What is inheritance? Inheritance is a mechanism in which one object...
Write a program in java which randomly generates two integer number n1 and n2 (suppose the...
Write a program in java which randomly generates two integer number n1 and n2 (suppose the range for each integer is [1, 100]), then asks the user what is the value of n1*n2, if the user’s answer is correct, call method printGoodComment to print out something nice, otherwise, call printBadComment to print out something “mean”. The method signatures are:                   public static void printGoodComment() and                   public static void printBadComment() in your printGoodComment method, it will randomly print one sentence from the...
Write a program in java which randomly generates two integer number n1 and n2 (suppose the...
Write a program in java which randomly generates two integer number n1 and n2 (suppose the range for each integer is [1, 100]), then asks the user what is the value of n1*n2, if the user’s answer is correct, call method printGoodComment to print out something nice, otherwise, call printBadComment to print out something “mean”. The method signatures are:                   public static void printGoodComment() and                   public static void printBadComment() in your printGoodComment method, it will randomly print one sentence from the...
Let a , b , c be three integer numbers. Write a C++ program with a...
Let a , b , c be three integer numbers. Write a C++ program with a functions void rotate1(int* a,int* b,int* c) void rotate2(int& a,int& b,int& c) such that a -> b , b -> c and c -> a. Thus we use two different approaches (pointers in rotate1 and references in rotate2).
Write a C code program to implement the comparisons of three integer numbers, using only conditional...
Write a C code program to implement the comparisons of three integer numbers, using only conditional operators (no if statements). Please ask the user to input random three integers. Then display the minimum, middle, and maximum number in one line. Also, please calculate and display the sum and the average value (save two digits after decimal point) of these three integers. Please write the comments line by line.
The Sum and The Average In C++, Write a program that reads in 10 integer numbers....
The Sum and The Average In C++, Write a program that reads in 10 integer numbers. Your program should do the following things: Use a Do statement Determine the number positive or negative Count the numbers of positive numbers, and negative Outputs the sum of: all the numbers greater than zero all the numbers less than zero (which will be a negative number or zero) all the numbers Calculate the average of all the numbers. The user enters the ten...
Write a C++ program to read a collective of integer numbers. I f the number is...
Write a C++ program to read a collective of integer numbers. I f the number is greater than zero and less than 15 then terminate the loop and find factorial of the number
Write a C++ program that randomly generates N integer numbers (such that N is entered by...
Write a C++ program that randomly generates N integer numbers (such that N is entered by the user) and then stores them to a text file (myNumbers.txt) sorted in increasing (non-decreasing) order. Again, please notice that the size of the data (N) is known during the run time, not the compile-time (needs to be entered by the user after running the program).
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it...
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it in horizontal order of the screen
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT