The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
The game of Life is intended to model life in a society of organisms. Consider a rectangular array of cells, each of which may contain an organism. If the array is considered to extend indefinitely in both directions, then each cell has eight neighbors, the eight cells surrounding it. Births and deaths occur according to the following rules:
An organism is born in any empty cell having exactly three neighbors.
An organism dies from isolation if it has fewer than two neighbors.
An organism dies from overcrowding if it has more than three neighbors.
All other organisms survive to the next generation.
Â
Write a program to play the game of Life and investigate the patterns produced by various initial configurations. Some configurations die off rather rapidly; others repeat after a certain number of generations; others change shape and size and may move across the array.
Â
Â
NOTE:
For representing each organism, use "@" characters.
For an array of cells, use 30x30 two-dimensional array.
Each generation should be displayed on the screen and should be paused.
(You can use cin.get( ) library function to pause running your program.)
Â
Â
Â
Â
Input
Â
A set of initial cells will be given using the interactive way using a keyboard.
Â
The followings are the prompt for the input:
Â
Please Enter the number of initial cells: 4
The position of cell is 10 10
The position of cell is 10 11
The position of cell is 10 12
The position of cell is 11 11
Â
How many generations do you want to display? 3
Â
Output
The program then display each generation of organisms at a time.
Â
The 1-generation
                           @@@
                               @
Â
Press any key to continue!!
Â
(This picture should be displayed on the new screen.)
Â
The 2-generation
                          @
                           @@@
                           @@@
Â
Press any key to continue!!
Â
The 3-generation
                          @@@
                          Â
                           @   @
                               @
Â
Do you want to do it again?(Yes/No)Â Â Â N
Â
please find attachment for more details, thank you!
Â
Â
Â
Program 1: Life•The game ofLife•‘@’ represents each organism.•30 x 30 two-dimensional array•Each generation should be displayed on the screen, and should be paused.•You may use cin.get() to pause, cin.ignore() to ignore ‘\n’.4\ncin buffer- When a user inputs 4 and hit the enter, they get into the cin buffer.-‘cin>> input’ will read data from buffer until the delimiting character ‘\n’ is encountered.- cin.get() will read one character from buffer, which is ‘\n’.\ncin >> inputWhy do we need cin.ignore()?cin.ignore()
The game ofLifeis intended to model life in a society of organisms.Consider arectangular array of cells, each of which may contain an organism.If the array isconsidered to extend indefinitely in both directions, then each cell has eight neighbors,the eight cells surrounding it.Births and deaths occur according to the followingrules:1.An organism is born in any empty cell having exactly three neighbors.2.An organism dies from isolation if it has fewer than two neighbors.3.An organism dies from overcrowding if it has more than three neighbors.4.All other organisms survive to the next generation.Write a program to play the game ofLifeand investigate the patterns produced byvarious initial configurations.Some configurations die off rather rapidly; othersrepeat after a certain number of generations; others change shape and size and maymove across the array.NOTE:1.For representing each organism, use "@" characters.2.For an array of cells, use 30x30 two-dimensional array.3.Each generation should be displayed on the screen and should be paused.(You can use cin.get( ) library function to pause running your program.)4.The source file should be calledlife.cppInputA set of initial cells will be given using the interactive way using a keyboard.The followings are the prompt for the input:Please Enter the number of initial cells: 4The position of cell is 10 10The position of cell is 10 11The position of cell is 10 12The position of cell is 11 11
Attachments: