In: Computer Science
[ Write in C not C++]
1. Define a C structure Covid19Info to store the information of
COVID 19 cases of
countries around the world. It keeps the name of the country,
number of COVID 19
cases, number of deaths, current test positive rate, etc. After
defining the structure,
declare a variable of Covid19Info type with some initial values for
Bangladesh. [8]
IF I am getting this right your just need to implement a structure in c here you just ask to store but u didn't specify what operations u want to do in that data
according to your question
we declare structure which include a string which store name ,and 2 two int type for no of covid case and death and one float type variable for test positive rate
so we declare it globally in our program ..
our program look like this
#include<stdio.h>//for using printf()
struct Covid19Info{
char countryName[25];
int deathsInCountry;
int casesInCountry;
float testPositiveRate;
}; //structure that store data of a country
int main()
{
/* for storing data of multiple countries we can use array of structure type Covid19Info but here they only asked for one country so we de declare with struct variable with country name
struct Covid19Info Bangladesh; //declaring the variable
//for accessing members of structure we can use (.) or (->)
//inserting data in variable in format name, case, death ,rate
//taking input form user
scanf("%s %d %d %f", Bangladesh.countryName, &Bangladesh.casesInCountry, &Bangladesh.deathsInCountry, &Bangladesh.testPositiveRate); //i think best practice is you should using four different scanf function and using printf for labeling every input
printf("%s %d %d %f", Bangladesh.countryName, Bangladesh.casesInCountry, Bangladesh.deathsInCountry, Bangladesh.testPositiveRate);
return 0;
}
// in above function we taking input from user otherwise we can directly assign values if we need to store more countries we can use array and we can apply searching on them using O(n) time complexity
as it is given in question we can directly assign data in Bangladesh variable
replace scanf of above code with this:
struct Covid19Info Bangladesh = {"Bangladesh", 2000 , 200, 38.20} //initialising at time of declaration
// or we can do after declaration like this :
Bangladesh.casesInCountry=20000;
Bangladesh.deathsInCountry=200;
Bangladesh.testPositiveRate= 38.20;
char country[25]="Bangladesh";
strcpy(Bangladesh.countryName,country);
/* like other data type string not support assignment operator after declaration string and array are second-class citizens in C so either we assign value at time of declaration and we use the way i showed u above but this is unnessasary so better way is we can assign values at time of declaration of variable */