In: Computer Science
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;
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 :