PROGRAM DESCRIPTION: The purpose of this programming project is to write a C++ p
ID: 3869659 • Letter: P
Question
PROGRAM DESCRIPTION: The purpose of this programming project is to write a C++ program to simulate a disease outbreak and determine how many days the outbreak lasted using user input, branch statements, and loops. BACKGROUND: In disease modelling, one of the basic models is called the SIR model. SIR stands for Susceptible Infectious, and Recovered, which represent the different states a person can be in with regard to an illness. A susceptible person is someone who is not sick, but can become sick. An infectious person is someone who is sick and can infect others with the disease. A recovered person is someone who is no longer sick and has developed an immunity to the disease. To represent the process of being healthy, becoming sick, and recovering, we can use simple differential equations to compute the diseases progress over time. In this case we will be assuming each time step represents one day. To calculate the number of susceptible, infectious, and recovered individuals each day we can use the following equations: i-13i-1 In these equations, S, is the number of susceptible people on day i, l, is the number of infectious people on day i, Ri is the number of recovered people on day i, is the contact rate (the rate at which people come into contact with infectious individuals and become infected), and is the recovery rate (the rate at which people recover from the disease). Additionally, since we are using differential equations, to calculate the values of Si, I, and R, you need the values of the previous day's Su li, and Ri, values S1, 1, Ri1 A typical graph of the progression of an outbreak might look like the following, where the number of susceptible individuals decreases over time, the number of infectious individuals grows, peaks, and then decreases, and the number of recovered individuals grows over timeExplanation / Answer
1. Intialise the Day=0 values of Infected, Susceptible and Recovered count according to the criteria ie, Infected=user input count, Susceptible= Total Count- Infected, Recovered=0;
2. Create 2 set of variables Current day count and DayBefore count for each criterias ie. Infected, Recovered and Susceptible.
3. Loop through using while taking, with remaining Infected count as the test condition and keep track of the days using a counter. Calculate the current day's Susceptible, Infected and Recovered count using the formula provided. At the end assign the Current day's values to the Day before values and increment the counter.
4. In the end the counter value will provide the "Days outbreak took to end".
// OUTBREAK SIMULATOR
#include <iostream>
#include <string>
using namespace std;
int main()
{
//take input from the user for the total sample size and inital Infected individuals
int totalPop,initInfec;
//take input from theuser for the beta(contact rate) and gama(recovery rate).
double cRate,rRate;
//current day's Infected, Recovered and Susceptible population count
int curInfec,curRec,curSus;
//Day before [i-1] Infected, Recovered and Susceptible population count
int dbInfec,dbRec,dbSus;
//counter variable
int index=0;
cout<<"******************************************************************* ";
cout<<"Computer Science and Engineering ";
cout<<"CSCE 1030- Computer Science ";
cout<<"Student: Your Name 67ty-76ty-89yu-67ty your@name.com ";
cout<<"******************************************************************* ";
cout<<"Welcome to the outbreak simulator ";
//looped input until user provides valid inputs
//poulation count input
cout<<"Please enter a positive whole number for the total of the population you wish to simulate: ";
cin>>totalPop;
while(totalPop<1)
{
cout<<totalPop<<" is not positive whole number. Please enter a postive whole number for the total poulation: ";
cin>>totalPop;
}
//Infected individuals count input
cout<<"Please enter a positive whole number, less than total population for the number of Infectious individuals: ";
cin>>initInfec;
while(initInfec<1||initInfec>totalPop)
{
cout<<initInfec<<" is not positive whole number or is greater than the population count provided earlier.Please enter a positive whole number, less than total population for the number of Infectious individuals: ";
cin>>initInfec;
}
//Contact Rate input
cout<<"Please enter a positive whole number, greater than 0 but less than 1 for the contact rate: ";
cin>>cRate;
while(cRate>1||cRate<=0)
{
cout<<cRate<<" is not greater than 0 but less than 1.Please enter a positive whole number, greater than 0 but less than 1 for the contact rate: ";
cin>>cRate;
}
//Recovery Rate input
cout<<"Please enter a positive whole number, greater than 0 but less than 1 for the recovery rate: ";
cin>>rRate;
while(rRate>1||rRate<=0)
{
cout<<rRate<<" is not greater than 0 but less than 1.Please enter a positive whole number, greater than 0 but less than 1 for the recovery rate: ";
cin>>rRate;
}
//Intialization for the day-0
dbInfec=initInfec;
//Susceptible count is difference of Total and Infected count
dbSus=totalPop-initInfec;
//Intial Recovered count is 0
dbRec=0;
//Loop through until Infected count becomes->0
while(dbInfec>0)
{
curSus=dbSus-(cRate*dbInfec*dbSus);
curInfec=dbInfec+(cRate*dbInfec*dbSus)-rRate*dbInfec;
curRec=dbRec+rRate*dbInfec;
cout<<"Day :"<<index<<" S: "<<curSus<<" I: "<<curInfec<<" R: "<<curRec<<" ";
dbInfec=curInfec;
dbSus=curSus;
dbRec=curRec;
index++;
}
cout<<" ";
cout<<"The outbreak took "<<index<<" days to end";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.