运用函数重载的知识,设计一组(2个)重载函数,这两个函数可以分别完成两个双精度浮点型数、两个字符型数的交换。(要求:必须用C++程序完成,主函数负责输入输出的工作,重载函数只负责交换。)

运用函数重载的知识,设计一组(2个)重载函数,这两个函数可以分别完成两个双精度浮点型数、两个字符型数的交换。(要求:必须用C++程序完成,主函数负责输入输出的工作,重载函数只负责交换。)

img


template<class T>
T swap(T t1,T t2)
{
    T temp;
    temp = t2;
    t2 = t1;
    t1 = temp;
    cout <<"交换后第一个数" << t1 <<"交换后第二个数"<< t2 << endl;
    return 0;
}
int main()
{
    cout << "please input two double number" << endl;
    double a, b;
    cin >> a >> b;
    cout << "交换前第一个数"<< a << "交换前第二个数" << b << endl;
    swap(a, b);
    cout << "please input two char buff" << endl;
    char s1, s2;
    cin >> s1 >> s2;
    cout << "交换前第一个数" << s1 << "交换前第二个数" << s2 << endl;
    swap(s1,s2);

    return 0;
}