#include <iostream>
#include<string>
using namespace std;
typedef enum HardwareLEVELenum
{
DefaultLevel,
Bad,
Normal,
Good
}HardwareLEVEL;
class PC
{
public:
void SetPC(string level){_level=level;}
void SetCPU(HardwareLEVEL CPU){ _CPU = CPU; }
void SetGPU(HardwareLEVEL GPU){ _GPU = GPU; }
void SetMotherboard(HardwareLEVEL Motherboard){ _Motherboard = Motherboard; }
void SetHarddisk(HardwareLEVEL Harddisk){ _Harddisk = Harddisk; }
void SetRAM(HardwareLEVEL RAM){ _RAM = RAM; }
void SetPower(HardwareLEVEL Power){ _Power = Power; }
void ShowPC()
{
cout<<"I'm a "<<_level<<endl;
cout<<"HardWare Level(1~3)"<<endl;
cout<<"CPU:"<<_CPU<<endl;
cout<<"GPU:"<<_GPU<<endl;
cout<<"Motherboard:"<<_Motherboard<<endl;
cout<<"Harddisk:"<<_Harddisk<<endl;
cout<<"RAM:"<<_RAM<<endl;
cout<<"Power:"<<_Power<<endl;
cout<<endl;
}
private:
string _level;
HardwareLEVEL _CPU;
HardwareLEVEL _GPU;
HardwareLEVEL _Motherboard;
HardwareLEVEL _Harddisk;
HardwareLEVEL _RAM;
HardwareLEVEL _Power;
};
class Builder
{
public:
virtual void BuildPC(){}
virtual void BuildCPU(){}
virtual void BuildGPU(){}
virtual void BuildMotherboard(){}
virtual void BuildHarddisk(){}
virtual void BuildRAM(){}
virtual void BuildPower(){}
virtual PC *GetPC(){ return NULL; }
};
class ServerPCBuilder : public Builder
{
public:
ServerPCBuilder(){ _ServerPC = new PC(); }
void BuildPC(){_ServerPC->SetPC("ServerPC");};
void BuildCPU(){ _ServerPC->SetCPU(Good); }
void BuildGPU(){ _ServerPC->SetGPU(Normal); }
void BuildMotherboard(){ _ServerPC->SetMotherboard(Good); }
void BuildHarddisk(){ _ServerPC->SetHarddisk(Good); }
void BuildRAM(){ _ServerPC->SetRAM(Good); }
void BuildPower(){ _ServerPC->SetPower(Good); }
PC *GetPC(){ return _ServerPC; }
private:
PC *_ServerPC;
};
class GamePCBuilder : public Builder
{
public:
GamePCBuilder(){ _GamerPC = new PC(); }
void BuildPC(){_GamerPC->SetPC("GamePC");};
void BuildCPU(){ _GamerPC->SetCPU(Good); }
void BuildGPU(){ _GamerPC->SetGPU(Good); }
void BuildMotherboard(){ _GamerPC->SetMotherboard(Normal); }
void BuildHarddisk(){ _GamerPC->SetHarddisk(Normal); }
void BuildRAM(){ _GamerPC->SetRAM(Good); }
void BuildPower(){ _GamerPC->SetPower(Normal); }
PC *GetPC(){ return _GamerPC; }
private:
PC *_GamerPC;
};
class OfficePCBuilder : public Builder
{
public:
OfficePCBuilder(){ _OfficePC = new PC(); }
void BuildPC(){_OfficePC->SetPC("OfficePC");};
void BuildCPU(){ _OfficePC->SetCPU(Normal); }
void BuildGPU(){ _OfficePC->SetGPU(Bad); }
void BuildMotherboard(){ _OfficePC->SetMotherboard(Normal); }
void BuildHarddisk(){ _OfficePC->SetHarddisk(Normal); }
void BuildRAM(){ _OfficePC->SetRAM(Normal); }
void BuildPower(){ _OfficePC->SetPower(Normal); }
PC *GetPC(){ return _OfficePC; }
private:
PC *_OfficePC;
};
class Director
{
public:
Director(Builder *builder) { m_Builder = builder; }
void CreatePC();
private:
Builder *m_Builder;
};
void Director::CreatePC()
{
m_Builder->BuildPC();
m_Builder->BuildCPU();
m_Builder->BuildGPU();
m_Builder->BuildMotherboard();
m_Builder->BuildHarddisk();
m_Builder->BuildMotherboard();
m_Builder->BuildHarddisk();
m_Builder->BuildRAM();
m_Builder->BuildPower();
}
int main(int argc, char *argv[])
{
Builder *builderPC1 = new ServerPCBuilder();
Director directorPC1(builderPC1);
directorPC1.CreatePC();
PC *PC1 = builderPC1->GetPC();
Builder *builderPC2 = new GamePCBuilder();
Director directorPC2(builderPC2);
directorPC2.CreatePC();
PC *PC2 = builderPC2->GetPC();
Builder *builderPC3 = new OfficePCBuilder();
Director directorPC3(builderPC3);
directorPC3.CreatePC();
PC *PC3 = builderPC3->GetPC();
if (PC1 == NULL)
return 0;
if (PC2 == NULL)
return 0;
if (PC3 == NULL)
return 0;
PC1->ShowPC();
PC2->ShowPC();
PC3->ShowPC();
delete PC1;
PC1 = NULL;
delete builderPC1;
builderPC1 = NULL;
delete PC2;
PC2 = NULL;
delete builderPC2;
builderPC2 = NULL;
delete PC3;
PC1 = NULL;
delete builderPC3;
builderPC3 = NULL;
return 0;
};