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 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?