C++ LAB

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7

PART- B

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8

old

PROGRAM 8 PROGRAM 9 PROGRAM 10 PROGRAM 11 PROGRAM 12 PROGRAM 13 PROGRAM 14 . . .

write a c++ program to swap two numbers using function template

 
   
#include< iostream >
 
using namespace std;
 

 template < class T >
void  swapp(T &a,T &b)      //Function Template
{
    T temp=a;
    a=b;
    b=temp;
};


 
int main()
{
    int x1=4,y1=7;
    float x2=4.5,y2=7.5;
 

    cout << "Before Swap:";
    cout << "\nx1=" << x1 << "ty1=" << y1;
    cout << "\nx2=" << x2 << "ty2=" << y2;

     swapp(x1,y1);
     swapp(x2,y2);

    cout<<"\nAfter Swap:";
    cout<< "\nx1=" << x1 << "ty1=" << y1;
    cout<< "\nx2=" << x2 << "ty2=" << y2;

    return 0;
}