//Adding two number using class template...
#include <iostream>#include<conio.h>
using namespace std;
template <class T>
class mytemp
{
private:
T a,b,c;
public:
void getdata()
{
cout<<"Enter first number:";
cin>>a;
cout<<"Enter Second number:";
cin>>b;
cout<<endl;
}
void total()
{
c=a+b;
cout<<"Total values is:"<<c<<endl;
cout<<endl;
}
};
int main()
{
mytemp<int>obj1;
mytemp<float>obj2;
cout<<"Enter two integer:"<<endl;
obj1.getdata();
obj1.total();
cout<<"Enter two float:"<<endl;
obj2.getdata();
obj2.total();
cout<<"********Thank You********"<<endl;
getch();
return 0;
}
OutPut
0 comments:
Post a Comment