#include using namespace std; // CPU等级:枚举型声明 enum CPU_Rank { P1 = 1, P2, P3, P4, P5, P6, P7 }; // CPU类的声明 class CPU { private: CPU_Rank rank; int frequency; // 频率 (MHz) float voltage; // 电压 (V) public: // 构造函数 CPU(CPU_Rank r, int f, float v) : rank(r), frequency(f), voltage(v) { cout << "构造了一个CPU!" << endl; } // 析构函数 ~CPU() { cout << "析构了一个CPU!" << endl; } // 成员函数:run void run() { cout << "CPU开始运行!" << endl; } // 成员函数:stop void stop() { cout << "CPU停止运行!" << endl; } // 输出等级 void printRank() { cout << "等级为:" << rank << endl; } }; // 测试 int main() { int rank1, rank2; // 输入两个CPU的等级 cin >> rank1 >> rank2; // 创建两个CPU对象 CPU cpu1(static_cast(rank1), 2400, 1.2); CPU cpu2(static_cast(rank2), 3200, 1.3); // 运行和停止第一个CPU cpu1.run(); cpu1.printRank(); cpu1.stop(); // 运行和停止第二个CPU cpu2.run(); cpu2.printRank(); cpu2.stop(); return 0; }