Member Avatar for iamthwee

Iamthwee ok I see what you're saying. So in the client code then I would need nested for loops that call the get function for every cell and stores the contents before calling to the print function that prints through the 2d array?

Yes, you would read each line of your text file and pipe each value into the set method.

And remember this is just your class. What about implementing the actual rules for 'the game of life'. Getting that correct will take a little more thinking.

The question is can you make it before your deadline? :lol:

[edit]
Unfortunately for you it's my bedtime, so I have to go. Good luck!
[/edit]

Wow that is flat out amazing...Although I'm not sure I understand half of what you just did...impresseive

Why do you have 2 default constructors?

Wow that is flat out amazing...Although I'm not sure I understand half of what you just did...impresseive

It's not that odd, most of the code he gave you was simply combined from the other snippets handed to you. So it shouldn't be that confusing.

Why do you have 2 default constructors?

I don't know if I missed something, but I sure can't see 2 constructors. I only see 1 constructor and 1 destructor. Tell me if I'm wrong.

Well I se it as 2 default constructors. THat how he labeled them.

No I was just messing around. I understand most of it. I just thought it was impressive how quickly he put it all together, that's all.

Hey can you help me with getting the proper client code for reading in the file and the "print" function.

Well I se it as 2 default constructors. THat how he labeled them.

No he did not. The last time I checked, a ~ in front of a member function designated the destructor.

boolMatrix(); //default constructor
   ~boolMatrix();//default destructor

Hey can you help me with getting the proper client code for reading in the file and the "print" function.

Alright, show some code for those functions first. I'll give you some quick tips for print():

Use 2 nested loops. The first loops through the columns, the second loops through the rows.

Inside the second loop, you'll reference the array by doing something like data[x][y] where 'x' is the first loop's iterator variable, and 'y' is the second's. And of course you will print out this result, so place that previous reference after a cout stream.

For reading in the file, please give the function name and a "detailed description of what the function is supposed to do". I don't feel like reading the 5-page design document you posted previously just to find out what exactly the function is supposed to do. All I can say is that you'll most likely have to use ifstream and loops. ;)

Hey JoeProgrammer,

Thanks man. Yeah you're right. I misread. and we haven't covered destuctors yet.

Ok really quickly about the data file. It is basically a list of integers in pairs that give the coordinates row, column of all living cells for the first generation.

my logic (which often isn't all that logical) was to have a call to a client side function right after the default constructor:

int main()
{
     boolMatrix boolMatrix;
     loadfile();
 }

void loadfile()
{
     ifstream infile("location_alive.dat");
     int row, col

     while(infile){
                    infile >> row >> col;
                    booleanMatrix.set(row,col, "true");
    }
}

I'll post some more soon... on the print function.

ok here's my shot at the print...

void boolMatrix::print()
{
     for(int row = 0; row < 20; row++)
     {
         (for int col = 0; col < 20; col++)
          { 
               cout << booleanMatrix[row][col];
          }
     }

This will print the char ('*' or ' ') based on the get function?
This will print the entire grid for a specific generation?

Sorry if you were expecting me to reply sooner... I was just finishing off a blog post. :)

Thanks man. Yeah you're right. I misread. and we haven't covered destuctors yet.

They are even simpler than destructors. They don't take any parameters, there's never more than one, and they basically help to deallocate and do reverse anything that the constructor did before the program quits.

Ok really quickly about the data file. It is basically a list of integers in pairs that give the coordinates row, column of all living cells for the first generation.

Your code for loading the file seems fine, as far as I can tell... however, are you really sure that you want to code this as a C-style function? Wouldn't it make much for sense for it to be a member function of boolMatrix?

This will print the char ('*' or ' ') based on the get function?
This will print the entire grid for a specific generation?

Your code is fine. I'm sorry, I forgot that you needed to print *s! Then you'll need to do an if() statement to check for the bool value.

Hope this helps

Hi all, would somebody help me finish this thing up. I have til the end of today. Problem is that I have 3 3hour finals today. I mainly need two more of the member functions, finish the client code and get the file separated and get the program to compile. Oh yeah and I need to figure out how to count the neighbors. Wow this might be mission impossible. Well if somebody can help, I'd appreciate it.

#include <iostream>
using namespace std;

class boolMatrix
{
      //Initialize public member functions
public:
       boolMatrix(); //default constructor      
       char get (int, int, bool);
       void set (int, int, bool);
       int rowCount(int);
       int colCount(int);
       int totalCount();
       void print();
     //Initialize Private member functions  
private:
        bool booleanMatrix[20][20];
};
//Initialize all cells to false
boolMatrix::boolMatrix()
{
     for(int row = 0; row < 20; row++)
     {
             for(int col = 0; col < 20; col++)
             {
                     booleanMatrix[row][col] = false;
             }
     }
}
/*Get member function:
  Return the CURRENT contents of a single array element.
  Returns a char, either a '*' or a ' ' (space).
*/
char boolMatrix::get(int row, int col, bool var)
{
     if (booleanMatrix[row][col] ==true)
        return '*';         // returns a star indicating alive.
     else
        return ' ';         // returns a space indicating dead!
}
void boolMatrix::set( int row, int col, bool var )
{
     if (var == true)
     {
        booleanMatrix[row][col] = true;
     }
     else if (var == false)
     {
        booleanMatrix[row][col] = false;  
     }
} 
int boolMatrix::rowCount( int row)
{
    
    
}

int boolMatrix::colCount(int col)
{
    
    
}
 
int boolMatrix::totalCount()
{
    
    
}

void boolMatrix::print()
{
    for(int row = 0; row < 20 row++
    {
            for (int col = 0; col < 20; col++)
            {
                cout << booleanMatrix[row][col]
            } 
    }
}

int main()
{
    boolMatrix boolmatrix;
    boolMatrix.set(10,10,true);
    cout << boolmatrix.get(10,10);
    
    cin.get();         
                 
}
Member Avatar for iamthwee

I'm disappointed. I thought with a little help you might have attempted to code the other functions

You haven't. All you've done is changed a few things that I have already done. I'm sure you've missed your deadline. Let this be a lesson, don't leave your homework to the last minute.

If you came here earlier, and shown a little more effort you probably could have passed. Tee he he.

Nic, did you read my previous post?

I'm sorry, I forgot that you needed to print *s! Then you'll need to do an if() statement to check for the bool value.

If you want to print out spaces and *s like the instuctions say, you're going to need to put in an if statement similar to get() to check the bool value, and then print out either a * or space. And yeah, follow iamthwee's advice (even if he is only 3 ;)).

Member Avatar for iamthwee

Actually u wouldn't need an if statement since his get method uses one and that is what his teach probably expects him 2 use.

U could say i'm being pedantic. In any case he's missed his deadline. End of.

DOn't count me out buddy. I got the deadline extended.. tile tonight.. now be a good buddy and help me PLEASE!

Actually u wouldn't need an if statement since his get method uses one and that is what his teach probably expects him 2 use.

I still don't understand what get() has to do with this, as it's never being called in print(), and also I don't see how an array of bools can be printed out as stars and spaces in this line:

cout << booleanMatrix[row][col]

Correct me if I'm wrong. And I just noticed that Nicoli's missing a semicolon at the end of that line.

In any case, I think iamthwee is right, although you've got your deadline extended, it's too late. I'm certainly not going to write the thing for you, as my time is not unlimited, and unless you're actually doing some work yourself you're not going to get it done. If you really have serious problems with these sorts of things, you need to post sooner. Period.

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.