Okay I need help getting started.

Here is the assignment:

Conway's Game of Life

For this assignment your are to write a program, that plays Conway's game of Life. See the Wikipedia definition, if
you have never played the game: http://en.wikipedia.org/wiki/Conway's_Game_of_Life.

Here is how our implementation will work:
(1) The program will ask the user to enter a filename from the console. (Just like the last assignment).
(2) The initial configuration will be read in from a file, which will be a 12 by 30 two-dimensional array of characters. The game board will be surrounded by all O's.
(3) The game will be played on 10 by 28 two-dimensional array. (Can you guess why?). A period ('.') will represent a dead cell and an 'X' will represent a live cell.

You will be severely penalized if your program does not have at least three functions.

Here is my current code:

//Game Of Life Assignment
//Dylan Metz
#include <iostream>
#include <string>
#include <fstream>
#include <cstring>

using namespace std;

int main()
{
	
const int ROWS=12;
const int COLS=30;
char file[ROWS][COLS];

ifstream myfile;
string filename;
cout<<"Enter the filename: \n";
cin>>filename;
myfile.open (filename.c_str());
myfile>>file;
cout<<file;






return 0;
}

I am getting compiler errors

Haven't really looked at this much (Tired!)

//Game Of Life Assignment
//Dylan Metz
#include <iostream>
#include <string>
#include <fstream>
#include <cstring>

using namespace std;

int main()
{
	
const int ROWS=12;
const int COLS=30;
char file[ROWS][COLS];

string filename;

cout << "Please enter a filename:";
cin >> filename;

cout << "File: " << filename << endl;
ifstream myfile(filename.c_str());

if(myfile.is_open())
{
	while(myfile.is_open())
	{
		// do something with file
		// do something with file
	}
	
}else{
	
	cout << "Could not open the file";
}
return 0;
}

Also, when assigning a multidimensional array (2d) just assign it as a massive 1D array (that's what it technically is)

Hope this helps anyway :)

I am getting compiler errors

Really? That's too bad. Could you turn your screen a little left so I can see what the errors are?

"myfile>>file;" <- your coding

but I don't see "file" anywhere else? what is "file"?

As Walt says, show us your errors, Copy Paste = your friend

You may want to overload >> operator to write to a two dimentional array.
There is no default implementation

Okay. Here is what I currently got so-far:

//Game of Life
//Dylan Metz
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

//functions
string GetName();

int main()
{
string g; //stops terminal window from quiting
string name = GetName();
cout<<name;
cin>>g;
return 0;
}

string GetName ()
{
	string filename;
	cout<<"Enter the filename: \n";
	cin>>filename;
	return filename;
}

Their is no errors.

BUT how do I do it like what the assignment says???

I know I am required to use 2D arrays and 3+ functions.

Conway's Game of Life

For this assignment your are to write a program, that plays Conway's game of Life. See the Wikipedia definition, if
you have never played the game: http://en.wikipedia.org/wiki/Conway's_Game_of_Life.

Here is how our implementation will work:
(1) The program will ask the user to enter a filename from the console. (Just like the last assignment).
(2) The initial configuration will be read in from a file, which will be a 12 by 30 two-dimensional array of characters. The game board will be surrounded by all O's.
(3) The game will be played on 10 by 28 two-dimensional array. (Can you guess why?). A period ('.') will represent a dead cell and an 'X' will represent a live cell.

You will be severely penalized if your program does not have at least three functions.

I've attached part of the solution output from hypergrade.

Okay. Here is what I currently got so-far:

...snipped...

Their is no errors.

With the code posted, there (note the spelling) is nothing for us to help with -- code-wise.

BUT how do I do it like what the assignment says???

1) By thinking about the problem, coming up with questions that need to be answered, answering the questions,
2) understanding the project
3) designing a solution based on your understanding,
4) programming based on the solution,
5) killing any bugs because you missed something in the design.

I know I am required to use 2D arrays and 3+ functions.

How many arrays do you think you need?
What would you use them for?
This is part of the design...

