Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with a C++ program to simulate the end of the world. Here are the in

ID: 3668934 • Letter: I

Question

I need help with a C++ program to simulate the end of the world.

Here are the instructions:

Make a program to simulate the end of the world as we know, containing the following features:

The world population according to all sci-fi movies will preish up to a certain percentage, given global:(a) earthquakes 10%, (b) tsunamis 2%, (c) volcanoes, 10%, (d) freezing temperature from sudden ice age 10%, (e) crashing meteorites 10%, (f) widely spread fires 10%, (g) hunger 10%, (h) zombies 10%, and (i) hurricanes 10%.

1. Implement a class names World. Class World inherited the Class CRandom

2. In the Class World create methods named EarthQuakes; Tsunamis; Volcanoes; IceAge; Meteorites; Fires; Hunger; Zombies; and Hurricanes; Those methods are used to return/inform the death toll (in numbers and percentage) caused according to the respective event uniform probability. e.g. tsunamis rangeLow is 0 and rangeHigh is 20%.

3. The methods created in the previous step should use the inherited class CRandom to obtain the expected random probability.

4. In the Class World create a method named TotalSurvivors that informs in percentage what is the final earth's population that survived the apocalypse, compared with its current population currently estimated as 7 billion.

5. In the Class World create a method named NewWorld that will print the message: "Happy Ending! Total number of survivor is ..." if there are no survivors, then print the message: "No Happy Ending! There are not survivors"

Here is CRandom:

Explanation / Answer

//========================================================================//
//========================================================================//
#include <sys/time.h>
#include <bits/stdc++.h>
#include <time.h>
using namespace std;
//========================================================================//
//========================================================================//
class CRandom{
public:
CRandom(){} // constructor
~CRandom(){} // destructor
int getRandomPublic(int rangeLow, int rangeHigh){
int myRand_scaled;
myRand_scaled=getRandomPrivate(rangeLow, rangeHigh);
return myRand_scaled;
}
private:// uniform distribution between rangeLow and rangeHigh
int getRandomPrivate(int rangeLow, int rangeHigh) {
double myRand = rand()/(1.0 + RAND_MAX);
int range = rangeHigh - rangeLow + 1;
int myRand_scaled = (myRand * range) + rangeLow;
return myRand_scaled;
}
protected:// uniform distribution between rangeLow and rangeHigh
int getRandomProtected(int rangeLow, int rangeHigh) {
double myRand = rand()/(1.0 + RAND_MAX);
int range = rangeHigh - rangeLow + 1;
int myRand_scaled = (myRand * range) + rangeLow;
return myRand_scaled;
}
};
//========================================================================//
//========================================================================//
class World: public CRandom {
public:
// constructor to initialize random functions
World() {
struct timeval time;
gettimeofday(&time, NULL);
srand((unsigned int) time.tv_usec);
}

long long TotalSurvivors() {

// population killed by tsunami
long long earthQuakeKills = EarthQuakes();
long long tsunamiKills = Tsunamis();
long long volcanoKills = Volcanoes();
long long iceAgeKills = IceAge();
long long meteoritesKills = Meteorites();
long long fireKills = Fires();
long long hungerKills = Hunger();
long long zombiesKills = Zombies();
long long hurricaneKills = Hurricanes();

long long totalSurvivors = CURRENT_POPULATION
- (earthQuakeKills
+ tsunamiKills
+ volcanoKills
+ iceAgeKills
+ meteoritesKills
+ fireKills
+ hungerKills
+ zombiesKills
+ hurricaneKills);

return max(0LL, totalSurvivors);
}

void NewWorld() {
long long totalSurvivors = TotalSurvivors();
if (totalSurvivors > 0) {
cout << "Happy Ending! Total number of survivor is " << totalSurvivors << endl;
} else {
cout << "No Happy Ending! There are not survivors" << endl;
}
}
private:
long long CURRENT_POPULATION = 7 * 1LL * 1000000000;

// sum of all adds up to 100 that's why for Tsunami it is taken as 20

long long EarthQuakes() {
int randomKillingPercentage = getRandomProtected(0, 10);
return (CURRENT_POPULATION * randomKillingPercentage) / 100;
}

long long Tsunamis() {
int randomKillingPercentage = getRandomProtected(0, 20);
return (CURRENT_POPULATION * randomKillingPercentage) / 100;
}

long long Volcanoes() {
int randomKillingPercentage = getRandomProtected(0, 10);
return (CURRENT_POPULATION * randomKillingPercentage) / 100;
}

long long IceAge() {
int randomKillingPercentage = getRandomProtected(0, 10);
return (CURRENT_POPULATION * randomKillingPercentage) / 100;
}

long long Meteorites() {
int randomKillingPercentage = getRandomProtected(0, 10);
return (CURRENT_POPULATION * randomKillingPercentage) / 100;
}

long long Fires() {
int randomKillingPercentage = getRandomProtected(0, 10);
return (CURRENT_POPULATION * randomKillingPercentage) / 100;
}

long long Hunger() {
int randomKillingPercentage = getRandomProtected(0, 10);
return (CURRENT_POPULATION * randomKillingPercentage) / 100;
}

long long Zombies() {
int randomKillingPercentage = getRandomProtected(0, 10);
return (CURRENT_POPULATION * randomKillingPercentage) / 100;
}

long long Hurricanes() {
int randomKillingPercentage = getRandomProtected(0, 10);
return (CURRENT_POPULATION * randomKillingPercentage) / 100;
}
};

int main(void){
World world;
world.NewWorld();
return EXIT_SUCCESS;
}
//========================================================================//
//========================================================================//

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote