Q1: Avian Flu Infection Simulation [30 points]
Avian flu is a headache for the livestock industry around the world. In this question, we will simulate the virus infection and recovery for the chickens in a farm. We use a one-dimensional array, called int farm[SIZE] , represent a planer area in the farm (i.e., like an x-y plane in your high school maths course). Each cell represents a chicken. The health level of that chicken is represented by the value kept in the cell, and we denote this value by k in this question.
When k <= 0, it means that the chicken gets infected. Furthermore, the chicken can spread the avian flu virus only if k is greater than or equal to a constant value, denoted by SPREAD_LEVEL.
When k > 1, the chicken is healthy. In this case, the chicken is immune to the virus transmission. Note that if the value of k is change from 0 to a positive value, the chicken is deemed recovered.
The rules for virus transmission are as follows.
When the value k of an infected chicken (identified by the index, say i, of the above- mentioned array) is no smaller than SPREAD_LEVEL and no greater than 0 (0 k SPREAD_LEVEL), the chicken can spread the avian flu virus to its adjacent chickens (i.e., spreading to the chicken in the cells with index i-1 or i+1). Note that the chicken at index i = 0 can only spread the virus to the chicken at index i = 1.
The transmission success rate is a probability value, denoted by INFECTED_PROB, which is in the range of [0, 1].
Healthy chickens (i.e., the chickens with k > 1) do not get infected.
When a chicken gets infected, the value k of that chicken drops from 1 to a constant value,
denoted by INFECTED_LEVEL. The health level is updated as follows.
The health level k of each infected chicken increases by one in each round. Furthermore, when an infected chicken gets recovery in a specific round, the value of k of that chicken increases to a constant value, denoted by IMMUNITY_LEVEL.
The health level k of each healthy chicken decreases by one in each round. When k = 1 is reached, k will stay at 1.
Your program should also fulfil the following requirements:
1. Define the symbols SIZE, IMMUNITY_LEVEL, SPREAD_LEVEL, INFECTED_LEVEL and INFECTED_PROB as C++ macros and set their values to 10, 4, -5, -7, and 0.2, respectively.
2. Initialize int farm[SIZE]. Make sure each cell in the array keeps a value within the range [INFECTED_LEVEL, IMMUNITY_LEVEL] at any time.
3. Each calendar day represents one round in the simulation. Print the content of the array farm and show the number of infected chickens for the current day and the next 30 days. If the number of infected chickens is zero, stop the simulation and print the following messages: The avian flu is over.
4. Format your output properly like the sample outputs.
Code Help, Add WeChat: cstutorcs
In
#include
using namespace std;
int main() {
/* initialize random seed: */
srand(5123456); // 5123456 is the seed to initialize the rand() function.
// toss a coin
int x = rand() % 101; // x is the value between 0 and 100, inclusively. cout << x;
if (x > 50)
cout << "Head" << endl; else
cout << "Tail" << endl; return 0;
The relationship between srand(N) and rand() is as follows:
N is a number. The function rand() actually is an algorithm that will generate a sequence of numbers based on the given seed N. Thus, by having the same value of N in executing the above program every time, the same result will be produced.
In the toss-a-coin example above, by replacing the constant 101 by another value, such as the VC2022 predefined macro RAND_MAX, you may get a random value in the range [0, RAND_MAX -1]. Based on the random value, as indicated in the example, the outcome based on the value of x can be stated in the program.
If students want exactly to reproduce the sample outputs below, use the following syntax to produce your random values in your solution for Q1.
• The sample outputs in Q1 below are based on the default seed value for rand() if the program does not call srand(N) beforehand.
• A probability value in the range of [0, 100) is randomly produced by the following statement:
double v = ((double) rand() )/ (RAND_MAX);
程序代写 CS代考 加QQ: 749389476
Sample outputs:
(Note that it is OK that your output may not look exactly the same as the sample output since the virus transmission is random.)
Assume int farm[SIZE] = { 1, 1, -3, 1, 1, 1, 1, 1, -3, 1};
Day 0: 1 1 -3 1 1 1 1 1 -3 1Thenumberofinfectedchickensis2 Day 1: 1 1 -2 1 1 1 1 1 -2 -7Thenumberofinfectedchickensis3 Day 2: 1 1 -1 1 1 1 1 1 -1 -6Thenumberofinfectedchickensis3 Day 3: 1 -7 0 -7 1 1 1 1 0 -5Thenumberofinfectedchickensis5 Day 4: 1 -6 4 -6 1 1 1 1 4 -4Thenumberofinfectedchickensis3 Day 5: 1 -5 3 -5 1 1 1 1 3 -3Thenumberofinfectedchickensis3 Day 6: -7 -4 2 -4 1 1 1 1 2 -2Thenumberofinfectedchickensis4 Day 7: -6 -3 1 -3 1 1 1 1 1 -1Thenumberofinfectedchickensis4 Day 8: -5 -2 1 -2 1 1 1 1 1 0Thenumberofinfectedchickensis4 Day 9: -4 -1 1 -1 -7 1 1 1 1 4Thenumberofinfectedchickensis4 Day10: -3 0 1 0 -6 1 1 1 1 3Thenumberofinfectedchickensis4 Day11: -2 4 1 4 -5 1 1 1 1 2Thenumberofinfectedchickensis2 Day12: -1 3 1 3 -4 1 1 1 1 1Thenumberofinfectedchickensis2 Day13: 0 2 1 2 -3 1 1 1 1 1Thenumberofinfectedchickensis2 Day14: 4 1 1 1 -2 1 1 1 1 1Thenumberofinfectedchickensis1 Day15: 3 1 1 1 -1 1 1 1 1 1Thenumberofinfectedchickensis1 Day16: 2 1 1 1 0 1 1 1 1 1Thenumberofinfectedchickensis1 Day17: 1 1 1 1 4 1 1 1 1 1Theavianfluisover.
Assumeint farm [SIZE] = { 1, 1, -3, 1, 1, 1, 1, 1, 1, -3};
Day 0: 1 1 -3 1 1 1 1 1 1 -3Thenumberofinfectedchickensis2 Day 1: 1 1 -2 1 1 1 1 1 1 -2Thenumberofinfectedchickensis2 Day 2: 1 -7 -1 1 1 1 1 1 1 -1Thenumberofinfectedchickensis3 Day 3: 1 -6 0 1 1 1 1 1 -7 0Thenumberofinfectedchickensis4 Day 4: 1 -5 4 -7 1 1 1 1 -6 4Thenumberofinfectedchickensis3 Day 5: 1 -4 3 -6 1 1 1 1 -5 3Thenumberofinfectedchickensis3 Day 6: 1 -3 2 -5 1 1 1 -7 -4 2Thenumberofinfectedchickensis4 Day 7: 1 -2 1 -4 1 1 1 -6 -3 1Thenumberofinfectedchickensis4 Day 8: 1 -1 1 -3 1 1 1 -5 -2 1Thenumberofinfectedchickensis4 Day 9: 1 0 1 -2 1 1 1 -4 -1 1Thenumberofinfectedchickensis4 Day10: 1 4 1 -1 1 1 1 -3 0 1Thenumberofinfectedchickensis3 Day11: 1 3 1 0 1 1 1 -2 4 1Thenumberofinfectedchickensis2 Day12: 1 2 1 4 1 1 -7 -1 3 1Thenumberofinfectedchickensis2 Day13: 1 1 1 3 1 1 -6 0 2 1Thenumberofinfectedchickensis2 Day14: 1 1 1 2 1 1 -5 4 1 1Thenumberofinfectedchickensis1 Day15: 1 1 1 1 1 1 -4 3 1 1Thenumberofinfectedchickensis1 Day16: 1 1 1 1 1 1 -3 2 1 1Thenumberofinfectedchickensis1 Day17: 1 1 1 1 1 -7 -2 1 1 1Thenumberofinfectedchickensis2 Day18: 1 1 1 1 1 -6 -1 1 1 1Thenumberofinfectedchickensis2 Day19: 1 1 1 1 1 -5 0 -7 1 1Thenumberofinfectedchickensis3 Day20: 1 1 1 1 -7 -4 4 -6 1 1Thenumberofinfectedchickensis3 Day21: 1 1 1 1 -6 -3 3 -5 1 1Thenumberofinfectedchickensis3 Day22: 1 1 1 1 -5 -2 2 -4 1 1Thenumberofinfectedchickensis3 Day23: 1 1 1 1 -4 -1 1 -3 1 1Thenumberofinfectedchickensis3 Day24: 1 1 1 1 -3 0 1 -2 1 1Thenumberofinfectedchickensis3 Day25: 1 1 1 -7 -2 4 -7 -1 1 1Thenumberofinfectedchickensis4 Day26: 1 1 1 -6 -1 3 -6 0 1 1Thenumberofinfectedchickensis4 Day27: 1 1 1 -5 0 2 -5 4 1 1Thenumberofinfectedchickensis3 Day28: 1 1 1 -4 4 1 -4 3 1 1Thenumberofinfectedchickensis2 Day29: 1 1 -7 -3 3 1 -3 2 1 1Thenumberofinfectedchickensis3 Day30: 1 1 -6 -2 2 1 -2 1 1 1Thenumberofinfectedchickensis3
Code Help