zoukankan      html  css  js  c++  java
  • 类模板

    #include<iostream>
    using namespace std;
    template<class T>
    class compare{
    public:
    compare(T aa,T bb):a(aa),b(bb){}
    void update1();
    void update2();
    void update3();

    private:
    T a,b;
    };

    template<class T>
    void compare<T>::update1()
    {
    if(a<b)
    {
    cout<<b<<" is the Maximum of two inteder numbers."<<endl;
    cout<<a<<" is the Minimum of two inteder numbers."<<endl;
    }
    else
    {
    cout<<a<<" is the Maximum of two inteder numbers."<<endl;
    cout<<b<<" is the Minimum of two inteder numbers."<<endl;
    }
    cout<<endl;
    }

    template<class T>
    void compare<T>::update2()
    {
    if(a<b)
    {
    cout<<b<<" is the Maximum of two float numbers."<<endl;
    cout<<a<<" is the Minimum of two float numbers."<<endl;
    }
    else
    {
    cout<<a<<" is the Maximum of two float numbers."<<endl;
    cout<<b<<" is the Minimum of two float numbers."<<endl;
    }
    cout<<endl;
    }

    template<class T>
    void compare<T>::update3()
    {
    if(a<b)
    {
    cout<<b<<" is the Maximum of two characters."<<endl;
    cout<<a<<" is the Minimum of two characters."<<endl;
    }
    else
    {
    cout<<a<<" is the Maximum of two characters."<<endl;
    cout<<b<<" is the Minimum of two characters."<<endl;
    }
    }

    int main(){
    int x1,y1;
    cin>>x1>>y1;
    compare<int>ii(x1,y1);
    ii.update1 ();

    float x2,y2;
    cin>>x2>>y2;
    compare<float>ff(x2,y2);
    ff.update2();

    char x3[30],y3[30];
    cin>>x3>>y3;
    compare<char>cc(x3[1],y3[1]);
    cc.update3();
    return 0;
    }

  • 相关阅读:
    网址
    asp.net 各种路径查找
    jquery.nicescroll.js 滚动条插件 API
    课程表上一周下一周
    上一周下一周
    使用NPOI导入导出标准Excel
    FTP文件操作 上传文、 下载文件、删除文件 、创建目录
    asp.net断点续传
    11.06第九次作业
    11.20dezuoye
  • 原文地址:https://www.cnblogs.com/zeross/p/4613368.html
Copyright © 2011-2022 走看看