第一天

1 .定义一个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{
    CPU_Rank Rank;
    int frequency;
    float voltage;
    public:
    CPU(CPU_Rank rank=P1,int f=2,float v=100)
:Rank(rank),frequency(f),voltage(v){
cout<<"create a CPU!\n";
}
CPU(const CPU&c){
Rank=c.Rank;
frequency=c.frequency;
voltage=c.voltage;
cout<<"copy create a CPU!\n";
}
~CPU(){
cout<<"destruct a CPU!\n";
}
void showinfo(){
cout<<"rank:"<<Rank<<endl;
cout<<"frequency:"<<frequency<<endl;
cout<<"voltage:"<<voltage<<endl;
}
};

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-17 21:45  chrisrmas、  阅读(27)  评论(0编辑  收藏  举报