首页 > 其他分享 >软件实验设计15

软件实验设计15

时间:2022-10-21 18:34:17浏览次数:44  
标签:15 name request public ShoppingRequest 实验设计 软件 Leader string

实验15:职责链模式

[实验任务一]:财务审批

某物资管理系统中物资采购需要分级审批,主任可以审批1万元及以下的采购单,部门经理可以审批5万元及以下的采购单,副总经理可以审批10万元及以下的采购单,总经理可以审批20万元及以下的采购单,20万元以上的采购单需要开职工大会确定。现用职责链模式设计该系统。

直接放源码:

#include <iostream>
#include <string>
using namespace std;

class ShoppingRequest
{
public:
    ShoppingRequest(string shoppingReaso,double billMone){
        ShoppingReason=shoppingReaso;
        billMoney=billMone;
    }
    string getShoppingReason() {
        return ShoppingReason;
    }
    void setShoppingReason(string shoppingReaso) {
        ShoppingReason = shoppingReaso;
    }

    double getBillMoney() {
        return billMoney;
    }

    void setBillMoney(double billMone) {
        billMoney = billMone;
    }
private:
    string ShoppingReason;
    double billMoney;
};


class Leader
{
public:
    Leader(string nam){
        name=nam;
    }
    void setSuccessor(Leader* successo){
        successor=successo;
    }
    virtual void handleRequest(ShoppingRequest* request) = 0;
protected:
    string name;
    Leader* successor;
};


class Director : public  Leader   //PM:Project manager项目经理
{
public:
    Director(string name):Leader(name){};
    void handleRequest(ShoppingRequest* request){
        if(request->getBillMoney()<10000.00){
            cout <<"主任"<<name<<"处理物资采集:"<<
                 request->getShoppingReason()<<
                 ",批准采购资金为:"<<request->getBillMoney()<<"RMB"<< endl;
        }else{
            successor->handleRequest(request);
        }
    }
};

class DepartmentManager : public  Leader   //PM:Project manager项目经理
{
public:
    DepartmentManager(string name):Leader(name){};
    void handleRequest(ShoppingRequest* request){
        if(request->getBillMoney()<50000.00){
            cout <<"部门经理"<<name<<"处理物资采集:"<<
                 request->getShoppingReason()<<
                 ",批准采购资金为:"<<request->getBillMoney()<<"RMB"<< endl;
        }else{
            successor->handleRequest(request);
        }
    }
};

class ViceManager : public  Leader   //PM:Project manager项目经理
{
public:
    ViceManager(string name):Leader(name){};
    void handleRequest(ShoppingRequest* request){
        if(request->getBillMoney()<100000.00){
            cout <<"副经理"<<name<<"处理物资采集:"<<
                 request->getShoppingReason()<<
                 ",批准采购资金为:"<<request->getBillMoney()<<"RMB"<< endl;
        }else{
            successor->handleRequest(request);
        }
    }
};

class GeneralManager : public  Leader   //PM:Project manager项目经理
{
public:
    GeneralManager(string name):Leader(name){};
    void handleRequest(ShoppingRequest* request){
        if(request->getBillMoney()<200000.00){
            cout <<"总经理"<<name<<"处理物资采集:"<<
                 request->getShoppingReason()<<
                 ",批准采购资金为:"<<request->getBillMoney()<<"RMB"<< endl;
        }else{
            cout <<"董事会处理物资采集:"<<
                 request->getShoppingReason()<<
                 ",批准采购资金为:"<<request->getBillMoney()<<"RMB"<< endl;
        }

    }
};

int main()
{
    Leader* l1,* l2,* l3,* l4;
    l1=new Director("张三");
    l2=new DepartmentManager("李四");
    l3=new ViceManager("王五");
    l4=new GeneralManager("赵六");
    l1->setSuccessor(l2);
    l2->setSuccessor(l3);
    l3->setSuccessor(l4);
    ShoppingRequest* s1=new ShoppingRequest("买a4纸",1000.00);
    ShoppingRequest* s2=new ShoppingRequest("买桌子",30000.00);
    ShoppingRequest* s3=new ShoppingRequest("买电脑",90000.00);
    ShoppingRequest* s4=new ShoppingRequest("买机器",150000.00);
    ShoppingRequest* s5=new ShoppingRequest("收购公司",1000000.00);
    l1->handleRequest(s1);
    cout<<"--------------------------------------------"<<endl;
    l1->handleRequest(s2);
    cout<<"--------------------------------------------"<<endl;
    l1->handleRequest(s3);
    cout<<"--------------------------------------------"<<endl;
    l1->handleRequest(s4);
    cout<<"--------------------------------------------"<<endl;
    l1->handleRequest(s5);
    cout<<"--------------------------------------------"<<endl;
}

  

标签:15,name,request,public,ShoppingRequest,实验设计,软件,Leader,string
From: https://www.cnblogs.com/lyf3701/p/16814459.html

相关文章

  • Android软件中嵌入地图之一:Sogou地图
          在App中加入地图功能真是让人揪结,Google地图功能强大,但是有些国内的手机厂商去掉了手机系统中Google地图的相关库,所以这类机型将无法安装调用了Google地图的软......
  • Fedora15 安装mplayer以及添加解码器播放wmv(原创)
    Mplayer称为世界上万能的播放器,对于Mplayer简单的操作界面,Mplayer对所有流媒体支持都让我对万能的播放器mplayer一见钟情,最近把我的fedora升级到Fedora14,又得重新​......
  • 设置开机启动软件
    1、打开我的电脑,在地址栏中输入C:\ProgramData\Microsoft\Windows\StartMenu\Programs\StartUp,回车,进入该文件夹,这是启动项所在文件夹。2、将需要添加开机启动的文件或......
  • ST/意法STTH1506DPI车规FRD,原厂渠道ASEMI代理
    编辑-ZST/意法STTH1506DPI车规FRD参数:型号:STTH1506DPI重复峰值反向电压(VRRM):600V平均正向电流(IF):15A浪涌非重复正向电流(IFSM):130A储存温度范围(Tstg):-65to﹢150℃工作结......
  • 动动手指,这段程序性能提升2s~15s
    性能优化说明:判断数据表里是否有数据,用limit1/top1取代求count近期,数据中心系统负荷大,mysql服务器的CPU动辄高达90%以上。代码和数据表存在很大优化空间。这里分享一......
  • 直播软件开发,元素水平垂直居中
    直播软件开发,元素水平垂直居中 position:absolute; top:45%; left:50%; transform:translate(-50%,-50%);​以上就是直播软件开发,元素水平垂直居中,更多内......
  • 【755】MacBook修改软件默认语言
    参考:LetOutlookforMacautomaticallydetectandspellchecklanguagesinyouremails左上角苹果图标》系统偏好设置》语言与地区》通用(修改电脑的语言)App(针对具体的......
  • ARC150D - Removing Gacha (树上期望)
    Link题意:给一棵\(n\)个节点的树,称一个点是好的,当且仅当它到根的路径上都是黑色(包括自己)。每次在不好的节点中随机选一个把它涂成黑色(不管原来它是否是白的),直到所有点都......
  • centos7 中bamtools软件的安装
     方法1、编译安装001、系统[liujiaxin01@localhostsoftware]$cat/etc/redhat-releaseCentOSLinuxrelease7.6.1810(Core) 002、下载bamtools软件安装包w......
  • NOIP2015普及组复赛参考解析
    目录P2669[NOIP2015普及组]金币P2670[NOIP2015普及组]扫雷游戏P2671[NOIP2015普及组]求和P2672[NOIP2015普及组]推销员题目传送P2669[NOIP2015普及组]金......