Question

In: Computer Science

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

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.”

Solutions

Expert Solution

#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;
}

Related Solutions

In Java, Write a Java program to simulate an ecosystem containing two types of creatures, bears...
In Java, Write a Java program to simulate an ecosystem containing two types of creatures, bears and fish. The ecosystem consists of a river, which is modeled as a relatively large array. Each cell of the array should contain an Animal object, which can be a Bear object, a Fish object, or null. In each time step, based on a random process, each animal either attempts to move into an adjacent array cell or stay where it is. If two...
****JAVA Program**** Make a LandTract class with the following fields: • length - an int containing...
****JAVA Program**** Make a LandTract class with the following fields: • length - an int containing the tract's length • width - an int containing the tract's width The class should also have the following methods : • area - returns an int representing the tract's area • equals - takes another LandTract object as a parameter and returns a boolean saying whether or not the two tracts have the same dimensions (This applies regardless of whether the dimensions match...
We know that as humans we are going to make mistakes. There is simply no way...
We know that as humans we are going to make mistakes. There is simply no way around that fact. Should we be nervous about making errors? As auditors, what should we think when we see an error? In other words, when we see an error, do we always think fraud? Is there a way to tell the difference? Is an auditor responsible for finding errors?
Java 176 Lottery Program in Word. Using ArrayLists to Simulate a Lottery Program Simulate a Lottery...
Java 176 Lottery Program in Word. Using ArrayLists to Simulate a Lottery Program Simulate a Lottery Drawing by choosing 7 numbers at random from a pool containing 30 numbers Each time a number is selected, it is recorded and removed from the pool The pool values are 00 to 29 inclusive Your program must output each selected number from the drawing using a two-digit format. For Example, the number 2 would be represented by 02 on the “Picked” line. The...
I need to create a program that will simulate an ATM. The program has to be...
I need to create a program that will simulate an ATM. The program has to be written in JAVA that uses JOptionaPane to pop up the messages. It will need to simulate to get ** balance **withdraw **Deposit **exit the atm ** need to have a method that shows a receipt of everything that was done during the transaction
In C, write a program that will simulate the operations of the following Round-Robin Interactive scheduling...
In C, write a program that will simulate the operations of the following Round-Robin Interactive scheduling algorithm. It should implement threads for the algorithm plus the main thread using a linked list to represent the list of jobs available to run. Each node will represent a Job with the following information: int ProcessID int time time needed to finish executing The thread representing the scheduler algorithm should continue running until all jobs end. This is simulated using the time variable...
Write a MATLAB program to simulate the Stuck in the Mud game, The following link contains...
Write a MATLAB program to simulate the Stuck in the Mud game, The following link contains the detail game description: https://www.activityvillage.co.uk/stuck-in-the-mud , with additional features that can: • Use five (5) 6-sided dice to automatically play the Stuck in the Mud game against a player. • Greet the player when the game starts. • Let the player to choose the number of rounds to play. Take care of the user input to ensure the program will not crash with inputs...
Java: Using ArrayLists to Simulate a Lottery Program Simulate a Lottery Drawing by choosing 7 numbers...
Java: Using ArrayLists to Simulate a Lottery Program Simulate a Lottery Drawing by choosing 7 numbers at random from a pool containing 30 numbers Each time a number is selected, it is recorded and removed from the pool The pool values are 00 to 29 inclusive Your program must output each selected number from the drawing using a two-digit format. For Example, the number 2 would be represented by 02 on the “Picked” line.    The numbers drawn cannot repeat Sort...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7...
Give an example of a real-world situation where we might need to know the mean AND...
Give an example of a real-world situation where we might need to know the mean AND standard deviation of a distribution. In other words, under what circumstances might we be concerned with... 1) the center of the distribution AND 2) the spread of the distribution (i.e., how far away data points are from the mean) HINT: When might looking exclusively at the mean be misleading or uninformative?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT