C++练习--实现客户机(CLIENT)类
实现客户机(CLIENT)类。
定义字符型静态数据成员SeverName,保存其服务器名称;
整型静态数据成员ClientNum,记录已定义的客户数量;
定义静态函数ChangeSeverName()改变服务器名称。
在头文件client.h中定义类,
在文件client.cpp中实现,
在文件test.cpp中测试这个类,
观察相应的成员变量取值的变化情况。
- 代码如下:
- client.h
/*
*This file contains code for C++ 3rd experiment
*By LZH
*/
/*
*Warnning:A static variable in a class belongs to a class and does not belong to an Object!
*You cannot initialize a variable when an object is defined!
*Cannot initialize with constructors!
*Also, use the class name instead of the object.
*/
#ifndef CLIENT_H
// we're here only if CLIENT_H has not yet been defined
#define CLIENT_H
// Definition of Sales_item class and related functions goes here
#include <iostream>
#include <string>
using namespace std;
class CLIENT {
private:
static string ServerName; //Keep the Name of the Sever
static int ClientNum; //Keep the sum of the client
public:
CLIENT();
~CLIENT();
static void ChangeSeverName();
void show();
};
#endif
- client.cpp
#include"client.h"
CLIENT::CLIENT() {
cout<<"This is the Dafault Constructor!!";
ClientNum++;
}
void CLIENT:: ChangeSeverName(){
cout << "Please enter the name of new server:";
cin >> ServerName;
} //Change the Name of the server
void CLIENT::show(){
cout << "The Server's name:" << ServerName << endl;
cout << "The number of the Clients:" << ClientNum << endl;
}
CLIENT::~CLIENT() {
}
int CLIENT::ClientNum = 0;
string CLIENT::ServerName = "#@$#@$";
- test.cpp
#include"client.h"
int main() {
CLIENT asp;
asp.show();
asp.ChangeSeverName();
asp.show();
return 0;
}
- 测试截图
C++练习--实现客户机(CLIENT)类的更多相关文章
- 解决Synergy的鼠标无法从服务器(server)机屏幕移动到客户机(client)屏幕的问题
我在工作时使用一台Win 7笔记本和一台Ubuntu台式机,为了提升工作效率,我使用Synergy在两台机器间共享了笔记本的鼠标和键盘,即笔记本作为服务器,台式机作为客户机. 这样使用了大概一年多,但 ...
- 问题解决——基于MSCOMM32.OCX控件的类在客户机不能创建控件
大家不要笑我了,我不喜欢用那个人家写的串口类. 所以导出了MSCOMM32.OCX的类,然后在此基础上写了一个串口打印机的小工具类. -------------声明--------------- 本文 ...
- System.TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception. ---> Oracle.DataAccess.Client.OracleException: 提供程序与此版本的 Oracle 客户机不兼容”
.net应用程序通过Oracle.DataAccess.dll访问64位的Oracle服务器,在连接时出现以下异常:“System.TypeInitializationException: The t ...
- 反应式系统实现MQTT客户机
反应式系统实现MQTT客户机 Implementing an MQTT client for reactive systems MQTT Reactive是从LiamBindle的MQTT-C库派生的 ...
- ORA-12523: TNS: 监听程序无法找到适用于客户机连接的例程
今天使用PL/SQL Developer连接到一台新的测试服务器时,遇到ORA错误:ORA-12523: TNS: 监听程序无法找到适用于客户机连接的例程.对应的监听日志文件里面错误为TNS-1252 ...
- 客户机中PLSQL DEV访问虚拟机中的ORCLE11g,错误百出!
客户机中PLSQL DEV访问虚拟机中的ORCLE11g,错误百出! 创建时间: 2017/10/14 18:44 作者: CNSIMO 标签: ORACLE 忙了一下午,只有两个字形容:麻烦! ...
- 如何为MySQL服务器和客户机启用SSL
本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn 摘要: mysql5.7后有ssl新特性 自己搭建mysql ent ...
- 多节点通过PPP连接,节点/用户/客户机之间互相访问ping
多节点通过PPP连接,节点/用户/客户机之间互相访问ping 转载注明来源: 本文链接 来自osnosn的博客,写于 2019-04-14. 有A, B, C 三台客户机,通过ppp虚拟拨号连接到服务 ...
- Window 64位下的客户机配置PLSQL链接远程Oracle
此文章记录的是艰难探索. 完成如下工作: 服务器A为Windows Serve 2016:安装Oracle. 客户机B为Win7 x64位,安装PLSQLDevelop,链接A上的Oracle. 首先 ...
随机推荐
- 封装http请求键值对的js函数
//封装http请求键值对的函数 function Map() { this.keys = new Array(); this.data = {}; //添加键值对 this.put = functi ...
- 静态化HttpClient
实现方法: public class HttpClientHelper { private static HttpClient _client; public static HttpClient Ge ...
- .NET开源工作流RoadFlow-表单设计-数据表格
数据表格即在表单中显示一个table,该table数据可以来自任意自定义的来源: 数据类型:指定表格的数据源类型 1.datatable,即.net中的System.Data.DataTable 2. ...
- ArcGIS Geodabase OBJECTID重新初始编号的间接方法
ArcGIS Geodabase OBJECTID为Long型,随着Feature的增加和删除自动编号,均为增加.即删除Feature后,再增加该号码自动只增加不重新编号. 间接方法可以实现重新从1编 ...
- eclipse中手动设置library,选择编译工具方法
target=android-25sdk.buildtools=25.0.2 target=android-26android.library=falseandroid.library.referen ...
- mvc4 坑啊
昨天下午出了个BUG.到今天上午才解决掉.就是mvc页面的属性名跟controller 中action 参数的名相同.导致action无法取得前台的值.这个问题浪费了很多时间.命名要规范. 如 页面 ...
- python中文入库
http://www.cnblogs.com/evening/archive/2012/04/19/2457440.html 工作需要,将cvm.csv文件中的记录志入数据库, name, owner ...
- SQL Server ->> 存储过程sp_rename重命名数据对象
1) 表转移Schema和重命名表 ALTER SCHEMA Stage TRANSFER dbo.Stage_AAA; EXEC sp_rename 'Stage.Stage_AAA', 'AAA' ...
- libxml
/** * section: Tree * synopsis: Navigates a tree to print element names * purpose: Parse a file to a ...
- Educational Codeforces Round 10 D. Nested Segments 【树状数组区间更新 + 离散化 + stl】
任意门:http://codeforces.com/contest/652/problem/D D. Nested Segments time limit per test 2 seconds mem ...