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