#include <iostream>
#include <string>
using namespace std;
class CPU{
public:
virtual void cal() = 0;
};
class InterCPU: public CPU{
void cal(){
cout<< "Inter厂商的CPU开始进行计算!" <<endl;
}
};
class AMDCPU: public CPU{
void cal(){
cout<< "AMD厂商的CPU开始进行计算!" <<endl;
}
};
class VideoCard{
public:
virtual void display() = 0;
};
class InterVideoCard: public VideoCard{
void display(){
cout<< "Inter厂商的VideoCard开始进行显示!" <<endl;
}
};
class Memory{
public:
virtual void storge() = 0;
};
class InterMemory: public Memory{
void storge(){
cout<< "Inter厂商的Memory开始进行存储!" <<endl;
}
};
class Computer{
public:
Computer(CPU* cpu, VideoCard* vc, Memory* mem)
{
m_cpu = cpu;
m_vc = vc;
m_mem = mem;
}
void work(){
m_cpu->cal();
m_vc->display();
m_mem->storge();
}
~Computer(){
if(m_cpu != NULL){
delete m_cpu;
m_cpu = NULL;
}
if(m_vc != NULL){
delete m_vc;
m_vc = NULL;
}
if(m_mem != NULL){
delete m_mem;
m_mem = NULL;
}
}
private:
CPU* m_cpu;
VideoCard* m_vc;
Memory* m_mem;
};
void test(){
CPU* cpu = new InterCPU;
CPU* cpu1 = new AMDCPU;
VideoCard* videoCard = new InterVideoCard;
Memory* memory = new InterMemory;
Computer* computer01 = new Computer(cpu, videoCard, memory);
computer01->work();
delete computer01;
}
int main()
{
test();
return 0;
}