类,函数,声明.
#include "bits/stdc++.h"
using namespace std;
enum CPU_Rank{P1 = 1,P2,P3,P4,P5,P6,P7};
class CPU {
public:
CPU(CPU_Rank rank,int frequency,float voltnumber)
: rank(rank),frequency(frequency),voltnumber(voltnumber){//初始化列表
cout<< "CPU's constructor is called!" < }
~CPU() {//析构函数 清理对象资源,销毁对象
cout<< "CPU's destructor is called!" < }
void run(){
cout<<"I am working, my rank is " << rank
<< ", my frequency is " << frequency
<<", my voltnumber is " << fixed << setprecision(1) << voltnumber << "." << endl;
}
void stop(){
cout << "I stopped working!" << endl;
}
private://私有成员
CPU_Rank rank;
int frequency;
float voltnumber;
};
int main(){
int rank, frequency;
float voltnumber;
cin >> rank >> frequency >> voltnumber;
CPU cpu((CPU_Rank)rank,frequency,voltnumber);// 将整数转换为 CPU_Rank 类型
cpu.run();
cpu.stop();
// 对象销毁时,析构函数自动调用
return 0;
}
using namespace std;
enum CPU_Rank{P1 = 1,P2,P3,P4,P5,P6,P7};
class CPU {
public:
CPU(CPU_Rank rank,int frequency,float voltnumber)
: rank(rank),frequency(frequency),voltnumber(voltnumber){//初始化列表
cout<< "CPU's constructor is called!" <
~CPU() {//析构函数 清理对象资源,销毁对象
cout<< "CPU's destructor is called!" <
void run(){
cout<<"I am working, my rank is " << rank
<< ", my frequency is " << frequency
<<", my voltnumber is " << fixed << setprecision(1) << voltnumber << "." << endl;
}
void stop(){
cout << "I stopped working!" << endl;
}
private://私有成员
CPU_Rank rank;
int frequency;
float voltnumber;
};
int main(){
int rank, frequency;
float voltnumber;
cin >> rank >> frequency >> voltnumber;
CPU cpu((CPU_Rank)rank,frequency,voltnumber);// 将整数转换为 CPU_Rank 类型
cpu.run();
cpu.stop();
// 对象销毁时,析构函数自动调用
return 0;
}
全部评论
相关推荐