Answer to Question #174763 in C++ for Hari bashkar

Question #174763

Implement a C++ program to overload the function named as sum, to perform sum of digits of integer and perform sum of digits of float number respectively.


1
Expert's answer
2021-03-24T06:20:18-0400
#include <iostream>


using namespace std;


int sum(int a, int b);
float sum(float a, float);	// overloaded function


int main()
{
	int intA = 0;
	int intB = 0;
	cout << "Enter first int number: ";
	cin >> intA;
	cout << "Enter second int number: ";
	cin >> intB;
	cout << "result of sum() is: " << sum(intA, intB) << endl << endl;
	float floatA = 0;
	float floatB = 0;
	cout << "Enter first float number: ";
	cin >> floatA;
	cout << "Enter second float number: ";
	cin >> floatB;
	cout << "result of sum() is: " << sum(floatA, floatB) << endl << endl;
	return 0;
}


int sum(int a, int b)
{
	return a + b;
}


float sum(float a, float b)
{
	return a + b;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS