Created
September 26, 2013 02:52
-
-
Save jmcph4/6709264 to your computer and use it in GitHub Desktop.
A very simple program which shows the evolution of a village. Just use Excel, it's better.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cstdlib> | |
| #include <iostream> | |
| #include <string> | |
| using namespace std; | |
| #define POPULATION_DENSITY 10 | |
| #define GAME_LENGTH 10 | |
| class village | |
| { | |
| public: | |
| string name; // village name | |
| int population; // village population | |
| float size; // village size in sqkm | |
| int x; // village centre's x-coordinate | |
| int y; // village centre's y-coordinate | |
| int step; // turn number | |
| village() | |
| { | |
| this->name = "The Compound"; | |
| this->population = 10; | |
| this->size = this->population / POPULATION_DENSITY; | |
| this->x = 0; | |
| this->y = 0; | |
| this->step = 0; | |
| this->growth = 0.10; | |
| } | |
| int update(void) | |
| { | |
| this->updatePopulation(); | |
| this->updateSize(); | |
| this->addStep(); | |
| return this->step; | |
| } | |
| private: | |
| float growth; // village growth rate | |
| void updatePopulation(void) | |
| { | |
| this->population = this->population + (this->population * this->growth); | |
| } | |
| void updateSize(void) | |
| { | |
| this->size = this->population / POPULATION_DENSITY; | |
| } | |
| void addStep(void) | |
| { | |
| this->step = this->step++; | |
| } | |
| }; | |
| int main(void) | |
| { | |
| village VILLAGE; | |
| int i = 0; | |
| for(i = 0;i <= GAME_LENGTH;i++) | |
| { | |
| cout<<VILLAGE.name<<":"<<endl; | |
| cout<<"----------Year "<<VILLAGE.step<<"----------"<<endl; | |
| cout<<"Population: "<<VILLAGE.population<<endl; | |
| cout<<"Land Area: "<<VILLAGE.size<<"sqkm"<<endl<<endl; | |
| VILLAGE.update(); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment