Question

In: Computer Science

In C++ language implement an end of the world simulation. Create 3 global variables earthquake =...

In C++ language implement an end of the world simulation. Create 3 global variables earthquake = 30%, hurricane = 35%, volcano = 35%

Implement a class named World. Class World inherited Class CRandom

In class World create three methods Earthquakes, Hurricanes and Volcanoes. These methods return death toll in numbers and percentage up to their global percentage. This percentage is calculated using CRandom.

Solutions

Expert Solution

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

}


Related Solutions

C language Write a program in C to implement Queue and its operation (like create, insert,...
C language Write a program in C to implement Queue and its operation (like create, insert, delete, search) using array data structure.
Using C++ language, create a program that uses a struct with array variables that will loop...
Using C++ language, create a program that uses a struct with array variables that will loop at least 3 times and get the below information: First Name Last Name Job Title Employee Number Hours Worked Hourly Wage Number of Deductions Claimed Then, determine if the person is entitled to overtime and gross pay. Afterwards, determine the tax and net pay. Output everything to the screen. Use functions wherever possible. Bonus Points: Use an input file to read in an unknown...
Language C++ Implement a Priority Queue with a Binary HEAP. Use a Max Heap. Create a...
Language C++ Implement a Priority Queue with a Binary HEAP. Use a Max Heap. Create a class called Node: Have a Name and Priority.Data set - 10 is the highest priority, 1 is lowest priority. Enqueue and dequeue in the following order. Function  Name, Priority Enqueue  Joe, 3 Enqueue  Fred,1 Enqueue Tuyet,9 Enqueue  Jose, 6 Dequeue Enqueue  Jing, 2 Enqueue  Xi, 5 Enqueue  Moe, 3 DequeueEnqueue  Miko, 7 Enqueue Vlady, 8 Enqueue Frank, 9 Enqueue  Anny, 3 DequeueEnqueue  Xi, 2 Enqueue  Wali, 2 Enqueue  xChe, 6 Enqueue  xVerra, 8 Dequeue Dequeue Dequeue Dequeue...
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a...
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a CPU scheduler. The number of CPU’s and the list of processes and their info will be read from a text file. The output, of your simulator will display the execution of the processes on the different available CPU’s. The simulator should also display: -   The given info of each process -   CPU utilization - The average wait time - Turnaround time for each process...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables:...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables: StudentName (string), SchoolYear (int), YearsUntilGraduation(int) * Method YTK() = 12 - SchoolYear; 2. Main *Enter name *Enter age *You will attend school:____ years before graduating.
Code in C Instructions For this programming assignment you are going to implement a simulation of...
Code in C Instructions For this programming assignment you are going to implement a simulation of Dijkstra’s solution to the Dining Philosophers problem using threads, locks, and condition variables. Dijkstra’s Solution Edsgar Dijkstra’s original solution to the Dining Philosophers problem used semaphores, but it can be adapted to use similar mechanisms: • Each philosopher is in one of three states: THINKING, HUNGRY, or EATING. • Every philosopher starts out in the THINKING state. • When a philosopher is ready to...
C++ Language Implement a two-dimensional image using a nested loop. 1) Create an integer constant DIM...
C++ Language Implement a two-dimensional image using a nested loop. 1) Create an integer constant DIM and set it equal to 5. 2) Use a nested loop to print the output in terms of DIM. Example output: ***** *---* *---* *---* *****
Assignment Implement Conway’s Game of Life IN C The Game of Life is a simple simulation...
Assignment Implement Conway’s Game of Life IN C The Game of Life is a simple simulation that takes place in a grid of cells. Each cell can be either alive or dead, and it interacts with its neighbors (horizontally, vertically, or diagonally). In each iteration, a decision will be made to see if living cells stay alive, or if dead cells become alive. The algorithm is as follows: If a cell is alive: If it has less than two living...
Problems create a C++ program that will do the followings - define 3 double variables x,...
Problems create a C++ program that will do the followings - define 3 double variables x, y, z - calculate the value of y as the following formula: y = 2*x*x+4*x+5 and print x and y; - assign a new value to x: x=5.6 - calculate the value of z as the following formula z = (y*y)/4 + (x*x)/5 - print x, y,x
Create global variables Mean, Mode, Median, then create a method that takes an array of 10...
Create global variables Mean, Mode, Median, then create a method that takes an array of 10 double numbers and return three answers of the Mean, Median, Mode ( no need for implementation of the mean, median and mode, calculate them manually and return the answers), assign the answers to the global variables. In java, please!!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT