Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with this. Requirements: Output file should be like this Template that you can follow: (make the population to 5000 for faster runtime)

Please help me with this.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Requirements:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Output file should be like this

image text in transcribed

Template that you can follow: (make the population to 5000 for faster runtime)image text in transcribed

image text in transcribedimage text in transcribed

This is in C. This program is mainly on random number generator and on arrays, loops, and conditional statements. Develop a program that simulates the spread of COVID-19 and the effectiveness of prevention mechanisms. Consider a closed community with a population of 5000 people, out of which some have tested positive for COVID. Each day, a person may interact with some random number of people randomly from the population. If a healthy person interacts with one who has tested positive, the healthy person will get infected with a certain probability. If that happens, on the second day, the infected person will be considered as tested positive and may infect others whom he/she interacts with. After 14 days, the infected person will be fully recovered. There are several COVID prevention mechanisms, (1) face mask: wearing face mask will reduce the probability that a healthy person being infected and the probability that a test positive person infecting others; (2) COVID vaccine: a person who is vaccinated will have a much lower probability of being infected; (3) quarantine: if a person who is tested positive is quarantined, he/she will not interact with anyone until he/she becomes healthy again (and thus will not infect anybody). Command Line Safety Checks (refer to requirements 1-3) a.out k1 k2 k3 k4 k5 In file Out file argc each argv[] files atoi(argv[1]): convert to an integer This is the input from the input file probability of being infected without any protection: 0.8 probability of being infected if the healthy person wears face mask: 0.5 probability of being infected if the infected person wears face mask: 0.4 probability of being infected after receiving vaccine: 0.1 Read this data from the formatted file by using fscanf(IN, "probability of being infected without any protection:%f", &a); or skip the non digital characters and then use %f to take the real value. The program flow should look like this: -safety check and open files -command line -input/output files -read input and store data -run simulation day by day and write output weekly -close all files For the simulation, on every day for each (not quarantined) person, (1) generate a random number m between 0 and 20, (ii) choose m random persons (who are not quarantined) to interact with. Transition of health status 0:healthy 1: infected 2: recovered 3: quarantined If condition not met, status no change O to 1: interact with an infected person and get infected 1 to 2: after 14 days 1 to 3: if gets to be quarantined 3 to 2: after 14 days Like so, WHEN status = 0 1. Select random number r 2. Select r random non-quarantined persons 3. Interact with each of the r selected persons if interact with an infected person {if get infected { update information (status CANNOT be changed here!!!) } } When, status = 1 1. Decide whether needs to be quarantined 2. If so, update information; // no interactions this day // this day will be the first day of quarantine 3. If not, select non-quarantined persons to interact // similar to the case of status = 0; When, status = 2: will not infect healthy person, will not get infected, do nothing. When, Status = 3: 1. If quarantined 14 days { update information (status = 2); can make interactions; } 2. If not, days quarantined++; Finding non-quarantined persons Approach 1: 1. Select a random person A[i] 2.if (A[i] is quarantined, has been picked already, or is itself) 3.go back to step 1. 4.If need more persons, go back to 1 Approach 2: 1. Create the non-quarantined list w/o self 2. Select a random person from list 1, and remove the person from the list. 3.If need more persons, go back to 1. 2. General Requirements: 1. Your program will begin with the following command: a.out ki k2 k3 k4 k5 In_file Out_file a.out is the executable file; In_file and out_file are the names of the input and output files; the five arguments in the middle are all integers: kl: the number of weeks to run the simulation; k2: the percentage of infected people initially in the population; k3: the percentage of population who wear face masks; k4: the percentage of population who are vaccinated; k5: the probability that an infected person will be quarantined. Your program should initially verify the followings for the correctness of the command line arguments: a. The number of command line arguments must be 8, including a.out b. kl is between 1 and 52, k2 k3 k4 and k5 are all between 0 and 100. c. Your program must be able to open files In_file and Out_file for read and write. If there is any violation, your program should print out the corresponding error message and terminate. If there are more than one errors in the command line, printing out any one of them will be ok. 3. Each person in the simulation will have many features, you need to define a structure that captures them. You can use either the following one or the one you defined in Phase I as long as it contains all the required information for the simulation. typedef struct person_t int ID; int mask; 7/0: not wear face mask; 1: wear face mask; int vaccine; //0: not vaccinated; 1: vaccinated; int status; 1/0: healthy; 1: infected; 2: recovered; 3: quarantined int days infected; // will recover after 14 days int days_quarantined; // quarantine will be over after 14 days | Person; 4. Upon valid command line arguments, your program should first initialize the population by determining (1) N*k2 initially infected person randomly; (2) N*k3 random person who will wear face masks every day; (3) N*k4 random person who have been vaccinated; (4) for each infected person, whether he/she is quarantined. The N-Person population should be updated accordingly. 5. The simulation needs to run day by day for 7*k1 days. On each day, a person will interact with m randomly selected persons, where m is generated randomly between 0 and 20 (0 means that the person will not interact with anyone). A person's features need to be updated based on the following rules: R01. A healthy person may get infected by an infected person when they interact (see item 6 for details). R02. A newly infected person will be able to infect others on the next day. R03. An infected person will have a fully recover after 14 days. R04. A recovered person will not get infected again. R05. Initially, there might be infected person(s), but there will be no recovered ones. R06. An infected person will be tested daily until he/she recovers or is tested positive and sent for quarantine (no interact that day and quarantine starts immediately). R07. A quarantined infected person will not make any interact with others. R08. Quarantine will be for 14 consecutive days. R09. Any two person can interact at most once per day. R10. Wearing face mask reduces the chance of spreading the virus. R11. Receiving vaccine reduces the chance of getting infected. R12. For simplicity, when person A chooses person B to interact with, it does not matter whether person B has chosen person A or not in the same day. This means that (1) it is ok to have A interacts with B, but B does not choose A to interact with; (2) if A chooses B and B also chooses A, this will be considered as two separate interactions, which means that the chance of A or B, whoever is healthy, getting infected will be considered twice. For example, if a healthy person gets infected on Mar. 1, he will not spread the virus to other people he interacts later on Mar. 1. On Mar. 2, he (1) is considered infected", (2) starts the first day of recovery, and (3) may be sent for quarantine with probability k5%. On Mar. 16, he will (4) have 14 full days after getting infected, (5) be considered fully recovered, and (6) start interact with others, if he is not quarantined (see next). However, if on Mar. 10, for example, he is sent to quarantine according to (3), he will (7) be considered quarantined" on Mar. 10, (8) start the first day of his 14-day quarantine on Mar. 10, and (9) get out of quarantine on Mar. 24. During Mar. 16 and Mar. 23, he must remain quarantined although he is technically fully recovered, which means that he cannot have any interact. He will start interact with others on Mar. 24. 6. The input file has the probabilities of the spreading of the virus that you need to run the simulation. Here is a sample input file. probability of being infected without any protection: 0.8 probability of being infected if the healthy person wears face mask: 0.5 probability of being infected if the infected person wears face mask: 0.4 probability of being infected after receiving vaccine: 0.1 Virus spreads only when a healthy person (say Alice) and an infected person (say Bob) interact. Using the above values as an example, Alice will have 80% chance to be infected without any protection (face mask or vaccine); if Alice wears face mask, but Bob does not, the chance drops to 50%; if Alice does not, but Bob wears, the chance becomes 40%; if both Alice and Bob wear face mask, the chance becomes 50%*40%=20%; if Alice has received vaccine, the above chances will go down to 8%, 5%, 4%, and 2%, respectively (that is, 10% of the previous value). Whether Bob get vaccine or not has nothing to do with the chance that Alice gets infected. At the end of each week (after every seven consecutive days of simulation), you need to report the status of the simulation to the output file. Here is part of a toy output file where the population is 20. 7. WEEK01: Healthy = 15, Infected = 5, Masked = 2, Vaccinated = 0. Infected Persons (5): 0, 2, 5, 13, 14 Persons wearing masks (2): 2, 7 Persons receiving vaccine (0): WEEK01: Healthy WEEK02: Healthy WEEK03: Healthy WEEK04: Healthy WEEK05: Healthy 7, New Cases 6, New Cases 13, New Cases 19, New Cases = 20, New Cases - 8, Total Cases 6, Total Cases = 1, Total Cases 0, Total Cases = 0, Total Cases = 13. 19. 20. 20. 20. The first part of the output file shows the information before the simulation starts. The first lines shows the number of people that are healthy, infected, wearing masks, and vaccinated, respectively. The next three lines list the ID of those who are infected, wearing masks, and receiving vaccine. The second part of the output file reports weekly update for kl weeks, one line per week. Healthy is the number of people who are healthy (including those who have recovered regardless whether they are quarantined or not) by the end of that week; New Cases represent the number of people who get infected in that week; Total Cases is the accumulative number of people who has got infected (including those who are initially infected). Use 6 spaces as the printing area for each number. In the above example, initially there are 15 healthy people, 5 infected, 2 will wear face masks, and nobody has received the vaccine. During week 1, 8 healthy people are infected (New Cases) which brings the Total Cases to 13 (5+8) and number of Healthy down to 7 (15-8). In week 2, 6 (out of the 7) healthy people are infected and the initial 5 infected people have fully recovered. Thus we have a total of 6 Healthy people (1+5), 6 New Cases and 19 Total Cases (6+13). In week 3, the last person who has been infected yet becomes the only New Case for the week and Total Cases becomes 20 (1+19), the entire population. Meanwhile, 8 people who were infected in week 1 have recovered, so we have 13 Healthy (5 recovered in week 2 and 8 recovered in week 3). At the end of week 5, all 20 people will have got infected and fully recovered, so nobody will get infected again. The pandemic will be over! . WEEKOO: Healthy = 450, Infected = 50, Masked = 100, Vaccinated = 0. Infected Persons (50): 2, 12, 24, 27, 33, 34, 43, 54, 60, 75, 76, 84, 85, 91, 102, 117, 1 20, 136, 142, 152, 153, 161, 165, 166, 184, 199, 243, 269, 277, 290, 294, 302, 307, 310, 311, 314, 322, 335, 338, 384, 388, 389, 395, 420, 430, 440, 442, 466, 473, 476 Persons wearing masks (100): 1, 6, 11, 13, 14, 15, 26, 32, 39, 41, 49, 50, 54, 57, 61, 64 67, 72, 77, 82, 85, 89, 93, 102, 103, 110, 112, 119, 127, 130, 131, 138, 152, 153, 157, 162, 168, 170, 178, 180, 185, 186, 205, 206, 207, 209, 211, 213, 216, 217, 223, 231, 234 , 244, 255, 259, 270, 273, 274, 275, 278, 281, 285, 297, 298, 304, 311, 318, 326, 329, 331 1, 333, 353, 364, 367, 370, 378, 388, 390, 394, 395, 401, 404, 422, 431, 433, 438, 441, 4 47, 452, 457, 459, 466, 470, 478, 488, 484, 486, 495, 498 Persons receiving vaccine (0): WEEK01: Healthy = 350, New Cases = 100, Total Cases = 150. WEEKO2: Healthy = 264, New Cases = 86, Total Cases = 236. WEEK@3: Healthy = 380, New Cases = 7, Total Cases = 243. WEEK04: Healthy = 489, New Cases = e, Total Cases = 243. WEEK05: Healthy = 500, New Cases = @, Total Cases = 243. A programming template/outline just for your reference. It is by no means a complete program or defines all the necessary variables. You do not have to follow it. /* project header */ #include #include #include typedef struct person_ ! int ID; int mask; //0: not wear face mask; 1: wear face mask; int vaccine; //0: not vaccinated; 1: vaccinated; int status; 1/0: healthy; 1: infected; 2: recovered; 3: quarantined int days_infected; // will recover after 14 days int days_quarantined; // quarantine will be over after 14 days } Person; #define POPULATION 50000 // define global variables // define function prototypes with documentation void Initialization (...); // document this function void Simulation (...); // document this function int main(int argc, char * argv (1) { // declare variables that you need to keep information; // use comments to document these variables int days 0; // number of days to run the simulation, provided // by the user from command line (as number of weeks) float p_infection; // probability of getting infected without protection FILE *IN, *OUT; // FILE pointers for the two files int i, j, k; // temporary variables such as loop variables Person A[POPULATION]; // an array of people for the population // check command line argument and input/output files, terminate on error; // getting values of the parameters from the command line and input file; days - 7*atoi (argv[1]); // value from the command line fscanf(IN, "%f",&p_infection); // value from input file Initialization (OUT, A,p_infection, ...); // add other necessary parameters for the function call // initialize the population based on the obtained value // these information will be printed to the output file for (i=0; i #include #include typedef struct person_ ! int ID; int mask; //0: not wear face mask; 1: wear face mask; int vaccine; //0: not vaccinated; 1: vaccinated; int status; 1/0: healthy; 1: infected; 2: recovered; 3: quarantined int days_infected; // will recover after 14 days int days_quarantined; // quarantine will be over after 14 days } Person; #define POPULATION 50000 // define global variables // define function prototypes with documentation void Initialization (...); // document this function void Simulation (...); // document this function int main(int argc, char * argv (1) { // declare variables that you need to keep information; // use comments to document these variables int days 0; // number of days to run the simulation, provided // by the user from command line (as number of weeks) float p_infection; // probability of getting infected without protection FILE *IN, *OUT; // FILE pointers for the two files int i, j, k; // temporary variables such as loop variables Person A[POPULATION]; // an array of people for the population // check command line argument and input/output files, terminate on error; // getting values of the parameters from the command line and input file; days - 7*atoi (argv[1]); // value from the command line fscanf(IN, "%f",&p_infection); // value from input file Initialization (OUT, A,p_infection, ...); // add other necessary parameters for the function call // initialize the population based on the obtained value // these information will be printed to the output file for (i=0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago