Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,208 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,279 people online right now. Registration is fast and FREE... Join Now!




help in c++ program

 
Reply to this topicStart new topic

help in c++ program, Write a program to implement the game called Life created by J. H. Con

sid2008
20 May, 2008 - 02:05 PM
Post #1

New D.I.C Head
*

Joined: 1 Apr, 2008
Posts: 12

HI everyone..
I am new on this site. But this forums hepled me a lot in my previous course
Does anyone know about this lifegame? I dont know about it.Actually i have started to study the C++ but this is also new for me.
Write a program to implement the game called Life, created by the British mathematician J. H. Conway in 1970. Life is really a simulation, not a game with players. It takes place on a rectangular grid in which each cell can either be occupied by an organism or not. Occupied cells are called
alive; unoccupied cells are called dead. Which cells are alive changes from generation to generation according to the number of neighboring cells that are alive


1. The neighbors of a given cell are the eight cells that touch it vertically, horizontally, or diagonally.
2. If a cell is alive but either has no neighboring cells alive or only one alive, then in the next generation the cell dies of loneliness.
3. If a cell is alive and has four or more neighboring cells also alive, then in the next generation the cell dies of overcrowding.
4. A living cell with either two or three living neighbors remains alive in the next generation.
5. If a cell is dead, then in the next generation it will become alive if it has exactly three neighboring cells no more or fewer that are already alive. All other dead cells remain dead in the next generation.
6. All births and deaths take place at exactly the same time, so that dying cells can help to give birth to another, but cannot prevent the death of others by reducing overcrowding, nor can cells being born either preserve or kill cells living in the previous generation.




if anyone has any information regarding this program plz let me know

User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Help In C++ Program
20 May, 2008 - 02:08 PM
Post #2

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,556



Thanked: 99 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
QUOTE
I am new on this site. But this forums hepled me a lot in my previous course
How come you've only got one post then? unsure.gif

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
User is online!Profile CardPM
+Quote Post

Cerolobo
RE: Help In C++ Program
20 May, 2008 - 02:08 PM
Post #3

D.I.C Regular
Group Icon

Joined: 5 Apr, 2008
Posts: 440



Thanked: 31 times
My Contributions
The article on wikipedia is actually quite useful.

http://en.wikipedia.org/wiki/Conway's_Game_of_Life
User is offlineProfile CardPM
+Quote Post

sid2008
RE: Help In C++ Program
21 May, 2008 - 08:16 AM
Post #4

New D.I.C Head
*

Joined: 1 Apr, 2008
Posts: 12

QUOTE(gabehabe @ 20 May, 2008 - 03:08 PM) *

QUOTE
I am new on this site. But this forums hepled me a lot in my previous course
How come you've only got one post then? unsure.gif

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.

hi..thanks for ur reply..i dont know that i have to attach code with my previous message....i have done some work on this code..what i did ,i have made 3 free functions...but could not able to print the generation's result in outputfile...plz take a look to my code and try to help me...

QUOTE(sid2008 @ 21 May, 2008 - 09:15 AM) *

QUOTE(gabehabe @ 20 May, 2008 - 03:08 PM) *

QUOTE
I am new on this site. But this forums hepled me a lot in my previous course
How come you've only got one post then? unsure.gif

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.

hi..thanks for ur reply..i dont know that i have to attach code with my previous message....i have done some work on this code..what i did ,i have made 3 free functions...but could not able to print the generation's result in outputfile...plz take a look to my code and try to help me...

here is the code...


#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
using namespace std;


const int ARRAY=10;



void load_init(char [ARRAY] [ARRAY]);

void print_grid (char [ARRAY] [ARRAY]);

void copy_array(char [ARRAY] [ARRAY], char [ARRAY][ARRAY]);

int main()
{



char life[ARRAY] [ARRAY];
int i;
unsigned int seed;
int num_of_gen;

ofstream outfile;
outfile.open("conway.txt");




cout<<"Please enter a number to initiate the grid(positive integers): ";
cin>>seed;
cout<<"Please enter the number of generations you would like to see.\n";
cout<<"(use more than 10 to make it interesting): ";
cin>>num_of_gen;
srand(seed);

load_init(life);

for(i=1; i<= num_of_gen; i++)
{

outfile<<"\nGeneration: "<< i <<"\n\n";
print_grid(life);

}
outfile.close();
return 0;
}


void load_init(char INITIAL[ARRAY] [ARRAY])
{

int y,x,z;

for(y=0; y<ARRAY;y++)
{
for(x=0;x<ARRAY;x++)
{
z=(int) (10.0*rand()/RAND_MAX+1.0);
if(z < 5)
INITIAL[y] [x]=' ';
else
INITIAL[y] [x]='*';

}
}
}




void print_grid(char INITIAL[ARRAY] [ARRAY])
{

int y,x;

ofstream outfile;
outfile.open("conway.txt");



outfile<<" ";
for(x=0;x<ARRAY;x++)




for(y=0; y<ARRAY;y++)
{

for(x=0;x<ARRAY;x++)
{

outfile<<INITIAL[y][x];
}

outfile<<"\n";
}
//outfile.close();
}



void copy_array(char INITIAL[ARRAY][ARRAY], char COPY[ARRAY][ARRAY])
{
int y,x;

for(y=0;y<ARRAY;y++)
for(x=0;x<ARRAY;x++)
COPY[y][x]=INITIAL[y][x];
}


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 01:05PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month