(Function Template swap_value) Write a program that uses a function template called swap_value to swap the value of two arguments. Test the program using integer, character and floating point number arguments.
(Function Template swap_value) Write a program that uses a function template called swap_value to swap the value of two arguments. Test the program using integer, character and floating point number arguments.
The input consists of n (0<n<100) samples.
Each sample consists of three lines.
The first line of each sample consists of two integers(range from 0 to 100)
The second line of each sample consists of two char.
The third line of each sample consists of two doubles(range from 0 to 100)
The last line of input consists of Int(-1).
输入
5 6 a b 1.2 5.2 1 2 e d 0 2 -1
输出
6 5 b a 5.2 1.2 2 1 d e 2 0
The main function is provided, you only need to complete the Function Template swap_value:
#include <iostream>
using namespace std;
// ToDo function template swap_value
int main()
{
int int1 = 0;
int int2 = 0;
char char1 = ' ';
char char2 = ' ';
double double1 = 0;
double double2 = 0;
while(true){
cin>>int1;
if(int1==-1)
break;
cin>>int2;
swap_value(int1, int2);
cout<<int1 << " "<<int2<<endl;
cin >> char1 >> char2;
swap_value(char1,char2);
cout << char1 << " " << char2 << endl;
cin >> double1 >> double2;
swap_value(double1,double2);
cout << double1 << " " << double2 << endl;
cout<<endl;
}
}