当前位置: 首页 > news >正文

网站制作教程及流程/优化seo厂家

网站制作教程及流程,优化seo厂家,东莞做网站需要多少钱,北京到安阳高铁时刻表实验报告题目2【实验名称】 实验五 数据的共享与保护 【实验内容】 1.为某个自己设定的游戏设定玩家类Player,设计必要的成员变量/成员函数/构造函数等。在类中增加静态成员,用于记录当前已经注册的玩家数量,并设计静态成员函数用于访问该数据。在主函数…

实验报告

  • 题目2

【实验名称】 实验五 数据的共享与保护
【实验内容】

1.为某个自己设定的游戏设定玩家类Player,设计必要的成员变量/成员函数/构造函数等。在类中增加静态成员,用于记录当前已经注册的玩家数量,并设计静态成员函数用于访问该数据。在主函数中生成对象并进行测试。

源代码:Player.h

#ifndef _Player_H_
#define _Player_H_
#include "Player.h"
#include <time.h>
using namespace std;
enum Sex{male,female};class Player{
public:Player();Player(string name , string password , int age = 0, Sex sex = male, string e_mail = NULL);static int getPlayerNumber(){ return playerNumber; } //返回当前注册玩家数量string getTime(){ return registerTime; } //返回注册时间void displayInformation(); //显示玩家信息void changeInformation();  //修改玩家信息void play(); //开始游戏
private:void setTime();  //设置注册时间static int playerNumber;  //所有注册玩家的数量string registerTime;  //注册时间static int IDgrowth; //ID号的增长int ID;  //唯一玩家ID号int grade;       //等级int experience;  //经验string name;   //用户名string password;  //密码int age;      //年龄Sex sex;    //性别string e_mail;    //邮箱
};#endif

Player.cpp

#include<iostream>
#include<stdlib.h>
#include"Player.h"
using namespace std;int Player::playerNumber = 0;
int Player::IDgrowth = 10000;Player::Player(){IDgrowth = IDgrowth + rand()%11;ID = IDgrowth;grade = 0;experience = 0;setTime();playerNumber++;}Player::Player(string name , string password , int age , Sex sex , string e_mail){this->name = name;this->password = password;this->age = age ;this->sex = sex;this->e_mail = e_mail;IDgrowth = IDgrowth + rand()%11;ID = IDgrowth;grade = 0;experience = 0;setTime();playerNumber++;}void Player::setTime()  //获取当前时间,作为注册时间{time_t timep;time (&timep);char tmp[64];strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S",localtime(&timep) );registerTime = tmp;}void Player::displayInformation(){cout <<ID<< "号玩家信息如下:" <<endl;cout << "玩家姓名:" << name <<endl;cout << "唯一ID号: " << ID <<endl;cout << "注册时间: " << registerTime <<endl;cout << "玩家等级: " << grade <<endl;cout << "玩家目前的经验: " << experience <<endl;cout << "玩家年龄: " << age <<endl;cout << "玩家性别: ";switch(sex){case 0:cout<< "男生" <<endl;break;case 1:cout<< "女生" <<endl;break;}cout << "玩家的邮箱: " << e_mail <<endl;}void Player::changeInformation(){int n = 1;while(n){cout << "请输入您需要修改的信息编号:0、用户名 1、密码: 2、性别 3、邮箱" <<endl;int m;string str;cin >>m;switch(m){case 0:cout<<"请输入新的用户名:"<<endl;cin >>str;name = str;break;break;case 1:cout<<"请输入新的密码:"<<endl;cin >>str;password = str;break;case 2:cout<<"请输入性别:男生 or 女生"<<endl;cin >>str;if(str == "男生") {sex = male;cout <<"性别修改为男生"<<endl;}if(str == "女生") {sex = female;cout <<"性别修改为女生"<<endl;}break;case 3:cout<<"请输入新的邮箱:"<<endl;cin >>str;e_mail = str;cout <<"邮箱修改为:"<< e_mail <<endl;}cout <<"是否要继续修改信息: 0、退出修改  1、继续修改"<<endl;cin>>n;}}void Player::play(){cout << "尊贵的  " <<name<< "  玩家进入游戏" <<endl;}

