Home > Back-end >  Virus fatality rate programs
Virus fatality rate programs

Time:09-25


Online for c + +, can you help to knock a this program,

CodePudding user response:

# include
# include
# include

using namespace std;

# define WIDTH 10

Struct EpidemicSituation
{
String nation;//region
Int the add;//new cases
Int cumulative;//the accumulative confirmed
Int cure;//cure for
Int death;//deaths
String getNation () {return nation; }
Int getAdd () {return the add; }
Int getCumulative () {return cumulative; }
Int getCure () {return cure; }
Int getDeath () {return death; }
Double getCureRate () {return cure * 1.0/cumulative * 100; }
Double getDeathRate () {return 1.0/cumulative death * * 100; }

EpidemicSituation ()=default;
~ EpidemicSituation ()=default;

EpidemicSituation (string s, int the add, int cumu, int cure, int death)
: the nation (s), add (add), cumulative (cumu), cure (cure), death (death)
{}
EpidemicSituation (const EpidemicSituation& Es)=default;

Ostream& ReadNation (ostream & amp; OS)//output region cases information
{
OS & lt; & lt; OS. Unsetf (ios: : fixed);
OS & lt; Return the OS;
}
};

Ostream& PrintNations (ostream & amp; OS, EpidemicSituation * p, size_t n)
{
OS & lt; """For (size_t I=0; i {
p-> ReadNation (OS) & lt; + + p;
}

Return the OS;
}

//exchange
Void swap (EpidemicSituation & amp; Pn1, EpidemicSituation & amp; Pn2)
{
EpidemicSituation pn=pn1;
Pn1=pn2;
Pn2=pn;
}


//to order according to the selected fields
Template
Void sortNation (EpidemicSituation * pse, size_t n, T (EpidemicSituation: : * f ())//f pointing to a member function
{
//USES bubble sort
For (size_t I=0; i {
For (size_t j=n - 1; J & gt; i; J -)
{
If ((pse [j]. J * f) (a) & gt; [j - 1]. (pse) * f ())
{
Swap (pse [j], pse [1]).
}
}
}
}


Int main ()
{

EpidemicSituation CONV19 [100].
Size_t number=0;//region

Cout & lt; Cout & lt; ""
String nation;//region
Int the add;//new cases
Int cumulative;//the accumulative confirmed
Int cure;//cure for
Int death;//deaths

//input around outbreak
While (cin & gt;> Nation)
{
If (nation=="null")
break;
Cin & gt;> The add & gt;> Cumulative & gt;> Cure & gt;> Death;
CONV19 [number] nation=nation;
CONV19 [number]. Add=add;
CONV19 [number]. Cumulative=cumulative;
CONV19 [number]. Cure=cure;
CONV19 [number]. Death=death;
+ + number;
}

Cout & lt; <"According to which field to sort? Please enter the corresponding field name, optional: "& lt;
"New diagnosed, the cumulative diagnose, cure, cure rate, death, mortality" & lt; String STR.
Cin & gt;> STR;
If (STR=="new confirmed")
SortNation (CONV19, number, & amp; EpidemicSituation: : getAdd);
Else if (STR=="cumulative confirmed")
SortNation (CONV19, number, & amp; EpidemicSituation: : getCumulative);
Else if (STR=="cure")
SortNation (CONV19, number, & amp; EpidemicSituation: : getCure);
Else if (STR=="rate")
SortNation (CONV19, number, & amp; EpidemicSituation: : getCureRate);
Else if (STR=="death")
SortNation (CONV19, number, & amp; EpidemicSituation: : getDeath);
Else if (STR=="mortality")
SortNation (CONV19, number, & amp; EpidemicSituation: : getDeathRate);
The else
Cout & lt; <"Error" & lt;
PrintNations (cout, CONV19, number);
return 0;
}
  • Related