#include <easyx.h> // Reference graphics library header file
#include <conio.h>
#include <iostream>
#include<random>
#include<ctime>
#include<cmath>
#include<windows.h>
#include"person.h"
#include"print.h"
using namespace std;
const int person_size = 3000;//城市总人口
const double u = 1;//人员流动平均意向 0~100%的移动概率
const int original_count = 5;//初始感染者人数0~200
const int shadow_time =15;//潜伏时间 0~100;
extern const double broad_rate =1;//传播率
const int receive_time = 2;//医院收治时间
const int bed_count = 1000 ;//医院床位数量
default_random_engine e; //引擎//随机数引擎的参数
int person_origin = person_size;
int shadow = 0;//潜伏期人数
int affect = 0;//感染人数
int hospital_count = 0;//医院里已有的病人
extern const int cure = 0;//治愈状态
extern const int orig = 1;//初始状态
extern const int shad = 2;//潜伏期状态
extern const int affe = 3;//被感染状态
person pe_po[person_size];//人口池
extern const int graph_l ;
extern const int graph_h ;
extern int city[480][480] ;
int ch_time = 0;
void set_person(person*, int);//set the people's location on graph
void print_person();
void move();//move each chanel
bool over();//make sure the affect is over.
bool check_pos(int,int);
void city_heal(const int x,const int y,int z);
void print_words();
void add_time();
void condition_change();
int person_city_heal(int z);
bool rand_broad();
void print_hospital();
void hospital_condition();
void refresh_city();
int affe_per();
int main()
{
for (int a = 0; a != person_size; a++)
{
pe_po[a].index = a;
}
srand(time(0));
initgraph(640, 480); // Create a graphics window with a size of 640x480 pixels
system("pause");
set_person(pe_po, person_size);
print_person();
_getch(); // Press any key to continue
for (int a = 0; a != original_count; a++)
{
int x1 = 0;
do
{
x1 = rand()% person_size;
} while (pe_po[x1].person_heal() == 0||check_pos(pe_po[x1].x_pos(), pe_po[x1].y_pos()));
pe_po[x1].change_heal(shad);
city_heal(pe_po[x1].x_pos(), pe_po[x1].y_pos(),x1);//初始化程序的状态
}
print_person();
settextcolor(WHITE);
BeginBatchDraw();//批量绘图的方法
while (over())
{
_getch();
move();
refresh_city();
add_time();
condition_change();
print_person();
print_words();
if (hospital_count < bed_count)
{
hospital_condition();
}
print_hospital();
FlushBatchDraw();
}
EndBatchDraw();
_getch();
closegraph(); // Close the graphics window
return 0;
}
void set_person(person a[],int b)
{
normal_distribution<double> n(240, 80);
//均值, 方差
int x = 0;
int y = 0;
for (int c = 0; c != b; c++)
{
do {
y = lround(n(e));
x = lround(n(e));
} while (check_pos(x,y));
a[c].position(x, y);
}
}
void print_person()
{
cleardevice();
for (auto &a:pe_po)
{
if (a.under_cure == 0)
{
switch (a.person_heal())
{
case cure:setfillcolor(GREEN); setlinecolor(GREEN); break;
case orig:setfillcolor(WHITE); setlinecolor(WHITE); break;
case shad:setfillcolor(YELLOW); setlinecolor(YELLOW); break;
case affe:setfillcolor(RED); setlinecolor(RED); break;
}
fillcircle(a.x_pos(), a.y_pos(), 1);
}
}
}
void move()
{
int x1 = 0;
int y1 = 0;
for (auto& a : pe_po)
{
if (rand()%10000<u*u*10000)
{
x1 = rand() % 9 - 4 + a.x_pos();
y1 = rand() % 9 - 4+ a.y_pos();
if (!check_pos(x1, y1))
{
a.position(x1, y1);
}
}
}
for (auto& a : pe_po)
{
city_heal(a.x_pos(), a.y_pos(), a.index);
}
for (auto& a : pe_po)
{
a.city_heal_person(city[a.x_pos()][a.y_pos()]);
}
}
bool over()
{
for (auto a : pe_po)
{
if (a.person_heal() != affe)//if one person are not affected
return 1;
}
return 0;
}
bool check_pos(int x, int y)
{
if ((x - graph_h / 2) * (x - graph_h / 2) + (y - graph_h / 2) * (y - graph_h / 2) > graph_h* graph_h / 4)
return 1;
return 0;
}
void city_heal(const int x,const int y,int z)
{
if (city[x][y] < pe_po[z].person_heal())
city[x][y] = pe_po[z].person_heal();
}
void print_words()
{
TCHAR s[10];//储存天数
settextcolor(WHITE);
sprintf_s(s, _T("%d"), ch_time++); // 高版本 VC 推荐使用 _stprintf_s 函数
outtextxy(580, 60, s);
sprintf_s(s, _T("%d"), person_size);
outtextxy(580, 100, s);
sprintf_s(s, _T("%d"), affe_per()- hospital_count);
outtextxy(580, 140, s);
outtextxy(444, 60, "病毒传播天数(天):");
outtextxy(460, 100, "城市总人数(人):");
outtextxy(492, 140, "已感染(人):");
}
void add_time()
{
for (auto& a : pe_po)
{
if (a.person_heal() == shad|| a.person_heal()==affe)
++a.af_time;
}
}
void condition_change()
{
for (auto& a : pe_po)
{
if (a.play_af_time() > shadow_time)
a.change_heal(affe);
}
}
void print_hospital()
{
setfillcolor(WHITE);
rectangle(540, 200, 570, 450);
if (hospital_count <= bed_count)
{
setfillcolor(WHITE);
if (bed_count == hospital_count) {
setfillcolor(RED); setlinecolor(RED); settextcolor(RED);
}
TCHAR x[10];
fillrectangle(540, 450 - 250 * static_cast<double>(hospital_count) / bed_count, 570, 450);
outtextxy(474, 180, "剩余床位(个):");
sprintf_s(x, _T("%d"), bed_count - hospital_count);
outtextxy(580, 180, x);
}
}
void hospital_condition()
{
for (auto& a : pe_po)
{
if (hospital_count < bed_count)
{
if (a.play_af_time() > shadow_time + receive_time && a.under_cure == 0)
{
a.under_cure = 1;
hospital_count++;
a.change_heal(0);
}
}
}
}
void refresh_city()
{
for (auto& a : city)
{
for (auto& b :a)
{
b = 0;
}
}
}
int affe_per()
{
int a = 0;
for (auto &b : pe_po)
{
if (b.person_heal()>orig)
a++;
}
return a;
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 1、项目源码在上传前,都经过本地成功运行,功能测试ok。请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机科学、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、机械电子信息等相关专业背景的在校大学生、专业老师 行业从业人员等下载使用。 3、用途:项目代表性强,具有创新性和启发性,故具有挺高的学习借鉴价值。不仅适合小白入门进阶,还可作为毕设项目、课程设计、大作业、比赛初期项目立项演示等。 4、如果基础还不错,又热爱学习钻研,也可基于此项目基础上进行修改进行二次开发。 本人也是技术狂热者,如果觉得此项目对您有价值,欢迎下载使用! 无论您是运行还是二次开发,部署过程若遇到问题,请及时私信交流,欢迎学习。 基于C++模拟仿真病毒传播项目源码(课程作业).zip基于C++模拟仿真病毒传播项目源码(课程作业).zip基于C++模拟仿真病毒传播项目源码(课程作业).zip基于C++模拟仿真病毒传播项目源码(课程作业).zip基于C++模拟仿真病毒传播项目源码(课程作业).zip基于C++模拟仿真病毒传播项目源码(课程作业).zip基于C++模拟仿真病毒传播项目源码(课程作业).zip基于C++模拟仿真病毒传播项目源码(课程作业).zip基于C++模拟仿真病毒传播项目源码(课程作业).zip基于C++模拟仿真病毒传播项目源码(课程作业).zip基于C++模拟仿真病毒传播项目源码(课程作业).zip基于C++模拟仿真病毒传播项目源码(课程作业).zip基于C++模拟仿真病毒传播项目源码(课程作业).zip基于C++模拟仿真病毒传播项目源码(课程作业).zip 基于C++模拟仿真病毒传播项目源码(课程作业).zip
资源推荐
资源详情
资源评论
收起资源包目录
基于C++模拟仿真病毒传播项目源码(课程作业).zip (2个子文件)
code
main.cpp 6KB
person.h 1KB
共 2 条
- 1
资源评论
唐先生的博客
- 粉丝: 3235
- 资源: 631
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 藏区特产销售平台源代码+论文+毕业设计.zip
- B297C8EC5A69641DB3E681E1B3F894E5.mp4
- PrimitivesPro v2.2.unitypackage
- 财务管理系统源代码+论文.zip
- 高级信息通信运行管理员第七套试卷
- UModeler v2.11.6 (May 10, 2024).unitypackage
- 基于Selenium的Java爬虫实战(内含谷歌浏览器Chrom和Chromedriver版本127.0.6486.0)
- 基于FPGA的CORDIC算法旋转模式实现
- bilibili视频解析下载源码
- 基于Selenium的Java爬虫实战(内含谷歌浏览器Chrom和Chromedriver版本124.0.6367.60)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功