问题描述:
在计算机主机(Mainframe)中,只需要按下主机的开机按钮(on()),即可调用其他硬件设备和软件的启动方法 ,如内存(Memory)的自检(check())、CPU的运行(run())、硬盘(HardDisk)的读取(read())、操作系统(OS)的载入(load()),如果某一过程发生错误则计算机启动失败。
类图:

C++代码:
#include<iostream>
using namespace std;
class Memory {
public:
bool check() {
cout<<"内存检查成功"<<endl;
return 1;
}
};
class Cpu {
public:
bool run() {
cout<<"CPU运行正常"<<endl;
return 1;
}
};
class HardDisk {
public:
bool read() {
cout<<"硬盘读入成功"<<endl;
return 1;
}
};
class OS {
public:
bool load() {
cout<<"操作系统载入正常"<<endl;
return 1;
}
};
class MainFrame {
private:
Memory memory;
Cpu cpu;
HardDisk hd;
OS os;
public:
MainFrame(){}
void start() {
if(memory.check()&&cpu.run()&&hd.read()&&os.load()){
cout<<"*****电脑启动成功*****"<<endl;
}else{
cout<<"电脑启动失败"<<endl;
}
}
};
void main()
{
MainFrame mf;
mf.start();
}
运行结果:

浙公网安备 33010602011771号