Answer to Question #273812 in C++ for Amit

Question #273812

WAP using function template to add two numbers and display result.


1
Expert's answer
2021-11-30T18:39:42-0500
#include <iostream>


using namespace std;
template<class t1,class t2>
void sum(t1 a,t2 b)//defining template function
{
    cout<<"\sum="<<a+b<<endl;
}


int main()
{
    int a,b;
    float x,y;
    cout << "\nEnter two integer data: " << endl;
    cin>>a>>b;
    cout << "\nEnter two float data: " << endl;
    cin>>x>>y;
    sum(a,b);//adding two integer type data
    sum(x,y);//adding two float type data
    sum(a,x);//adding float and integer type data
    return 0;
}

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