Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Object Oriented ProgrammingRSS Feeds

Program to interchange the values of two int , float and char using function templates

Posted By: Easy Tutor     Category: C++ Programming     Views: 6245

A C++ Program to interchange the values of two int , float and char using function templates.

Code for Program to interchange the values of two int , float and char using function templates in C++ Programming

 #include<iostream.h>
 #include<conio.h>

 /*************************************************************************///---------------------------   swap(T &,T &)  --------------------------///*************************************************************************/
 
 template <class T>

 void swap(T &value_1,T &value_2)
    {
       T temp;

       temp=value_2;
       value_2=value_1;
       value_1=temp;
    }


 main()
    {
       clrscr();

       int int_1;
       int int_2;

       float float_1;
       float float_2;

       char char_1;
       char char_2;

       cout<<"\n ********* Data Type - int  **********"<<endl;

       cout<<"\n Enter the value of int_1 = ";
       cin>>int_1;

       cout<<"\n Enter the value of int_2 = ";
       cin>>int_2;

       cout<<"\n ********* Data Type - floatt  **********"<<endl;

       cout<<"\n Enter the value of floatt_1 = ";
       cin>>float_1;

       cout<<"\n Enter the value of float_2 = ";
       cin>>float_2;

       cout<<"\n ********* Data Type - char  **********"<<endl;

       cout<<"\n Enter the value of char_1 = ";
       cin>>char_1;

       cout<<"\n Enter the value of char_2 = ";
       cin>>char_2;

       getch();
       clrscr();

       cout<<"\n ********* Before Swap()  **********"<<endl;

       cout<<"\n Values of int :"<<endl;

       cout<<"\t\t Value of int_1 = "<<int_1<<endl;
       cout<<"\t\t Value of int_2 = "<<int_2<<endl;

       cout<<" Values of float :"<<endl;

       cout<<"\t\t Value of float_1 = "<<float_1<<endl;
       cout<<"\t\t Value of float_2 = "<<float_2<<endl;

       cout<<" Values of  char :"<<endl;

       cout<<"\t\t Value of char_1 = "<<char_1<<endl;
       cout<<"\t\t Value of char_2 = "<<char_2<<endl;

       cout<<"\n ********* After Swap()  **********"<<endl;

       cout<<"\n Values of int :"<<endl;
       swap(int_1,int_2);
       cout<<"\t\t Value of int_1 = "<<int_1<<endl;
       cout<<"\t\t Value of int_2 = "<<int_2<<endl;

       cout<<" Values of float :"<<endl;
       swap(float_1,float_2);
       cout<<"\t\t Value of float_1 = "<<float_1<<endl;
       cout<<"\t\t Value of float_2 = "<<float_2<<endl;

       cout<<" Values of  char :"<<endl;
       swap(char_1,char_2);
       cout<<"\t\t Value of char_1 = "<<char_1<<endl;
       cout<<"\t\t Value of char_2 = "<<char_2<<endl;

       getch();
       return 0;
    }
  
Share: 



Easy Tutor
Easy Tutor author of Program to interchange the values of two int , float and char using function templates is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!