用C++来声明一个简单的Computer类
声明一个简单的Computer类,有数据成员cpu,ram,cdrom等有两个公有成员函数run()和stop(),其中cpu,ram和cdrom分别为CPU,RAM和C...
声明一个简单的Computer类,有数据成员cpu,ram,cdrom等有两个公有成员函数run()和stop(),其中cpu,ram和cdrom分别为CPU,RAM和CDROM的一个对象,定义并测试这个类。
本人急用的,谢谢~~ 展开
本人急用的,谢谢~~ 展开
3个回答
2013-04-19
展开全部
#include <iostream>
using namespace std;
class CPU;//关于这三个类的定义 ,相信你有
class RAM;
class CDRAM;
class Computer{
public:
void run();//具体的函数功能你自己设定
void stop();
private:
CPU cpu;
RAM ram;
CDROM cdrom;
};
using namespace std;
class CPU;//关于这三个类的定义 ,相信你有
class RAM;
class CDRAM;
class Computer{
public:
void run();//具体的函数功能你自己设定
void stop();
private:
CPU cpu;
RAM ram;
CDROM cdrom;
};
展开全部
class Computer{
public:
void start();
void end();
private:
HDD hdd;
CDROM cdrom;
CPU cpu;
};
public:
void start();
void end();
private:
HDD hdd;
CDROM cdrom;
CPU cpu;
};
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-04-19
展开全部
C/C++ code
#include "iostream"
#include "string"
using namespace std;
class Client
{
public :
static void ChangeServerName(string strName)
{
ServerName = strName;
}
Client()
{
++ClientNum;
}
~Client()
{
--ClientNum;
}
static string ServerName;
static int ClientNum;
};
string Client::ServerName = "";
int Client::ClientNum = 0;
int main()
{
Client::ChangeServerName("server1");
Client* p1 = new Client;
Client* p2 = new Client;
cout<<"server name :"<<Client::ServerName<<endl;
cout<<"client num : "<<Client::ClientNum<<endl;
Client::ChangeServerName("server2");
delete p2;
cout<<"server name :"<<Client::ServerName<<endl;
cout<<"client num : "<<Client::ClientNum<<endl;
return 0;
}
#include "iostream"
#include "string"
using namespace std;
class Client
{
public :
static void ChangeServerName(string strName)
{
ServerName = strName;
}
Client()
{
++ClientNum;
}
~Client()
{
--ClientNum;
}
static string ServerName;
static int ClientNum;
};
string Client::ServerName = "";
int Client::ClientNum = 0;
int main()
{
Client::ChangeServerName("server1");
Client* p1 = new Client;
Client* p2 = new Client;
cout<<"server name :"<<Client::ServerName<<endl;
cout<<"client num : "<<Client::ClientNum<<endl;
Client::ChangeServerName("server2");
delete p2;
cout<<"server name :"<<Client::ServerName<<endl;
cout<<"client num : "<<Client::ClientNum<<endl;
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询