目录
代码部分
#include <iostream>
#include <iomanip>
using namespace std;
int total1=0,total2=0,total3=0;
struct Provinces
{
string Province;
int New;
int Diagnosis;
int Cured;
int Dead;
};
void Input(Provinces ProvincesList[],int & total)
{
int i=1;total=0;total1=0;total2=0;total3=0;
cout<<"请录入34个省级行政区的疫情信息:\n省 新增 确诊 治愈 死亡"<<endl;
while(1)
{
cout<<"第"<<i<<"个:"<<endl;
cin>>ProvincesList[i].Province;
cin>>ProvincesList[i].New>>ProvincesList[i].Diagnosis>>ProvincesList[i].Cured>>ProvincesList[i].Dead;
total=total+ProvincesList[i].Diagnosis;
total1=total1+ProvincesList[i].Cured;
total2=total2+ProvincesList[i].Dead;
total3=total3+ProvincesList[i].New;
i++;
if(i>34)
{
cout<<"录入完毕"<<endl;
break;
}
}
}
void Output(Provinces ProvincesList[],int total)
{
cout<<"---------------------------------------------------------------"<<endl;
cout<<"全国\n新增:"<<total3<<"\n确诊:"<<total<<"\n治愈:"<<total1<<"\n死亡:"<<total2<<"\n治愈率:"<<setiosflags(ios::fixed)<<setprecision(2)<<(double)total1/total*100<<"%"<<"\n死亡率:"<<(double)total2/total*100<<"%"<<endl;
cout<<"---------------------------------------------------------------"<<endl;
cout<<"省\t新增\t确诊\t治愈\t死亡\t占比\t治愈率\t死亡率"<<endl;
int i=1;
while(1)
{
cout<<ProvincesList[i].Province<<"\t"<<ProvincesList[i].New<<"\t"<<ProvincesList[i].Diagnosis<<"\t"<<ProvincesList[i].Cured<<"\t"<<ProvincesList[i].Dead<<"\t"<<setiosflags(ios::fixed)<<setprecision(2)<<(double)ProvincesList[i].Diagnosis/total*100<<"%\t"<<(double)ProvincesList[i].Cured/ProvincesList[i].Diagnosis*100<<"%\t"<<(double)ProvincesList[i].Dead/ProvincesList[i].Diagnosis*100<<"%"<<endl;
i++;
if(i>34)
{
cout<<"---------------------------------------------------------------"<<endl;
break;
}
}
cout<<"湖北以外"<<total3-ProvincesList[1].New<<"\t"<<total-ProvincesList[1].Diagnosis<<"\t"<<total1-ProvincesList[1].Cured<<"\t"<<total2-ProvincesList[1].Dead<<"\t"<<setiosflags(ios::fixed)<<setprecision(2)<<(double)(total-ProvincesList[1].Diagnosis)/total*100<<"%\t"<<(double)((total1-ProvincesList[1].Cured)/(double)(total-ProvincesList[1].Diagnosis))*100<<"%\t"<<(double)((total2-ProvincesList[1].Dead)/(double)(total-ProvincesList[1].Diagnosis))*100<<"%\t"<<endl;
}
void Input1(Provinces ProvincesList[],int & total)
{
int i=1;total=0;total1=0;total2=0;total3=0;
cout<<"请录入17个市的疫情信息:\n市 新增 确诊 治愈 死亡"<<endl;
while(1)
{
cout<<"第"<<i<<"个:"<<endl;
cin>>ProvincesList[i].Province;
cin>>ProvincesList[i].New>>ProvincesList[i].Diagnosis>>ProvincesList[i].Cured>>ProvincesList[i].Dead;
total=total+ProvincesList[i].Diagnosis;
total1=total1+ProvincesList[i].Cured;
total2=total2+ProvincesList[i].Dead;
total3=total3+ProvincesList[i].New;
i++;
if(i>17)
{
cout<<"录入完毕"<<endl;
break;
}
}
}
void Output1(Provinces ProvincesList[],int total)
{
cout<<"---------------------------------------------------------------"<<endl;
cout<<"湖北\n新增:"<<total3<<"\n确诊:"<<total<<"\n治愈:"<<total1<<"\n死亡:"<<total2<<"\n治愈率:"<<setiosflags(ios::fixed)<<setprecision(2)<<(double)total1/total*100<<"%"<<"\n死亡率:"<<(double)total2/total*100<<"%"<<endl;
cout<<"---------------------------------------------------------------"<<endl;
cout<<"市\t新增\t确诊\t治愈\t死亡\t占比\t治愈率\t死亡率"<<endl;
int i=1;
while(1)
{
cout<<ProvincesList[i].Province<<"\t"<<ProvincesList[i].New<<"\t"<<ProvincesList[i].Diagnosis<<"\t"<<ProvincesList[i].Cured<<"\t"<<ProvincesList[i].Dead<<"\t"<<setiosflags(ios::fixed)<<setprecision(2)<<(double)ProvincesList[i].Diagnosis/total*100<<"%\t"<<(double)ProvincesList[i].Cured/ProvincesList[i].Diagnosis*100<<"%\t"<<(double)ProvincesList[i].Dead/ProvincesList[i].Diagnosis*100<<"%"<<endl;
i++;
if(i>17)
{
cout<<"---------------------------------------------------------------"<<endl;
break;
}
}
cout<<"武汉以外"<<total3-ProvincesList[1].New<<"\t"<<total-ProvincesList[1].Diagnosis<<"\t"<<total1-ProvincesList[1].Cured<<"\t"<<total2-ProvincesList[1].Dead<<"\t"<<setiosflags(ios::fixed)<<setprecision(2)<<(double)(total-ProvincesList[1].Diagnosis)/total*100<<"%\t"<<(double)((total1-ProvincesList[1].Cured)/(double)(total-ProvincesList[1].Diagnosis))*100<<"%\t"<<(double)((total2-ProvincesList[1].Dead)/(double)(total-ProvincesList[1].Diagnosis))*100<<"%\t"<<endl;
}
int main()
{
Provinces ProvincesList[100];int total=0;
while(1)
{
cout<<"---------------------------------------------------------------"<<endl;
cout<<"新冠肺炎疫情分析系统\n1)全国分析\n2)湖北分析\n3)退出\n请选择要进行的操作:";
char ch;
cin>>ch;
switch(ch)
{
case '1':Input(ProvincesList,total);
Output(ProvincesList,total);
system("pause");
break;
case '2':Input1(ProvincesList,total);
Output1(ProvincesList,total);
system("pause");
break;
case '3':exit(0);
}
}
}
用户界面
数据来源及数据处理
数据来源:百度-最新疫情地图实时数据报告
数据处理:在文本文档中将tab替换为空格,然后将“-”替换为“0”,复制粘贴即可。
数据展示
2月10日数据
2月11日数据
2月12日数据
2月13日数据
2月14日数据
2月15日数据
2月16日数据
2月17日数据
2月18日更新
2月19日数据
2月20日数据
----------------------------------------------------------------------------------------------------------------------------------
全国新型肺炎疫情最新数据接口
http://www.tianqiapi.com/index/doc?version=epidemic
使用JSON - 学习 Web 开发 | MDN
还可以增加一些功能:
保存历史数据
爬取数据
各项参数升序降序排列
自动生成文本报告
可视化界面
窗体
总结:
#include <iomanip>
struct Provinces
{
};//结构体 分号
void Input(Provinces ProvincesList[],int & total)
//数组作为函数参数无需引用&,因为数组名就是地址,无需取地址
setiosflags(ios::fixed)<<setprecision(2)<<(double)total1/total*100<<"%"
system("pause");
原博地址
https://blog.csdn.net/weixin_43673589