Swap data

Description:

Program to swap data using function templates. Test Case 1 Input (stdin) 4 3 2.1 1.2 d f Expected Output Before passing data to function template. i1 = 4 i2 = 3 f1 = 2.1 f2 = 1.2 c1 = d c2 = f After passing data to function template. i1 = 3 i2 = 4 f1 = 1.2 f2 = 2.1 c1 = f c2 = d Test Case 2 Input (stdin) 7 6 1.1 5.4 f w Expected Output Before passing data to function template. i1 = 7 i2 = 6 f1 = 1.1 f2 = 5.4 c1 = f c2 = w After passing data to function template. i1 = 6 i2 = 7 f1 = 5.4 f2 = 1.1 c1 = w c2 = f

Program :

  • #include <iostream>

    using namespace std;

    int main()

    {

    int a,b,c;

      float d,e,f;

      char x,y,z;

      cin>>a>>b>>d>>e>>x>>y;

      cout<<"Before passing data to function template.";

      cout<<"\ni1 = "<<a<<"\ni2 = "<<b<<"\nf1 = "<<d<<"\nf2 = "<<e;

      cout<<"\nc1 = "<<x<<"\nc2 = "<<y;

      c=a; a=b; b=c;

      f=d; d=e; e=f;

      z=x; x=y; y=z;

      cout<<"\nAfter passing data to function template.";

        cout<<"\ni1 = "<<a<<"\ni2 = "<<b<<"\nf1 = "<<d<<"\nf2 = "<<e;

      cout<<"\nc1 = "<<x<<"\nc2 = "<<y;

    return 0;

    }