main.cpp

#include<iostream>
#include"Player.h"
#include"Player.cpp"
using namespace std;int main(){Player array[100];cout<<"array[0]访问的玩家数量,目前的注册玩家数量为:"<<array[0].getPlayerNumber()<<endl;Player player1("大灬白","A12345678",18,male,"123456789@qq.com");cout<<"player1访问的玩家数量,目前的注册玩家数量为:"<<player1.getPlayerNumber()<<endl;player1.displayInformation();player1.changeInformation();player1.displayInformation();player1.play();return 0;
}

【实验结果】
在这里插入图片描述

题目2

设计两个道具类Helm和Armor,
设计必要的成员变量/成员函数/构造函数等,其中要求必须有成员变量valueOfDefense.在外部定义一个友元函数,可以读取该数据成员。在主函数中生成对象并进行测试。

Armor.cpp

#include<iostream>using namespace std;class Armor{
public:Aemor(){}Armor(string name , int price,int durability,int physicalResist,int magicResist,int valueOfDefense){this->name = name;this->price = price;this->durability = durability;this->physicalResist = physicalResist;this->magicResist = magicResist;this->valueOfDefense = valueOfDefense;}string getName(){ return name; }int getPrice(){ return price; }int getDurability(){ return durability; }int getPhysicalResist(){ return physicalResist; }int getMagicResist(){ return magicResist; }void setPrice(int price){ this->price = price; }void setDurability(int durability){ this->durability = durability; }void setPhysicalResist(int physicalResist){ this->physicalResist = physicalResist; }void setMagicResist(int magicResist){ this->magicResist = magicResist; }void setValueOfDefense(int valueOfDefense){ this->valueOfDefense = valueOfDefense; }void show(){ //显示装备信息cout << name << "的价格是:" << price <<endl;cout << name << "的耐久度是:" << durability <<endl;cout << name << "的物理抗性是:" << physicalResist <<endl;cout << name << "的魔法抗性是:" << magicResist <<endl;}void effect(){cout<<"特殊效果:装备这件护甲,在血量低于30%时会获得一个随等级提高的护盾。"<<endl;}friend int getValueOfDefense(Armor &h);
private:string name;   //装备名称int price;   //价格0~3000int durability;  //耐久度0~100int physicalResist;  //物理抗性0~100int magicResist;  //魔法抗性0~100int valueOfDefense;  //防御值0~1000
};int getValueOfDefense(Armor &a){ return a.valueOfDefense; }

Helmet.cpp

#include<iostream>using namespace std;class Helmet{
public:Helmet(){}Helmet(string name , int price,int durability,int physicalResist,int magicResist,int valueOfDefense){this->name = name;this->price = price;this->durability = durability;this->physicalResist = physicalResist;this->magicResist = magicResist;this->valueOfDefense = valueOfDefense;}string getName(){ return name; }int getPrice(){ return price; }int getDurability(){ return durability; }int getPhysicalResist(){ return physicalResist; }int getMagicResist(){ return magicResist; }void setPrice(int price){ this->price = price; }void setDurability(int durability){ this->durability = durability; }void setPhysicalResist(int physicalResist){ this->physicalResist = physicalResist; }void setMagicResist(int magicResist){ this->magicResist = magicResist; }void setValueOfDefense(int valueOfDefense){ this->valueOfDefense = valueOfDefense; }void show(){ //显示装备信息cout << name << "的价格是:" << price <<endl;cout << name << "的耐久度是:" << durability <<endl;cout << name << "的物理抗性是:" << physicalResist <<endl;cout << name << "的魔法抗性是:" << magicResist <<endl;}void effect(){cout<<"特殊效果:装备这件头盔,可以为你抵挡一次致命攻击"<<endl;}friend int getValueOfDefense(Helmet &h);
private:string name;  //装备名称int price;   //价格0~3000int durability;  //耐久度0~100int physicalResist;  //物理抗性0~100int magicResist;  //魔法抗性0~100int valueOfDefense;  //防御值0~1000
};int getValueOfDefense(Helmet &h){ return h.valueOfDefense; }

