I'm currently taking an intro to C++ class and I have an assignment to write a "game of life" program using a 2d array, but the catch is that the array has to be inside of a class titled boolMatrix. I've written the class constructor and print member functions for boolMatrix (both of which work) and now I am trying to write a set member function and I can't get it to work. I've been fiddling with it for quite some time now, and at this point I'm really guessing. Here is my code with what seems like the most logical way to write the set function. Can someone point me in the right direction with an explanation of your thought process.
I'm sure this is very basic, but this is brand new to me and very confusing. Thanks in advance.
Ted
main.cpp file:
include <iostream>
include <fstream>
include "boolmatrix.h"
using namespace std;
/*
*/
const int NUMBER_COLUMNS = 20;
const int NUMBER_ROWS = 20;
... as it happens, you should not feel bad, I happen to think that your code was pretty good.
You have to realise that you can imagine any tone of voice when reading written text. The tone I applied in my head was one of helpful advice of the kind "in future it would be helpful if you could...", whereas you seem to have imagined "Ha ha, look at what the idiot has done!...!", which was not my intent at all!
Be assured that if I thought you were an idiot, I would have just said that.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You wrote a lot (of unnecessary waffle), but did not actually explain what your problem was other tha, "it don't work". In what way does it not work, and what exactly is it supposed to do.
Since you appear to have expended some effort, how about you explain your though process, then someone might point you in the right direction.
I am sorry if that sounds harsh, but asking a smart precise question will get you the best answer. Also we have to be careful not to be duped into doing your homework.
However at a guess I would imagine that what you actually need is simply:
void boolMatrix::set(int row, int column, bool value)
{
array[row][column] = value ;
}
otherwise when value is false, the array would not be changed. That is not about coding, that is merely about clear thought.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for what I assume is an attempt to make me feel bad.
I actually found the error, I forgot to pass by reference in the client program, a minor oversight that is easy to miss. I was hoping to get a pair of fresh eyes on my code. Yes I understand that your version of code is more efficient. I'm new at this and am still figuring it all out.
I find your response shocking and nothing more than an attempt to be hurtful. Shame on you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
> Yes I understand that your version of code is more efficient.
No, my version works! Yours was just incorrect. You had no way to set to false.
My point was simply, get to the point, ask the question, we don't need to wade through the preamble to find that you forgot to ask a question and have to guess at what you intended to ask. That way you get an answer and we don't waste any time, everyone's happy.
Its a public forum, toughen up; there are far ruder and less helpful denizens of cyberspace out there than me!
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello all,
I'm currently taking an intro to C++ class and I have an assignment to write a "game of life" program using a 2d array, but the catch is that the array has to be inside of a class titled boolMatrix. I've written the class constructor and print member functions for boolMatrix (both of which work) and now I am trying to write a set member function and I can't get it to work. I've been fiddling with it for quite some time now, and at this point I'm really guessing. Here is my code with what seems like the most logical way to write the set function. Can someone point me in the right direction with an explanation of your thought process.
I'm sure this is very basic, but this is brand new to me and very confusing. Thanks in advance.
Ted
main.cpp file:
include <iostream>
include <fstream>
include "boolmatrix.h"
using namespace std;
/*
*/
const int NUMBER_COLUMNS = 20;
const int NUMBER_ROWS = 20;
void setZeroGeneration (boolMatrix currentGeneration);
//void calculateGenerations(const int gensToCalc,
// char currentGeneration[NUMBER_ROWS][NUMBER_COLUMNS],
// char nextGeneration[NUMBER_ROWS][NUMBER_COLUMNS]);
int main()
{
boolMatrix currentGeneration;
boolMatrix nextGeneration;
int gensToCalc;
// calculateGenerations(const gensToCalc, currentGeneration, nextGeneration);
}
void setZeroGeneration (boolMatrix currentGeneration)
{
ifstream infile("data.in");
int row;
int column;
}
/void calculateGenerations(const int gensToCalc,
char currentGeneration[NUMBER_ROWS][NUMBER_COLUMNS],
char nextGeneration[NUMBER_ROWS][NUMBER_COLUMNS])
{
for (int count = 0; count < gensToCalc; count++){
//stuff goes here
}
}/
boolMatrix.h file:
ifndef BOOLMATRIX_H
define BOOLMATRIX_H
/*
*/
class boolMatrix
{
public:
};
endif // BOOLMATRIX_H
boolmatrix.cpp file:
include <iostream>
include "boolmatrix.h" // class's header file
using namespace std;
const int NUMBER_COLUMNS = 20;
const int NUMBER_ROWS = 20;
// class constructor
boolMatrix::boolMatrix()
{
for (int currentRow = 0; currentRow < NUMBER_ROWS; currentRow++)
{
for (int currentCol = 0; currentCol < NUMBER_COLUMNS; currentCol++)
{
array[currentRow][currentCol] = false;
}
}
}
//print
void boolMatrix::print() const
{
char printMatrix[NUMBER_ROWS][NUMBER_COLUMNS];
}
//set
void boolMatrix::set(int row, int column, bool value)
{
if (value == true){
array[row][column] = true;
}
}
... as it happens, you should not feel bad, I happen to think that your code was pretty good.
You have to realise that you can imagine any tone of voice when reading written text. The tone I applied in my head was one of helpful advice of the kind "in future it would be helpful if you could...", whereas you seem to have imagined "Ha ha, look at what the idiot has done!...!", which was not my intent at all!
Be assured that if I thought you were an idiot, I would have just said that.
Clifford
You wrote a lot (of unnecessary waffle), but did not actually explain what your problem was other tha, "it don't work". In what way does it not work, and what exactly is it supposed to do.
Since you appear to have expended some effort, how about you explain your though process, then someone might point you in the right direction.
I am sorry if that sounds harsh, but asking a smart precise question will get you the best answer. Also we have to be careful not to be duped into doing your homework.
However at a guess I would imagine that what you actually need is simply:
void boolMatrix::set(int row, int column, bool value)
{
array[row][column] = value ;
}
otherwise when value is false, the array would not be changed. That is not about coding, that is merely about clear thought.
Clifford
Clifford,
Thanks for what I assume is an attempt to make me feel bad.
I actually found the error, I forgot to pass by reference in the client program, a minor oversight that is easy to miss. I was hoping to get a pair of fresh eyes on my code. Yes I understand that your version of code is more efficient. I'm new at this and am still figuring it all out.
I find your response shocking and nothing more than an attempt to be hurtful. Shame on you.
> Yes I understand that your version of code is more efficient.
No, my version works! Yours was just incorrect. You had no way to set to false.
My point was simply, get to the point, ask the question, we don't need to wade through the preamble to find that you forgot to ask a question and have to guess at what you intended to ask. That way you get an answer and we don't waste any time, everyone's happy.
Its a public forum, toughen up; there are far ruder and less helpful denizens of cyberspace out there than me!
Clifford