123 lines
2.6 KiB
C++
123 lines
2.6 KiB
C++
#include "combination.hpp"
|
||
|
||
bool ComputerComponent::isComposite()
|
||
{
|
||
return false;
|
||
}
|
||
|
||
void ComputerComponent::startup(string indent)
|
||
{
|
||
cout << indent << m_name << " " << "准备开始工作" << endl;
|
||
}
|
||
|
||
void ComputerComponent::shutdown(string indent)
|
||
{
|
||
cout << indent << m_name << " " << "即将结束工作" << endl;
|
||
}
|
||
|
||
void CPU::showInfo(string indent)
|
||
{
|
||
cout << indent << "CPU:" << indent << ",可以进行高速运算。" << endl;
|
||
}
|
||
|
||
void MemoryCard::showInfo(string indent)
|
||
{
|
||
cout << indent << "内存:" << indent << ",可以缓存数据,读写速度快。" << endl;
|
||
}
|
||
|
||
void HardDisk::showInfo(string indent)
|
||
{
|
||
cout << indent << "硬盘:" << indent << ",可以永久存储数据,存储容量大。" << endl;
|
||
}
|
||
|
||
void GraphicsCard::showInfo(string indent)
|
||
{
|
||
cout << indent << "显卡:" << indent << ",可以高速计算和处理图形图像。" << endl;
|
||
}
|
||
|
||
void Battery::showInfo(string indent)
|
||
{
|
||
cout << indent << "电源:" << indent << ",可以持续给主板和外接配件供电。" << endl;
|
||
}
|
||
|
||
void Fan::showInfo(string indent)
|
||
{
|
||
cout << indent << "风扇:" << indent << ",辅助CPU散热。" << endl;
|
||
}
|
||
|
||
void Displayer::showInfo(string indent)
|
||
{
|
||
cout << indent << "显示器:" << indent << ",负责内容的显示。" << endl;
|
||
}
|
||
|
||
void ComputerCompsite::showInfo(string indent)
|
||
{
|
||
cout << m_name << ",由以下部分组成:" << endl;
|
||
vector<ComputerComponent*>::iterator iter;
|
||
for (iter = m_components.begin(); iter != m_components.end(); iter++)
|
||
{
|
||
(*iter)->showInfo(indent);
|
||
}
|
||
}
|
||
|
||
bool ComputerCompsite::isComposite()
|
||
{
|
||
return true;
|
||
}
|
||
|
||
void ComputerCompsite::addComponent(ComputerComponent* component)
|
||
{
|
||
m_components.push_back(component);
|
||
}
|
||
|
||
void ComputerCompsite::removeComponent(ComputerComponent* component)
|
||
{
|
||
vector<ComputerComponent*>::iterator iter = find(m_components.begin(), m_components.end(), component);
|
||
if (iter != m_components.end())
|
||
{
|
||
m_components.erase(iter);
|
||
}
|
||
}
|
||
|
||
void ComputerCompsite::startup(string indent)
|
||
{
|
||
ComputerComponent::startup(indent);
|
||
indent += "\t";
|
||
|
||
vector<ComputerComponent*>::iterator iter;
|
||
for (iter = m_components.begin(); iter != m_components.end(); iter++)
|
||
{
|
||
(*iter)->startup();
|
||
}
|
||
}
|
||
|
||
void ComputerCompsite::shutdown(string indent)
|
||
{
|
||
ComputerComponent::shutdown(indent);
|
||
indent += "\t";
|
||
|
||
vector<ComputerComponent*>::iterator iter;
|
||
for (iter = m_components.begin(); iter != m_components.end(); iter++)
|
||
{
|
||
(*iter)->shutdown();
|
||
}
|
||
}
|
||
|
||
void Mainboard::showInfo(string indent)
|
||
{
|
||
cout << indent << "主板:";
|
||
ComputerCompsite::showInfo(indent);
|
||
}
|
||
|
||
void ComputerCase::showInfo(string indent)
|
||
{
|
||
cout << indent << "机箱:";
|
||
ComputerCompsite::showInfo(indent);
|
||
}
|
||
|
||
void Computer::showInfo(string indent)
|
||
{
|
||
cout << indent << "电脑:";
|
||
ComputerCompsite::showInfo(indent);
|
||
}
|