声明一个简单的函数Computer类,有数据成员芯片(cpu)、内存(ram)、光驱(cdrom)等,有两个公有成员函

声明一个简单的函数Computer类,有数据成员芯片(cpu)、内存(ram)、光驱(cdrom)等,有两个公有成员函数run和stop.cpu为CPU类的一个对象,ra... 声明一个简单的函数Computer类,有数据成员芯片(cpu)、内存(ram)、光驱(cdrom)等,有两个公有成员函数run和stop.cpu为CPU类的一个对象,ram为RAM类的一个对象,cdrom为CDROM类的一个对象,声明并实现这个函数\\这个题怎么做啊,求助各位高手。。急 展开
 我来答
云溪风
推荐于2018-12-27 · TA获得超过102个赞
知道答主
回答量:5
采纳率:0%
帮助的人:3.5万
展开全部
#include<iostream.h>
enum CPU_rank{p1=1,p2,p3,p4,p5,p6,p7};
class CPU
{
private:
CPU_rank rank;
int frequency;
float voltage;
public:
CPU (CPU_rank r,int f,float v)
{
rank=r;
frequency=f;
voltage=v;
cout<<"构造了一个cpu!"<<endl;
}
~CPU()
{ cout<<"其构了一个cpu!"<<endl;}
CPU_rank getrank() const
{ return rank;}
void setrank(CPU_rank r)
{ rank=r;}
void run()
{cout<<"cpu开始运行!"<<endl;
}
void stop()
{cout<<"cpu停止运行!"<<endl;}
};
class RAM
{
private:
int ram;
public:
RAM(int r)
{ cout<<"构造了一个ram!"<<endl;}
RAM(){ ram=0;cout<<"构造了一个ram!"<<endl;}
~RAM(){cout<<"析构了一个ram!"<<endl;}

void run()
{cout<<"ram开始运行!"<<endl;}
void stop()
{cout<<"ram停止运行!"<<endl;}
};
class CDRAM
{
private:
int cdram;
public:
CDRAM(int c)
{ cdram=c;
cout<<"构造了一个cdram!"<<endl;}
CDRAM(){ cout<<"构造了一个cdram!"<<endl;}
~CDRAM(){cout<<"析构了一个cdram!"<<endl;}

void run()
{cout<<"cdram开始运行"<<endl;}
void stop()
{cout<<"cdram停止运行"<<endl;}
};
class computer
{private:
CPU cpu;RAM ram;CDRAM cdram;
public:
computer(CPU c,RAM r,CDRAM cd);

computer();
~computer(){cout<<"析构了一个computer"<<endl;}
computer(computer &p);
void run()
{cout<<"computer开始运行"<<endl;}
void stop()
{cout<<"computer停止运行"<<endl;}
};
computer::computer():cpu(p6,100,float(1.3)),ram(20),cdram(30)
{cout<<"构造了一个 cpu00"<<endl;}
computer::computer(CPU c,RAM r,CDRAM cd):cpu(c),ram(r),cdram(cd)
{cout<<"构造了一个computer"<<endl;}
computer::computer(computer &p): cpu(p.cpu),ram(p.ram),cdram(p.cdram)
{ cout<<"调用了复制构造函数"<<endl;}
void main()
{
CPU m(p6,300,float(2.8));
RAM n(1);
CDRAM q(2);
computer com1;

computer com2(m,n,q);

}
Andy_le6
2018-10-18
知道答主
回答量:1
采纳率:0%
帮助的人:815
展开全部

// class.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include<iostream>

using namespace std;

enum CPU_Rank{p1=1,p2,p3,p4,p5,p6,p7};

class CPU

{

private:

CPU_Rank rank;

int frequency;

float voltage;

public:

CPU(CPU_Rank r, int f, float v)

{

rank = r;

frequency = f;

voltage = v;

cout << "构造了一个CPU!" << endl;

}

~CPU(){ cout << "析构了一个CPU!" << endl; }

CPU_Rank GetRank() const { return rank; }//      外部接口函数

int GetFrequency() const{ return frequency; }

float GetVoltage() const{ return voltage; }

void SetRank(CPU_Rank r){ rank = r; }//      

void SetFrequency(int f){ frequency = f; }

void SetVoltage(float v){ voltage = v; }

void Run(){ cout << "CPU开始运行!" << endl; }

void Stop(){ cout << "CPU停止运行!" << endl; }

};

enum RAM_Type{DDR2=2, DDR3, DDR4 };

class RAM

{

private:

int capacity;

RAM_Type type;

float Mfrequency;

public:

RAM(int c, RAM_Type t, float mf)

{

capacity = c;

type = t;

Mfrequency = mf;

cout << "构造了一个RAM!" << endl;

}

~RAM(){ cout << "析构了一个RAM!" << endl; }

RAM_Type GetType() const { return type; }

int GetCapacity() const{ return capacity; }

float GetMfrequency() const { return Mfrequency; }

void SetType(RAM_Type t) { type = t; }

void SetCapacity(int c){ capacity = c; }

void SetMfrequency(float mf){ Mfrequency = mf; }

void Run(){ cout << "RAM开始运行!" << endl; }

void Stop(){ cout << "RAM停止运行!" << endl; }

};

enum CDRAM_Interface{SATA,USB};

enum CDRAM_Install_type{external,built_in};

