C++ Programming Blog

 
 
 

Image

 #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;
    }

    Related Post:
  1. Program to interchange the values of two int , float and char using function templates

  2. Program that provides an example of passing objects to function using call by reference method

  3. Program to draw a Circular Arc using Trigonometric Method

  4. Program to solve the mystery of Towers of Hanoi using recursion

  5. Program of Deterministic Finite Automation (DFA) for identifier, real number with optional Integer and Fractional Part

  6. Program to estimate the value of Fourth Derivative of the function at the given points from the given data using Central Difference Formula of order 4

  7. Program to illustrate over-riding of base class member function in a derived class

  8. Program to illustrate the implementation of arrays as a Linear Queue ( in graphics )

  9. Program to add, subtract and multiply matrix

  10. Program to illustrate the binary operator(-) overloading by creating an object of that class

  11. Program to illustrate the use of function overloading

  12. Program for Fahrenheit to Celcius

  13. Program to show the projection of 3D objects using Standard Perspective Projection w.r.t. an Arbitrary Plane and Center of Projection...

  14. Program of Minimum Spaning Tree ( MST )

  15. Program to print, read and calculate sum, smallest, largest element an array using pointers

  16. Program to rotate the word Computer by 1 results in rCompute

  17. Program to estimate the value of First Derivative of the function at the given points from the given data using Central Difference Formula of order 4

  18. Program that provides an example of call by value for functions

  19. Program that takes input of vector elements and performs multiplication operation, and input/output (&gt;&gt;, &lt;&lt;) using operator overloading

  20. Program to convert an Infix Expression into a Postfix Expression using Linked List as a Stack