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

I need help writing a C++ program for class. Any help would be appreciated. Agai

ID: 3689887 • Letter: I

Question

I need help writing a C++ program for class. Any help would be appreciated. Again, this is in C++, NOT Java. Thanks! Here is the prompt:

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 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 (h) hurricanes 10%;

1) Implement a class named World; Class World inherited the Class CRandom; (2 points

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%; (2 points)

3) The methods created in the previous step (item 2), should use the inherited Class CRandom to obtain the expected random probability; (2 points)

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/armageddon, compared with its current population currently estimated as 7 Billion; (2 points)

5) In the Class World create a method named NewWorld that 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.” (2 points

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;
}
//========================================================================//
//========================================================================//