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. 首先 ...
随机推荐
- 51nod 1597 有限背包计数问题 (背包 分块)
题意 题目链接 Sol 不会做啊AAA.. 暴力上肯定是不行的,考虑根号分组 设\(m = \sqrt{n}\) 对于前\(m\)个直接暴力,利用单调队列优化多重背包的思想,按\(\% i\)分组一下 ...
- Python爬虫之图片懒加载技术、selenium和PhantomJS
一.引入 2.概要 图片懒加载 selenium phantomJs 谷歌无头浏览器 3.回顾 验证码处理流程 一.今日详情 动态数据加载处理 1.图片懒加载 什么是图片懒加载? 案例分析:抓取站长素 ...
- twaver拓扑图拖拽后保存json数据
功能描述:拓扑图.对节点进行拖拽,序列化获取拓扑图信息,保存到本地localStorage,刷新页面,执行反序列化,从本地获取之前保存的数据,展现之前拖拽后的拓扑 拓展:此处存储用的是web本地存储l ...
- js for in 遍历对象与数组
遍历对象 let obj = { q:'9', w:'5', e:'2', t:'7', c:'3' } //for in 遍历对象 key为对象的属性名称,遍历属性值时用[]操作符访问 //通过[] ...
- UIRecorder安装与使用
继vue单元测试,将进行vue的e2e测试学习. 学习点: 安装uirecorder 用工具(UI Recorder)录制测试脚本 测试脚本的回放 本文意在安装UI Recorder,并且利用该工具进 ...
- OFFICE_EXCEL_Combine text from two or more cells into one cell.
Excel Enter and format data Layout Combine text from two or more cells into one cell Combine t ...
- Ext,合计保留两位小数
1. features: [{ ftype: 'summary', dock: 'bottom' }], 2. summaryType: function(records){ return '合计'; ...
- idea打jar包经验总结
关于在idea下打jar问题,在日常工作中经常用到,这里总结下流程. 1.在项目上鼠标右键 --> Open Module Settings 2.如下图,点击 '+' 3. 选择JAR --&g ...
- 因子和&&因子数
给定一数n,求n的因子数目和因子之和 上述求因子和式子等于 ∏{(piei+1 - 1) / (pi - 1)} (∏就是连乘) 模板: +; int prime[maxn]; bool is_pr ...
- 一组div跟随鼠标移动,反应鼠标轨迹
<!DOCTYPE html> <html> <head> <title>div随鼠标移动</title> <style type=& ...