How to solve some errors in the code in c++
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
class Person { //creating a Person class with attributes like ID, latitude (X) and longitude (y)
public:
int x;
int y;
bool infected;
}; Person(int _id, int _x, int _y, bool _infected) : id(_id), x(_x), y(_y), infected(_infected) {}
void display(const Person people[], int numPeople) { // Display movements and infection status
system("cls"); // Clear console
for (int i = 0; i < numPeople; ++i) {
std::cout << "Person " << people[i].id << ": ";
std::cout << "Location (" << people[i].x << ", " << people[i].y << ")";
std::cout << " - Infected: " << (people[i].infected ? "Yes" : "No") << std::endl;
}
}
int main() {
srand(time(nullptr));
const int numPeople = 100; // creating 100 people with random locations and infections
const int numInfected = numPeople * 0.1;
const int n = 7; // Number of days for simulation
Person people[numPeople];
for (int i = 0; i < numPeople; ++i) {
int x = rand() % 201 - 100; // [-100, 100]
int y = rand() % 201 - 100;
bool infected = i < numInfected;
people[i] = Person(i + 1, x, y, infected);
}
for (int day = 1; day <= n; ++day) { // simulation movement for n days
for (int i = 0; i < numPeople; ++i) {
if (!people[i].infected) {
int dx = rand() % 3 - 1; // -1, 0, 1
int dy = rand() % 3 - 1;
people[i].x += dx;
people[i].y += dy;
}
}
for (int i = 0; i < numPeople; ++i) { // Tracking infections
if (people[i].infected) {
for (int j = 0; j < numPeople; ++j) {
if (!people[j].infected) {
double distance = sqrt(pow(people[i].x - people[j].x, 2) + pow(people[i].y - people[j].y, 2));
if (distance <= sqrt(2)) {
if (rand() % 100 < 90) {
people[j].infected = true;
}
}
}
}
}
}
display(people, numPeople);
}
int numInfectedAtEnd = 0; // Count infected people
for (int i = 0; i < numPeople; ++i) {
if (people[i].infected) {
numInfectedAtEnd++;
}
}
std::cout << "Number of infected people at the end: " << numInfectedAtEnd << std::endl;
return 0;
}