class CDRAM

{

private:

CDRAM_Interface interface;

int cache_size;

CDRAM_Install_type install_type;

public:

CDRAM(CDRAM_Interface i,int cs,CDRAM_Install_type ty)

{

interface = i;

cache_size = cs;

install_type = ty;

cout << "构造了一个CDRAM!" << endl;

}

~CDRAM(){ cout << "析构了CDRAM!" << endl; }

CDRAM_Interface GetInterface() const { return interface; }

int GetCache_size() const{ return cache_size; }

CDRAM_Install_type GetInstall_type() const { return install_type; }

void SetInterface(CDRAM_Interface i){ interface = i; }

void SetCache_size(int cs){ cache_size = cs; }

void SetInstall_type(CDRAM_Install_type ty){ install_type = ty; }

void Run(){ cout << "CDROM开始运行!" << endl; }

void Stop(){ cout << "CDROM停止运行!" << endl; }

};

class COMPUTER

{

private:

CPU my_cpu;

RAM my_ram;

CDRAM my_cdram;

unsigned int storage_size;

unsigned int bandwidth;

public:

COMPUTER::COMPUTER(CPU c, RAM r, CDRAM cdr, int sto, int ban) :my_cpu(c), my_ram(r), my_cdram(cdr)

storage_size = sto;

bandwidth = ban;

cout << "构造了一个COMPUTER!" << endl; 

}

~COMPUTER(){ cout << "析构了COMPUTER!" << endl; }

void Run()

{

my_cpu.Run();

my_ram.Run();

my_cdram.Run();

cout << "COMPUTER开始运行!" << endl;

}

void Stop()

{

my_cpu.Stop();

my_ram.Stop();

my_cdram.Stop();

cout << "COMPUTER停止运行!" << endl;

}

};

/*COMPUTER::COMPUTER(CPU c, RAM r, CDRAM cdr, int sto, int ban) :my_cpu(c), my_ram(r), my_cdram(cdr)

{

//my_cpu = c;

//my_ram = r;

//my_cdram = cdr;

storage_size = sto;

bandwidth = ban;

cout << "构造了一个COMPUTER!" << endl;

}*/

int _tmain(int argc, _TCHAR* argv[])

{

CPU a(p6, 300, 220);//声明一个CPU对象,下面都是对这个对象的操作

a.Run();

a.Stop();

cout << "**************************" << endl;

RAM b(1600, DDR3, 220.34);

b.Run();

b.Stop();

cout << "**************************" << endl;

CDRAM c(USB, 400, external);

c.Run();

c.Stop();

cout << "**************************" << endl;

COMPUTER mycomputer(a, b, c, 300, 200);

mycomputer.Run();

mycomputer.Stop();

cout << "**************************" << endl;

return 0;

}


已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2011-03-30
展开全部
#include <iostream>
using namespace std;

enum CPU_Rank {P1=1,P2,P3,P4,P5,P6,P7};
class CPU
{
private:
CPU_Rank rank;
int frequency;
float voltage;
public:
CPU (CPU_Rank r, int f, float v)
{
rank = r;
frequency = f;
voltage = v;
cout << "构造了一个CPU!" << endl;
}
CPU()
{
cout << "构造了一个CPU!" << endl;
};
~CPU ()
{
cout << "析构了一个CPU!" << endl;
}

CPU_Rank GetRank() const { return rank; }
int GetFrequency() const { return frequency; }
float GetVoltage() const { return voltage; }

void SetRank(CPU_Rank r) { rank = r; }
void SetFrequency(int f) { frequency = f; }
void SetVoltage(float v) { voltage = v; }

void Run() {cout << "CPU开始运行!" << endl; }
void Stop() {cout << "CPU停止运行!" << endl; }
};
class RAM
{
public:
RAM ()
{
cout << "构造了一个RAM!" << endl;
}
~RAM ()
{
cout << "析构了一个RAM!" << endl;
}

void Run() {cout << "RAM开始运行!" << endl; }
void Stop() {cout << "RAM停止运行!" << endl; }
};

class CDROM
{
public:
CDROM (){ cout << "构造了一个CDROM!" << endl; }
~CDROM ()
{
cout << "析构了一个CDROM!" << endl;
}

void Run() {cout << "CDROM开始运行!" << endl; }
void Stop() {cout << "CDROM停止运行!" << endl; }
};

class COMPUTER
{
private:
CPU cpu;
RAM ram;
CDROM cdrom;
public:
COMPUTER()
{
cout << "构造了一个COMPUTER!" << endl;
}
~COMPUTER ()
{
cout << "析构了一个COMPUTER!" << endl;

}

void Run()
{
cout << "COMPUTER开始运行!" << endl;
cpu.Run();
ram.Run();
}
void Stop()
{
ram.Stop();
cpu.Stop();
cout << "COMPUTER停止运行!" << endl;
}
};

int main()
{
COMPUTER a;
a.Run();
a.Stop();
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2019-04-21
展开全部
只想说一句,这么多年过去了,我也在写这个代码
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
_iamcoco
2011-04-01
知道答主
回答量:29
采纳率:0%
帮助的人:0
展开全部
class Computer{
private:
Cpu cpu;
Ram ram;
Cdrom cdrom;
public:
void run()
{}
void stop()
{}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(4)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式