Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program to simulate a disease outbreak within a region and determine how many days the outbreak lasted. You will be using an

Write a C++ program to simulate a disease outbreak within a region and determine how many days the outbreak lasted. You will be using an SIR model to model the disease progression in a person, and a cellular automata to represent the population in the geographic region. Your program will simulate the disease outbreak one day at a time until no infectious people are left.


Requirements:

You will need to declare a global integer constant called SIZE and initialize it to 7.

You will need to declare and define a function to initialize the value of all slots in an array to ‘s’ • It should have a two-dimensional char array and an integer as its parameters.

• It should not return a value.

You will need to declare and define a function to output the char value of every slot in an array in a grid format o It should have a two-dimensional char array and an integer as its parameters. It should not return a value.

You will need to declare and define a function to count the total number of ‘i’ in an array. It should then return that count.

• It should have a two-dimensional char array and an integer as its parameters.

• It should return an integer value

You will need to declare and define a function to allow for infectious people (i) to become recovered (r). For each ‘i’ in the current day, the function should update the corresponding slot in a next day’s array to ‘r’. Once all of the appropriate slots in the next day’s array have been set to ‘r’, you should update all of the values in the current day’s array with all of the values in the next’s day array. By using two arrays, this avoids any problems that may be incurred by updating values in place, such accidentally infecting people who should not be infected, or not infecting people who should be infected. It should have two, two-dimensional char arrays and an integer as its parameters. It should not return a value.

You will need to declare and define a function spread the disease across the region. For each ‘s’ in the current day the function should examine the surrounding 8, 5, or 3 slots (depending on if the ‘s’ is in the middle of the array, on a border, or in a corner respectively) and if any of the surrounding slots contain an ‘i’, the position of the examined ‘s’ should be set to ‘i’ in next day’s array. By updating using two arrays this prevent accidental infecting of people who are not near any infectious people (i) today, but will be tomorrow..

It should have two, two-dimensional char arrays and an integer as its parameters. o It should not return a value.

• Make sure you perform correct bounds checking on the arrays.

Inside your main function, you will need to

Create two SIZExSIZE two-dimensional char arrays, one to represent the current day’s region, and one to represent the next day’s region.

Create two integers to store user-defined coordinates of which slot they would like to infect. o Create one integer to store the day number, and it should be initialized to 0.

You will need to initialize both char arrays to all ‘s’ using the appropriate function. Be sure to use SIZE when passing in the size of the arrays.

You will then need to prompt for and read in two integers representing the x and y coordinates of where the infected person will be, and store them in the appropriate variables. Be sure to check if the input values are within the bounds of the region, and if they are not, politely, repeatedly prompt the user for correct coordinates.

• Using the user’s coordinates, you should set those positions in the current day’s array to ‘i’.

• Then, you should print out the current day value with an appropriate label, and print out the state of current day’s region using the appropriate function.

Next, you should simulate the spread of the disease. This should be done by first using your function to examine the current day’s array and setting the appropriate slots in the next day’s array to ‘i’. Next, you need to use the appropriate function to set all of the current day’s ‘i’ to ‘r’ in the next day array, and then overwrite the current day’s array with the next day’s array. Finally, you should print out the current day value and the current day’s region using the appropriate function. You should continue doing this until the current day’s region does not contain any ‘i’.

Finally, your program should print out the total number of days the outbreak lasted with an appropriate message.

Step by Step Solution

3.47 Rating (157 Votes )

There are 3 Steps involved in it

Step: 1

C program to simulate a disease outbreak include using namespace std const int SIZE 7 func... 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

Document Format ( 2 attachments)

PDF file Icon
609528da99dfc_25606.pdf

180 KBs PDF File

Word file Icon
609528da99dfc_25606.docx

120 KBs Word File

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

Business Statistics For Contemporary Decision Making

Authors: Black Ken

8th Edition

978-1118494769, 1118800842, 1118494768, 9781118800843, 978-1118749647

More Books

Students also viewed these Programming questions

Question

6-25. How is fraudulent intent established without a confession?

Answered: 1 week ago