What does the program as a whole need to do -- from start to finish?
What steps can be logically done by functions?
Another part of the design.

Conway's Game of Life

For this assignment your are to write a program, that plays Conway's game of Life. See the Wikipedia definition, if
you have never played the game: http://en.wikipedia.org/wiki/Conway's_Game_of_Life.

Here is how our implementation will work:
(1) The program will ask the user to enter a filename from the console. (Just like the last assignment).
(2) The initial configuration will be read in from a file, which will be a 12 by 30 two-dimensional array of characters. The game board will be surrounded by all O's.
(3) The game will be played on 10 by 28 two-dimensional array. (Can you guess why?). A period ('.') will represent a dead cell and an 'X' will represent a live cell.

You will be severely penalized if your program does not have at least three functions.

Part of the design (a small part) is listed here.
What tasks can be made into functions based on the above description?

Here is my current code:

//Game of Life
//Dylan Metz
 
#include <iostream>
#include <string>
#include <fstream>
#include <cstring>
 
using namespace std;
 
//function(s)
void GetFile(); //Get filename
char MakeArray(); //Make 2d array
char ChgArray(); //change the array
char GameBoard(); //Game Board
//Global Variables
const int ROW1 =12;
const int COL1 =30;
ifstream myfile;
string filename;
char live = 'x';
char dead = '.';
char name [ROW1][COL1];
//end of Global variables
int main()
{
int q; //stops terminal window from quitting
//call functions
GetFile();
MakeArray();
ChgArray();
 
//Stop Program from quitting
cin >> q;
 
return 0;
}
 
//Other Functions
void GetFile()
{
cout<<"Enter the filename: \n";
cin>>filename;
return;
}
 
char MakeArray()
{
myfile.open (filename.c_str());
for (int r=0; r<12; r++)
{
for (int c=0; c<30; c++)
{
myfile>>name[r][c];
//cout << name[r][c];
}
//cout << endl;
}
}
char ChgArray()
{
char name2 [12][30];
for (int r=0; r<12; r++)
{
for (int c=0; c<30; c++)
{
name2[r][c]=name[r][c];
//cout<<name2[r][c];
}
//cout<<endl;
}
 
}

I really need help finishing this assignment. I am really confused.

I really need help finishing this assignment. I am really confused.

With what? Just posting your completely unformatted code and telling us you're confused gives us nothing to help you with.

My current codes asks the user to input a file name and stores it into a 12by30 2d array. I need help comparing the characters of the array and use the rules of the game of life to complete the assignment. This is where I'm stuck and I really need help.

single
that is a single vairable called single

1dArray[x]
is a single element of 1dArray at index x, of whatever type is used to declare 1dArray

2dArray[r][c]
is a single element of 2dArray having indexes r and c (convenient shorthand for row and column). 2dArray can be declared using any valid type

If single, 1dArray and 2dArray were all declared with type char, then you could directly compare individual elements of any of them using the equality operator, or any other valid operator available to the char class. For example is is valid to do this:

if(single == 2dArray[r][c])

or this:

if(2dArray[r][c] == '.')

etc.

The rules of the game of life vary by who is implementing the strategy. All of the strategies involve looking at the "surrounding environment". Sometimes the surrounding environment is the cell above, below, to the right and to the left, and sometimes the surrounding element is any cell in the arrya that touches the current cell (the full face cells top/bottom/right/left and the 4 corners). There is a mathematical relationship between the current cell and the one above it: if the current cell has indexes r and c then the one immediately above it has indexes r - 1 and c. The one to left of current cell is r and c + 1.

I'll leave it to you figure out the indexes for the cell below, the cell to the left and the cells at the cornes of the current cell.

Once you can access the cells in the surrounding environment you need to access where the cells in the surrounding environment are valid and if so how to use the information contained within the valid surrounding cells in the current generation are used to determine the status of the current cell in the new generation.

You will want to determine if the new generation numbers come about as a static interaction from the prior generation or whether the new generation is influenced by the new members of the new generation as well as the unchanged old members of the currrent generation. One version needs two arrays, and the other only needs one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.