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
原文地址:https://www.cnblogs.com/wmdww/p/14157472.html