FORESTAPE
学海舟舟_林
2017-11-04 15:24

C++关于类的一个小问题,怎么改,急~~~

2
  • c++

图片说明#include
using namespace std;
enum CPU_Rank{P1=1,P2,P3,P4,P5,P6,P7};

class CPU{ //CPU类

private:
CPU_Rank rank;
int frequency;
float voltage;

public:
void run();
void stop();

CPU(CPU_Rank a,int b,float c){
    rank=a;
    cout<<"构造成员rank"<<endl;
    frequency=b;
    cout<<"构造成员frequency"<<endl;
    voltage=c;
    cout<<"构造成员voltage"<<endl;
}
CPU();

};

void CPU::run(){
cout<<"成功构造一个CPU对象"<<endl;
}
void CPU::stop(){
cout<<"程序结束"<<endl;
system("pause");
}

class RAM{ //RAM类
public:
RAM(int a,int b,double c){
frequency=a;
size=b;
delay=c;
}
RAM();
private:
int frequency;
int size;
double delay;

};

class CDROM{ //CDROM类
public:
CDROM(int a,int b){
type=a;
speed=b;
}
CDROM();
private:
int type;
int speed;
};

class Computer{ //Computer类
public:
void run();
void stop();
Computer(CPU a,RAM b,CDROM c){
cpu=a;
ram=b;
cdrom=c;
}
private:
CPU cpu;
RAM ram;
CDROM cdrom;
};

void Computer::run(){
cout<<"构造了一个Computer对象"<<endl;
}

void Computer::stop(){
cout<<"停止..."<<endl;
system("pause");
}

int main(int argc,char *argv[]){
CPU cpu(P2,400,5);
RAM ram(1,2,3);
CDROM cdrom(4,7);
Computer computer(cpu,ram,cdrom);
computer.run();
computer.stop();
return 0;
}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答