实现客户机(Client)类。定义字符型静态数据成员ServerName,保存其服务器名称;整型静态数据成员ClientNum,记录已定义的客户机数量;定义静态函数ChangeServerName()改变服务器名称。完成程序,使得提供的测试程序可以运行并得到要求的结果。
函数接口定义:
根据要求实现类代码
裁判测试程序样例:
/*在这里完成类代码*/
在这里给出函数被调用进行测试的例子。例如:
int main(){
Client::show();
Client c1;
Client::show();
Client::changeServerName('B');
Client::show();
}
输入样例:
在这里给出一组输入。例如:
无
输出样例:
在这里给出相应的输出。例如:
server name:A
num of clients:0
server name:A
num of clients:1
server name:B
num of clients:1
#include<iostream>
using namespace std;
class Client {
public:
void static changeServerName(char c)//改变服务器的名称
{
ServerName = c;
}//改变服务器名称
void static show()
{
cout << "server name:" << ServerName << endl;
cout << "num of clients:" << ClientNum << endl;
}
Client()
{
ClientNum++;
}
private:
static char ServerName;//保存服务器名称
static int ClientNum;//记录已定义的客户机数量
};
int Client::ClientNum = 0;
char Client::ServerName = 'A';