Question

In: Computer Science

[ Write in C not C++] 1. Define a C structure Covid19Info to store the information...

[ 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]

Solutions

Expert Solution

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 */


Related Solutions

Programming assignment 4 : C++ Write a program to do the following: 1.Define a structure to...
Programming assignment 4 : C++ Write a program to do the following: 1.Define a structure to store a date, which includes day(int), month(int), and year(int). 2.Define a structure to store an address, which includes address(house number and street)(string), city(string), state(string), zip code (string). 3.Define a class to store the following information about a student. It should include private member variables: name(string), ID (int), date of birth (the first structure), address (the second structure), total credit earned (int), and GPA (double)....
C++ program: Define a structure to hold the contact's information including: name, phone number, and a...
C++ program: Define a structure to hold the contact's information including: name, phone number, and a pointer to the next node on the list. Each node on the list will be a contact instead of a number (like the example in the book). struct ContactNode { string name; string phoneNumber; ContactNode *next; } Define a class containing the structure, private member variable head (that will point to the beginning of the list) and the following member functions: A constructor that...
Please write in C. This program will store roster and rating information for a soccer team....
Please write in C. This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers in one int array and the ratings in another int array. Output these arrays (i.e., output the roster). (3 pts) ex Enter player 1's jersey number:...
A) csc 401 c++ Write a class CorpData to store the following information on a company...
A) csc 401 c++ Write a class CorpData to store the following information on a company division: a. Division name (such as East, West, North, or South) b. First quarter sales c. Second quarter sales d. Third quarter sales e. Fourth quarter sales Include a constructor that allows the division name and four quarterly sales amounts to be specified at the time a CorpData object is created. The program should create four CorpData objects, each representing one of the following...
Write a program that does the following in C++ 1 ) Write the following store data...
Write a program that does the following in C++ 1 ) Write the following store data to a file (should be in main) DC Tourism Expenses 100.20 Revenue 200.50 Maryland Tourism Expenses 150.33 Revenue 210.33 Virginia Tourism Expenses 140.00 Revenue 230.00 2 ) Print the following heading: (should be in heading function) Store name | Profit [Note: use setw to make sure all your columns line up properly] 3 ) Read the store data for one store (should be in...
C Language Let us define a Point type to store two-dimensional coordinates (x, y)! Write the...
C Language Let us define a Point type to store two-dimensional coordinates (x, y)! Write the following functions operating on this data type: dist(): calculates the distance between the two points received (using the Pythagorean theorem) equal(): checks if to points are equal or not read(): reads a point from the keyboard and returns it In the main, define two points, and test all these functions. When all tests are passed, solve the following task by utilizing the structure and...
In C++ Write the definition for following methods of List data structure. 1. setList – The...
In C++ Write the definition for following methods of List data structure. 1. setList – The function set the value of list elements equal to a value passed as the function input. 2. getAt – The function returns an element of the list referred by its position which is given to the function as input. 3. insertAt – The function inserts a given element passed as function input in the list at the specified position also passed as second function...
Write a program that uses a structure to store the following weather data for a particular...
Write a program that uses a structure to store the following weather data for a particular month: Total Rainfall High Temperature Low Temperature Average Temperature. The program should have an array of 12 structures to hold weather data for an entire year. When the program runs, it should ask the user to enter data for each month. (The average temperature should be calculated.) Once the data are entered for all the months, the program should calculate and display the average...
(MUST BE DONE IN C (NOT C++)) Instead of using two different variables, define a structure...
(MUST BE DONE IN C (NOT C++)) Instead of using two different variables, define a structure with two members; one representing the feet and the other one representing the inches. You will also use three functions; one to initialize a structure, another one to check the validity of its values and one last one to print them out. First, go ahead and define your structure. Next, declare a structure of this type inside main. Then, call your first function (this...
Write a program in C language 1- Define a struct for students with the aforementioned attributes,...
Write a program in C language 1- Define a struct for students with the aforementioned attributes, test it by populating one initialized struct variable with arbitrary input and take screenshots of the output. 2- For each student, struct add an array of number grades for a class the students are enrolled in such as S E 185. Then write functions which find the max, average, and minimum score for a specified assignment identified by a number, for example, Assignment 0...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT