#include <iostream>
#include <iomanip>
// Class representing the Epidemic Model
class EpidemicModel {
public:
EpidemicModel(double initialSusceptible, double initialInfected, double initialRecovered,
double infectionRate, double recoveryRate, double timeStep)
: susceptible(initialSusceptible), infected(initialInfected), recovered(initialRecovered),
infectionRate(infectionRate), recoveryRate(recoveryRate), timeStep(timeStep) {}
void simulate(double totalTime) {
std::cout << std::fixed << std::setprecision(2);
std::cout << "Time\tSusceptible\tInfected\tRecovered\n";
for (double t = 0; t <= totalTime; t += timeStep) {
// Output current state
std::cout << t << "\t" << susceptible << "\t" << infected << "\t" << recovered << "\n";
// Calculate changes
double newInfections = infectionRate * susceptible * infected;
double newRecoveries = recoveryRate * infected;
// Update states
susceptible -= newInfections * timeStep;
infected += (newInfections - newRecoveries) * timeStep;
recovered += newRecoveries * timeStep;
// Ensure values remain within bounds
if (susceptible < 0) susceptible = 0;
if (infected < 0) infected = 0;
if (recovered < 0) recovered = 0;
}
}
private:
double susceptible;
double infected;
double recovered;
double infectionRate;
double recoveryRate;
double timeStep;
};
int main() {
double initialSusceptible, initialInfected, initialRecovered;
double infectionRate, recoveryRate;
double timeStep, totalTime;
std::cout << "Enter initial number of susceptible individuals: ";
std::cin >> initialSusceptible;
std::cout << "Enter initial number of infected individuals: ";
std::cin >> initialInfected;
std::cout << "Enter initial number of recovered individuals: ";
std::cin >> initialRecovered;
std::cout << "Enter infection rate (per susceptible and infected): ";
std::cin >> infectionRate;
std::cout << "Enter recovery rate (per infected): ";
std::cin >> recoveryRate;
std::cout << "Enter time step (in days): ";
std::cin >> timeStep;
std::cout << "Enter total simulation time (in days): ";
std::cin >> totalTime;
EpidemicModel model(initialSusceptible, initialInfected, initialRecovered,
infectionRate, recoveryRate, timeStep);
model.simulate(totalTime);
return 0;
}