zoukankan      html  css  js  c++  java
  • 2021.9.16 简单工厂模式(女娲造人)

    一、今日学习内容

       

    1、类图

    2、源程序代码

    #include<iostream>
    #include<vector>
    using namespace std;
    
    typedef enum PersonTypeTag
    {
        M,
        W,
        R
    }PersonType;
    
    class Person
    {
    public:
         virtual void make() = 0;
    };
    
    class Man : public Person
    {
    public:
        void make()
        {
            cout << "生产男人" << endl;
        }
    };
    
    class Woman : public Person
    {
    public:
        void make()
        {
            cout << "生产女人" << endl;
        }
    };
    
    class Robot : public Person
    {
    public:
        void make()
        {
            cout << "生产机器人" << endl;
        }
    };
    
    class Nvwa
    {
    public:
        Person*Personjudge(PersonType type) {
            switch (type) {
            case M:
                return new Man();
            case W:
                return new Woman();
            case R:
                return new Robot();
            default:
                return NULL;
            }
        }
    };
    
    int main(int argc, char *argv[])
    {
        Nvwa *nvwa = new Nvwa();
        char t = 0;
    
        Person * man = nvwa->Personjudge(M);
        Person * woman = nvwa->Personjudge(W);
        Person * robot = nvwa->Personjudge(R);
    
        while (t != -1) {
            cout << "请输入标识符:";
            cin >> t;
            if (t == 'M')
                man->make();
            else if (t == 'W')
                woman->make();
            else if (t == 'R')
                robot->make();
            else {
                cout << "输入的标识符有误,请重新输入!" << endl;
                cout << "请输入标识符:";
                cin >> t;
            }
            cout << endl;
        }
        delete nvwa;
        nvwa = NULL;
    
        delete man;
        man = NULL;
    
        delete woman;
        woman = NULL;
    
        delete robot;
        robot = NULL;
    
        return 0;
    }

    3、运行截图

    二、遇到的问题

       对于查询不到信息时,弹出“没有该用户的信息"提示框时始终无法弹出,后来查询,需要界面的代码获

                     <script type="text/javascript">

                   alert("<%=request.getAttribute("message")%>");
              </script>
    三、明日计划
    明天继续学习Javaweb
  • 相关阅读:
    jQury+Ajax与C#后台交换数据
    loadrunner 测试问题汇总
    Loadrunner脚本学习总结
    sar命令详解
    用sar进行CPU利用率的分析
    centos7-sar工具的安装过程及其简单应用
    shell if [ -d filename]
    shell脚本自带变量的含义
    Sublime Text2使用规则
    selenium grid结构图
  • 原文地址:https://www.cnblogs.com/wmdww/p/14157472.html
Copyright © 2011-2022 走看看