编写一个名为CPU的类,描述一个CPU 的以下信息:时钟频率,最大不会超过3000MHz;字长,可以是32位或64位;核数,可以是单核,双核或四核;是否支持超线程。各项信息要求使用位域来表示。通过输出sizeof(CPU)来观察该类所占的字节数。
1 #include <iostream> 2 #include <string> 3 #include <stdio.h> 4 using namespace std; 5 6 enum word_len{_32bit = 32, _64bit = 64}; 7 enum nuclear_num{one = 1, two = 2, four = 4}; 8 enum Hyper_thread{_true = 1, _false = 0}; 9 10 class CPU{ 11 private: 12 int clock_frequency:29; 13 word_len wl:7; 14 nuclear_num num:3; 15 Hyper_thread hthread:1; 16 public: 17 CPU(){} 18 CPU(int c, word_len wl = _32bit, nuclear_num num = two, Hyper_thread hthread = _false): 19 clock_frequency(c), wl(wl), num(num), hthread(hthread){} 20 ~CPU(){} 21 void show(); 22 23 }; 24 void inline CPU::show(){ 25 cout<<"时钟频率:"<<clock_frequency<<"HZ"<<endl<<"字长:"<<wl<<"位"<<endl<<"核数:"<<num<<"核"<<endl<<"是否支持超线程:"; 26 if(hthread == 1) cout<<"是"; 27 else cout<<"否"; 28 cout<<endl; 29 } 30 31 int main(){ 32 CPU cp(323232,_64bit,four,_true); 33 cp.show(); 34 cout<<sizeof(cp); 35 return 0; 36 }
标签:thread,19,nuclear,wl,num,CPU,hthread From: https://www.cnblogs.com/YUZE2001/p/17212854.html