C++第四章课后习题4-19

定义一个CPU类

复制代码
 1 #include <iostream>
 2 using namespace std;
 3 enum Core{
 4     Single,Dual,Quad
 5 };
 6 enum Words{
 7     Bits32,Bits64
 8 };
 9 enum HyperThread{
10     Support,Notsupport
11 };
12 class CPU{
13     public:
14         CPU(long int frequense,Core type,Words length,HyperThread mode):
15             frequense(frequense),CoreType(type),Wordlen(length),mode(mode){
16             }
17         void show();
18     private:
19         unsigned frequense:32;
20         Core CoreType:3;
21         Words Wordlen:2;
22         HyperThread mode:2;
23 };
24 void CPU::show()
25 {
26     cout<<"frequense"<<frequense<<endl;
27     cout<<"core:";
28     switch((unsigned) CoreType){
29         case Single: cout<<"Single-core"<<endl;break;
30         case Dual: cout<<"Dual-core"<<endl;break;
31         case Quad: cout<<"Qual-core"<<endl;break;
32     }
33     cout<<"words:";
34     switch((unsigned) Wordlen){
35         case Bits32: cout<<"32bits len"<<endl;break;
36         case Bits64: cout<<"64bits len"<<endl;break;
37     }
38     cout<<"Hyperthread:";
39     switch((unsigned) mode){
40         case Support: cout<<"support Hyper-Thread"<<endl;break;
41         case Notsupport: cout<<"not support Hyper-Thread"<<endl;break;
42     }
43 }
44 int main()
45 {
46     CPU c(3000000000UL,Quad,Bits64,Support);
47     cout<<"size of Class CPU:"<<sizeof(CPU)<<endl;
48     c.show();
49 }
复制代码

 

posted @   新晋软工小白  阅读(13)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示