Monday, February 8, 2016

 //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

Translate

Sample Text

Powered by Blogger.

Every thing is possible in real world....

Contact us

Name

Email *

Message *

IT Support

Blogroll

You can replace this text by going to "Layout" and then "Page Elements" section. Edit " About "

Video

Our Facebook Page

Popular Posts

Total Pageviews