Question #273812

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


Expert's answer

#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!

LATEST TUTORIALS
APPROVED BY CLIENTS