C++每日打卡

创建CPU

定义一个CPU类,包含等级(Rank)、频率(frequency)、电压(voltage)等属性。其中,rank为枚举类型CPU__Rank,定义为enum CPU_Rank{P1=1,P2,P3,P4,P5,P6,P7},frequency为单位是MHz的整型数,voltage为浮点型的电压值。

 

#include<iostream>
using namespace std;

enum CPU_Rank{P1=1,P2,P3,P4,P5,P6,P7};

class CPU
{
public:
CPU()
{
Rank=1;
frequency=2;
voltage=100;
cout<<"create a CPU!"<<endl;
}
CPU(CPU_Rank rank,int f,double v)
{
Rank=rank;
frequency=f;
voltage=v;
cout<<"create a CPU!"<<endl;
}
CPU(CPU &c)
{
Rank=c.Rank;
frequency=c.frequency;
voltage=c.voltage;
cout<<"copy create a CPU!"<<endl;
}
void showinfo()
{
cout<<"rank:"<<Rank<<endl;
cout<<"frequency:"<<frequency<<endl;
cout<<"voltage:"<<voltage<<endl;
}
~CPU()
{
cout<<"destruct a CPU!"<<endl;
}
private:
int Rank;
int frequency;
double voltage;
};

int main()

{

CPU a(P6,3,300);

cout<<"cpu a's parameter"<<endl;

a.showinfo(); //显示性能参数

CPU b;

cout<<"cpu b's parameter"<<endl;

b.showinfo(); //显示性能参数

CPU c(a);

cout<<"cpu c's parameter"<<endl;

c.showinfo(); //显示性能参数

}

 

 
posted @ 2023-04-19 18:40  涨涨涨张  阅读(18)  评论(0编辑  收藏  举报