定义一个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 }
标签:Core,Words,19,enum,mode,课后,习题,CPU,frequense From: https://www.cnblogs.com/Lyh3012648079/p/17360372.html