#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
enum CPU_Rank{ P1=1,P2,P3,P4,P5,P6,P7 };// 声明枚举类型 CPU_Rank p1-7递增
class CPU{
public:
CPU (CPU_Rank r, int f, float v)//构造函数
{
rank = r;
frequency = f;
voltage = v;
cout<< "创造了一个CPU"<<endl;
}
~CPU(){
cout<<"析构了一个CPU!"<< endl;
}
CPU_Rank GetRank() const {return rank;}//函数成员的外部接口 访问三个私有成员的接口
int GetFrequency() const { return frequency;}
float GetVolatage() const { return voltage;}
void SetRank(CPU_Rank r){rank = r;// 设置三个私有成员的接口
}
void SetFrequency(int f){ frequency = f;
}
void SetVoltage(float v){ voltage = v;
}
void Run(){
cout<< "CPU开始运行!"<<endl;
}
void Stop(){
cout<<"CPU停止运行!"<<endl;
}
private:
CPU_Rank rank;
int frequency;
float voltage;
};
int main(){
CPU A(P6,300,28); //声明了一个cpu的对象 并调用了三个参数的构造函数初始化
A.Run();
A.Stop();
return 0;
}
c++ 类与对象的声明使用 并观察构造和析构的执行过程
猜你喜欢
转载自blog.csdn.net/qq_41814721/article/details/82562131
今日推荐
周排行