码迷,mamicode.com
首页 > 其他好文 > 详细

shiyan66

时间:2015-04-23 19:38:42      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

  1 #include<iostream>
  2 #include<string>
  3 #include<algorithm>
  4 using namespace std;
  5 enum CPUrank{i3,i5,i7};
  6 enum RAMrank{DDR,DDR2,DDR3};
  7 class CPU{
  8 public:
  9     CPU(float f,int  pin,CPUrank  r):f(f),pin(pin),r(r){}
 10     float getft() const{
 11         return f;
 12     }
 13   int getpin() const{
 14       return pin;
 15   }
 16   CPUrank getrank() const{
 17       return r;
 18   }
 19   friend class COMPUTER;
 20 private:
 21     float f;
 22     int   pin;
 23     CPUrank  r;
 24 };
 25 class RAM{
 26 public:
 27     RAM(float f,int   Memory,RAMrank  r):f(f),Memory(Memory),r(r){}
 28     float    getft() const{
 29         return f;
 30     }
 31   int getMemory() const{
 32       return Memory;
 33   }
 34   RAMrank  getrank() const{
 35       return r;
 36   }
 37 friend class COMPUTER;
 38 private:
 39     float f;
 40     int   Memory;
 41     RAMrank  r;
 42 
 43 };
 44 class COMPUTER{
 45 public:
 46     COMPUTER(CPU a,RAM b,float prace,string pinpai):a(a),b(b),price(price),pinpai(pinpai){}
 47     COMPUTER(const CPU &a,const RAM &b):a(a),b(b){}
 48     void  Getcomputer() const{
 49         cout<<"CPU电压为"<<a.f<<endl;
 50         cout<<"CPU频率为"<<a.pin<<endl;
 51         cout<<"CPU频率为";
 52         switch(a.r){
 53         case i3: cout<<"i3"<<endl;break;
 54         case i5: cout<<"i5"<<endl;break;
 55         case i7: cout<<"i7"<<endl;break;
 56         }
 57        cout<<"RAM电压为"<<b.f<<endl;
 58         cout<<"CPU频率为"<<b.Memory<<endl;
 59         cout<<"CPU频率为";
 60         switch(b.r){
 61         case DDR: cout<<"DDR"<<endl;break;
 62         case DDR2: cout<<"DDR2"<<endl;break;
 63         case DDR3: cout<<"DDR3"<<endl;break;
 64         }
 65         cout<<"价格为"<<price<<endl;
 66         cout<<"品牌为"<<pinpai<<endl;
 67     }
 68     void Setcpu(const CPU m){ //{直接访问设置cpu的数据成员}
 69           a=m;
 70           }
 71     void Setram(const RAM t){ //{直接访问设置ram的数据成员}
 72          b=t;
 73     }
 74 void Setprice(float price2){     //设置价格price。
 75        price=price2;
 76 }
 77        float Getprice(){//得到价格price。
 78            return price;
 79        }
 80        static int pp(){
 81            count++;
 82            return count;
 83        }
 84 private:
 85 CPU a;
 86 RAM b;
 87 float price;
 88 string pinpai;
 89 static int count;
 90 };
 91 int COMPUTER::count=0;
 92 int main(){
 93      CPU a(100,34,i5);
 94      RAM b(1000,45,DDR);
 95      COMPUTER computer(a,b);
 96      computer.Getcomputer();
 97      const CPU a1(200,577,i7);
 98      const RAM b1(1000,400,DDR2);
 99      COMPUTER computer2(a1,b1);
100      computer2.Getcomputer();
101      cout<<computer2.pp<<endl;
102      return 0;
103 }

 

shiyan66

标签:

原文地址:http://www.cnblogs.com/qianxunke/p/4451306.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!