#include <iostream>
#include <iomanip>
using namespace std;
int total1=0,total2=0;
struct Provinces
{
string Province;
int Diagnosis;
int Cured;
int Dead;
};
void Input(Provinces ProvincesList[],int & total)
{
int i=1;total=0;total1=0;total2=0;
cout<<"请录入34个省级行政区的疫情信息:\n省 确诊 治愈 死亡"<<endl;
while(1)
{
cout<<"第"<<i<<"个:"<<endl;
cin>>ProvincesList[i].Province;
cin>>ProvincesList[i].Diagnosis>>ProvincesList[i].Cured>>ProvincesList[i].Dead;
total=total+ProvincesList[i].Diagnosis;
total1=total1+ProvincesList[i].Cured;
total2=total2+ProvincesList[i].Dead;
i++;
if(i>34)
{
cout<<"录入完毕"<<endl;
break;
}
}
}
void Output(Provinces ProvincesList[],int total)
{
cout<<"--------------------------------------------------------"<<endl;
cout<<"全国\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死亡率"<<endl;
int i=1;
while(1)
{
cout<<ProvincesList[i].Province<<"\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<<"湖北以外"<<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;
cout<<"请录入17个市的疫情信息:\n市 确诊 治愈 死亡"<<endl;
while(1)
{
cout<<"第"<<i<<"个:"<<endl;
cin>>ProvincesList[i].Province;
cin>>ProvincesList[i].Diagnosis>>ProvincesList[i].Cured>>ProvincesList[i].Dead;
total=total+ProvincesList[i].Diagnosis;
total1=total1+ProvincesList[i].Cured;
total2=total2+ProvincesList[i].Dead;
i++;
if(i>17)
{
cout<<"录入完毕"<<endl;
break;
}
}
}
void Output1(Provinces ProvincesList[],int total)
{
cout<<"--------------------------------------------------------"<<endl;
cout<<"全省\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死亡率"<<endl;
int i=1;
while(1)
{
cout<<ProvincesList[i].Province<<"\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<<"武汉以外"<<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日数据
分析:
随着疫情的发展,治愈率和死亡率均有所增加,其中全国治愈率大幅增加,死亡率略微上升。
湖北确诊占总确诊人数的74%,并逐渐增加。
武汉一市占湖北的58%,并逐渐增加。
全国除湖北外省份确诊人数与湖北除武汉外城市的确诊人数大致相当,两者之和与武汉确诊人数大致相当。
湖北地区的死亡率远高于湖北以外地区。
总结:
#include <iomanip>
struct Provinces
{
};//结构体 分号
void Input(Provinces ProvincesList[],int & total)
//数组作为函数参数无需引用&,因为数组名就是地址,无需取地址
setiosflags(ios::fixed)<<setprecision(2)<<(double)total1/total*100<<"%"
system("pause");
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。