LuBoiSyn / Lb

6
0 stars 0 forks source link

b #17

Open LuBoiSyn opened 1 year ago

LuBoiSyn commented 1 year ago

include

using namespace std; class Strategy { public: virtual void crypy() = 0;

}; class AES :public Strategy {

public: virtual void crypy() { cout << “AES加密算法 ” << endl; } }; class DES :public Strategy {

public: virtual void crypy() { cout << ” DES加密算法” << endl; } }; class Context { public: void setStrategy(Strategy *strategy) { this->strategy = strategy; } void myoperator() { strategy->crypy(); }

private: Strategy strategy; }; void main() { // DES des = new DES; des->crypy(); delete des; Strategystrategy = NULL; strategy= new DES; Context context = new Context; context->setStrategy(strategy); context->myoperator(); delete strategy; delete context; system(“pause”); return;

}

LuBoiSyn commented 1 year ago

include

using namespace std;

include”string”

class Person { public: Person(string name, int sex, int condi) { m_name=name; m_sex=sex; m_condi = condi;

} string getName() { return m_name; } int getSex() { return m_sex; } int getCondi() { return m_condi; } protected: string m_name; int m_sex; int m_condi; }; class Women :public Person { public: Women(string name, int sex, int condi) :Person(name, sex, condi) {

} virtual void getParter(Person*p) { if (this->m_sex == p->getSex()) { cout << “我不是同性恋..(这里就是问题研究,不带任何感情色彩)” << endl; } if (this->getCondi() == p->getCondi()) { cout << this->getName() << “和” << p->getName() << “绝配” << endl;

} else { cout << this->getName() << “和” << p->getName() << “bu配” << endl; } } }; class Man :public Person { public: Man(string name, int sex, int condi) :Person(name, sex, condi) {

} virtual void getParter(Person*p) { if (this->m_sex == p->getSex()) { cout << “我不是同性恋..(这里就是问题研究,不带任何感情色彩)” << endl; } if (this->getCondi() == p->getCondi()) { cout << this->getName() << “和” << p->getName() << “绝配” << endl;

} else { cout << this->getName() << “和” << p->getName() << “bu配” << endl; } } }; void main() { Person xiaofang = new Women(“小芳”, 2, 5); Person zhangsan = new Man(“张三”, 1, 4); Person *lisi = new Man(“李四”, 2, 5); xiaofang->getParter(zhangsan); xiaofang->getParter(lisi); system(“pause”); return; }

LuBoiSyn commented 1 year ago

include

using namespace std;

include”string”

class Person { public: Person(string name, int sex, int condi, Mediator*m) { m_name = name; m_sex = sex; m_condi = condi; mediator = m;

} string getName() { return m_name; } int getSex() { return m_sex; } int getCondi() { return m_condi; } protected: string m_name; int m_sex; int m_condi; Mediator mediator; }; class Mediator//中介这的抽象父类 { public: virtual void getParter() = 0; void setMan(PersonpMan) { pMan = man; } void setWomen(PersonpMan) { pWomen = women; } public: virtual void getParter() { if (pWomen->getSex() == pMan->getSex()) { cout << “我不是同性恋..(这里就是问题研究,不带任何感情色彩)” << endl; } if (pWomen->getCondi() == pMan->getCondi()) { cout << pWomen->getName() << “和” << pMan->getName() << “绝配” << endl;

} else { cout << pWomen->getName() << “和” << pMan->getName() << “bu配” << endl; } } private: Person pWomen; Person pMan; };

class Women :public Person { public: Women(string name, int sex, int condi, Mediator*m) :Person(name, sex, condi,m) {

} public: virtual void getParter(Person*p) { mediator->setMan(p); mediator->setWomen(this); mediator->getParter();

} }; class Man :public Person { public: Man(string name, int sex, int condi, Mediator*m) :Person(name, sex, condi,m) {

} public: virtual void getParter(Person*p)

{

mediator->setMan(this); mediator->setWomen(p); mediator->getParter(); } }; void main() { Mediator m = new Mediator; Person xiaofang = new Women(“小芳”, 2, 5,m); Person zhangsan = new Man(“张三”, 1, 4,m); Person lisi = new Man(“李四”, 2, 5,m); xiaofang->getParter(zhangsan); xiaofang->getParter(lisi); system(“pause”); return; }