Q please explain the following code (step by step) #include #include using namespace std; int main() { string country[1000], cty, cty_update; int i=0,j,choice,max=0; long tot_pop[1000], infected_pop[1000], recovered_pop[1000]; while(true){ cout<<"1. Enter new records\n"; cout<<"2. Display records\n"; cout<<"3. Check highest infected cases\n"; cout<<"4. Update records\n"; cout<<"5. Exit\n"; cin>>choice; if(choice==1){ cout<<"Enter country\n"; cin>>country[i]; cout<<"Total Population?\n"; cin>>tot_pop[i]; cout<<"Total Infected?\n"; cin>>infected_pop[i]; cout<<"Total Recovered?\n"; cin>>recovered_pop[i]; if(infected_pop[i]>max){ max=infected_pop[i]; cty=country[i]; } i++; } if(choice==2){ for(j=0;j>cty_update; for(j=0;j>infected_pop[j]; cout<<"Enter new Recovered Population\n"; cin>>recovered_pop[j]; break; } } } if(choice==5) break; } return 0; }
Q please explain the following code
(step by step)
#include <iostream>
#include <string>
using namespace std;
int main() {
string country[1000], cty, cty_update;
int i=0,j,choice,max=0;
long tot_pop[1000], infected_pop[1000], recovered_pop[1000];
while(true){
cout<<"1. Enter new records\n";
cout<<"2. Display records\n";
cout<<"3. Check highest infected cases\n";
cout<<"4. Update records\n";
cout<<"5. Exit\n";
cin>>choice;
if(choice==1){
cout<<"Enter country\n";
cin>>country[i];
cout<<"Total Population?\n";
cin>>tot_pop[i];
cout<<"Total Infected?\n";
cin>>infected_pop[i];
cout<<"Total Recovered?\n";
cin>>recovered_pop[i];
if(infected_pop[i]>max){
max=infected_pop[i];
cty=country[i];
}
i++;
}
if(choice==2){
for(j=0;j<i;j++){
cout<<"Country = "<<country[j]<<endl;
cout<<"Total Population = "<<tot_pop[j]<<endl;
cout<<"Infected Population = "<<infected_pop[j]<<endl;
cout<<"Recovered Population = "<<recovered_pop[j]<<endl;
cout<<endl;
}
}
if(choice==3){
cout<<"\nCountry with highest infections is "<<cty<<" with number of infections = "<<max<<endl;
}
if(choice==4){
cout<<"Enter the country to update\n";
cin>>cty_update;
for(j=0;j<i;j++){
if(cty_update.compare(country[j])==0){
cout<<"Enter new infected Population\n";
cin>>infected_pop[j];
cout<<"Enter new Recovered Population\n";
cin>>recovered_pop[j];
break;
}
}
}
if(choice==5)
break;
}
return 0;
}
Step by step
Solved in 2 steps