Main.cpp

#include<iostream>
#include"Armor.cpp"
#include"Helmet.cpp"
using namespace std;int main(){Armor armor("锁子甲",1000,80,50,40,120);Helmet helmet("防爆头盔",800,60,74,43,160);armor.show();cout<< armor.getName() <<"的防御值:"<<getValueOfDefense(armor)<<endl;armor.effect();helmet.show();cout<< helmet.getName() <<"装备的防御值:"<<getValueOfDefense(helmet)<<endl;helmet.effect();return 0;
}

【实验结果】
在这里插入图片描述

【小结或讨论】
本次实验是实验五 数据的共享与保护,实验的主要目的是第一题在类中增加静态成员,用于记录当前已经注册的玩家数量,并设计静态成员函数用于访问该数据。在第一题中也为玩家设置了注册时间(通过strftime函数获取系统时间,以年-月-日 xx:xx:xx的格式记录)、唯一的ID号(通过rand函数的累加)、玩家等级、玩家经验等系统设置的成员变量,以及姓名、密码、年龄、性别、邮箱等可以个人设置的成员变量。实验二必须有成员变量valueOfDefense.在外部定义一个友元函数,可以读取该数据成员。还设置了装备的价格、耐久度、魔法抗性、物理抗性等,之后再主文件中通过友元函数读取了两件装备的防御值valueOfDefense。这次实验不难,主要就是实现了静态成员变量和函数,以及友元函数的使用,以此来实现对数据的共享与保护。

http://www.lbrq.cn/news/832231.html

相关文章:

  • 域名通过了才可以做网站吗/关键词分析软件
  • 建站之星有手机版模板/站长统计app进入网址新版
  • https网站建设花费/google图片搜索
  • 国外做家谱的网站/汕头seo网站推广
  • 做打鱼网站/中国50强企业管理培训机构
  • 邵阳疫情最新消息今天又封了/抖音seo是什么
  • 网站开发背景图模板/郑州外语网站建站优化
  • 上虞网站建设baidu/百度客服人工电话
  • 开发网站用得最多的是什么语言/住房和城乡建设部
  • 自己做产品网站/网站优化的意义
  • 网站的登录功能一般是用cookie做的/百度一下官方下载安装
  • 企业手机网站开发/做网络推广的网站有哪些
  • 广西建设工程管理网站/每日精选12条新闻
  • 网站风格 颜色搭配/sem和seo的区别
  • 网站新闻源码/网页设计与制作项目教程
  • 富阳做兼职的网站/阿里云搜索引擎
  • 网站项目设计与制作综合实训/北京seo优化推广
  • 化妆品的网站设计方案/seo权重查询
  • 常州模板建站哪家好/关键词排名监控
  • 内网电脑做网站/四川seo技术培训
  • dw做了网站还可以做淘宝详情吗/广告投放公司
  • seo关键词优化服务/天津seo优化公司
  • 中国icp备案网站/app拉新推广平台渠道商
  • 注册个网站域名多少钱一年/应用宝aso优化
  • 衡东网站制作/志鸿优化网
  • 高中生做网站网页/网站推广方案策划书2000
  • 怎么用frontpage做网站/海淀区seo搜索引擎
  • 南通制作手机网站/图片百度搜索
  • html5 js全屏滑动网站源码/郴州seo网络优化
  • 竞价单页网站模板/seo的收费标准
  • 学习C++、QT---29(QT库中QT事件的介绍和用了几个案例来对事件怎么使用的讲解)
  • 本地大模型部署工具全解析:LM Studio vs. Ollama 及最佳实践指南
  • Flutter基础(前端教程①③-单例)
  • Java 大视界 -- Java 大数据机器学习模型在自然语言处理中的对话系统多轮交互优化与用户体验提升(351)
  • Kubernetes Pod深度理解
  • spring boot 实战之分布式锁