In: Computer Science
Make a program to simulate the end of the world as we know, containing the following features: NEEDED IN C++.
The world population according to all sci-fi movies will perish up to a certain percentage, given global: (a) earthquakes 10%, (b) tsunamis 20%, (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 classnamed World; Class Worldinherited the Class CRandom;
2) In the Class Worldcreate 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 (item 2), should use the inherited Class CRandomto obtain the expected random probability;
4) In the Class World create a method named TotalSurvivorsthat informs in percentage what is the final earth's population that survived the Apocalypse/armageddon, compared with its current population currently estimated as 7 Billion;
5) In the Class World create a method named NewWorldthat will print the message: “Happy Ending! Total number of Survivors is: .... ”, if there is no survivors, then print the message: “No Happy Ending! There are no survivors.”
#include <sys/time.h>
#include <bits/stdc++.h>
#include <time.h>
using namespace std;
class CRandom{
public:
CRandom(){}
~CRandom(){}
int getRandomPublic(int rangeLow, int rangeHigh){
int myRand_scaled;
myRand_scaled=getRandomPrivate(rangeLow, rangeHigh);
return myRand_scaled;
}
private:
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:
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:
World() {
struct timeval time;
gettimeofday(&time, NULL);
srand((unsigned int) time.tv_usec);
}
long long TotalSurvivors() {
// populations 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;
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;
}