栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

黑马C++课程141P-142P电脑组装实现

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

黑马C++课程141P-142P电脑组装实现

#include
#include
using namespace std;
//-------------------CPU--------------------
//抽象CPU类
class CPU
{
public:
    virtual void calculate() = 0;
    virtual ~CPU() = 0;
};
CPU::~CPU() {};
class IntelCPU :public CPU
{
public:
    IntelCPU() {};
    virtual void calculate()
    {
        cout << "IntelCUP is running.." << endl;
    }
};
class LenovoCPU :public CPU
{
public:
    virtual void calculate()
    {
        cout << "LenovoCUP is running.." << endl;
    }
};
//-------------------显卡--------------------
//抽象显卡类
class VideoCard
{
public:
    virtual void display() = 0;
    virtual ~VideoCard() = 0;
};
VideoCard::~VideoCard() {};
class IntelVideoCard :public VideoCard
{
public:
    virtual void display()
    {
        cout << "Intel VideoCard is displaying.." << endl;
    }
};
class LenovoVideoCard :public VideoCard
{
public:
    virtual void display()
    {
        cout << "Lenovo VideoCard is displaying.." << endl;
    }
};
//-------------------内存--------------------
//抽象内存类
class Memory
{
public:
    virtual void storage() = 0;
    virtual ~Memory() = 0;
};
Memory::~Memory() {};
class IntelMemory :public Memory
{
public:
    virtual void storage()
    {
        cout << "IntelMemory is storaging..." << endl;
    }
};
class LenovoMemory :public Memory
{
public:
    virtual void storage()
    {
        cout << "LenovoMemory is storaging..." << endl;
    }
};
//--------------------装电脑!-----------------------
//电脑类
class Computer
{
public:
    Computer() {};
    Computer(CPU* p1, VideoCard* p2, Memory* p3)
    {
        m_p1 = p1;
        m_p2 = p2;
        m_p3 = p3;
    }
    void doCalculate()
    {
        m_p1->calculate();
    }
    void doDisplay()
    {
        m_p2->display();
    }
    void dostorage()
    {
        m_p3->storage();
    }
    void doWork()
    {
        doCalculate();
        doDisplay();
        dostorage();
        cout << endl;
    };
    CPU* m_p1;
    VideoCard* m_p2;
    Memory* m_p3;
};
//------------------test---------------------
void test01()
{
    Computer c1(new IntelCPU, new IntelVideoCard, new IntelMemory);
    Computer c2(new LenovoCPU, new LenovoVideoCard, new LenovoMemory);
    Computer c3(new IntelCPU, new LenovoVideoCard, new LenovoMemory);
    c1.doWork();
    c2.doWork();
    c3.doWork();
}
//-------------------------------------------
int main()
{
    test01();
    return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/656337.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号