问题求教!
#include <string>#include <iostream>
using namespace std;
class PurchaseRequest {
public:
double Amount; // 一个采购的金额
int Number; // 采购单编号
string Purpose; // 采购目的
};
class Approver { // 审批者类
public:
Approver(){ successor = NULL; }
virtual void ProcessRequest(PurchaseRequest aRequest)
{
if (successor != NULL){ successor->ProcessRequest(aRequest); }
}
void SetSuccessor(Approver *aSuccesssor){ successor = aSuccesssor; }
private:
Approver* successor;
};
class Congress : public Approver {
public:
void ProcessRequest(PurchaseRequest aRequest){
if(aRequest.Amount >= 500000){ /* 决定是否审批的代码省略 */ }
else Approver::ProcessRequest(aRequest);
}
};
class Director : public Approver {
public:
void ProcessRequest(PurchaseRequest aRequest){ /* 此处代码省略 */ }
};
class President : public Approver {
public:
void ProcessRequest(PurchaseRequest aRequest){ /* 此处代码省略 */ }
};
class VicePresident : public Approver {
public:
void ProcessRequest(PurchaseRequest aRequest){ /* 此处代码省略 */ }
};
void main(){
Congress Meeting;
VicePresident VPre;
Director Dir;
President Pre;
// 构造责任链
Meeting.SetSuccessor(NULL);
VPre.SetSuccessor(&Pre);
Pre.SetSuccessor(&Meeting);
Dir.SetSuccessor(&VPre);
PurchaseRequest aRequest; // 构造一采购审批请求
cin >> aRequest.Amount; // 输入采购请求的金额
Dir.ProcessRequest(aRequest); // 开始审批
return ;
}
07年下半年软设最后一题,这个搞不懂了,不知怎么传来传去的,希望那位高手能解答一下,万分感激了!