Welcome

Hi! This blog is for beginners of c++ and java .You can check and pick codes for your programming assignments. This will also help you to understand the concepts of these programming languages. Its all about programming.

Template Practice (Sum of three numbers)

Wednesday, May 25, 2011

#include<iostream.h>
template<class T>
class Add
{
private:
T a,b,c,res;
public:
void getdata()
{
cout<<"\n Enter the ist value = ";
cin>>a;
cout<<"\n Enter the second value = ";
cin>>b;
cout<<"\n Enter the Third value = ";
cin>>c;
}
void display()
{
res = (a+b+c);
cout<<"\n\n Sum is = "<<res<<endl;
}
};
void main()
{
Add<int>s;
s.getdata();
s.display();
Add<float>s1;
s1.getdata();
s1.display();
}