954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Looking for help with C++ game of life program. Will pay or make donation for tutor.

Hi all,

I looking for somebody to help me through a final class program. I would be happy to pay somebody to tutor me through this or make a donation. I am not looking for somebody to just give me the answer, but I DEFINITELY need help. It is due on Monday. Only two people in the entire class have had any success with it. I'm pretty lost. If someone can help me, please let me know. I have all the info pertaining to the assignment. Thanks alot.

nicolivolkov
Newbie Poster
18 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

What's the problem then?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

THe actual assignment is 3 pages long with requirements, so I'll just give you the cut and dry version:

Write a program that plays the game of life. Create a class with the name "boolMatrix" for storing and processing a two dimensional array of bool values. We need to read in a dat file that basically contains a pair of coordinates representing the row / col of the locations containing the true values (live cells). the array must be 20 by 20 to start. We need 8 member functions.

This is basically it, with a bunch more specs about whether a cell lives in the future generations and such... The problem is that this is the first time we have used either classes or 2 d arrays and I'm having a terrible time using them together.

nicolivolkov
Newbie Poster
18 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

1. Plan what you think you need to do on paper, i.e NO CODE
2. Draw a flow chart, how does your program go from start to finish?
3. Play with 2d arrays, filling and printing them out.
4. Learn how a basic class can be built.
5. Think about what methods your class will have.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

When you've actually got some code together post back. Have a go.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

Well I have spent quite a bit of time working on this... I just don't really understand it and the class is online and the teacher is never available for help. Which is probably why 22 people have dropped. Here's what I've come up with so far. It's not much and I truthfully don't understand exactly where I'm going with it.

Is there a way to attach the entire assgnment?

#include <iostream>
#include <fstream>
#include "boolMatrix.h"
using namespace std;
const int num_rows = 20;
const int num_cols = 20;
boolMatrix booleanMatrix[row_num][col_num];
int row = 0;
int col = 0;


boolMatrix::boolMatrix()
{
     for(int row = 0; row < num_rows; row++){
         for(int col = 0; col < num_cols; col++){
              return false;
         }                          
     }
}


boolMatrix boolMatrix::get( boolMatrix booleanMatrix)const
{
     return booleanMatrix (row, col);      
}

void boolmatrix::set (boolMatrix booleanMatrix)
{
     ifstream infile("location_alive.dat");
     int row, col;          
     
     
     while(infile){
           infile >> row >> col;
           booleanMatrix.set(row,col,"TRUE");
     }    
}
nicolivolkov
Newbie Poster
18 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

Please post your code with code tags. See the watermark in the background.

Ok, briefly tell me what all your member functions are for your class and what you expect them to do?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

At the bottom of the "Advanced reply", you can attach a number of different types of files. And if you do post the code right in your post, please use Code tags. (More info in my sig)

Just a note: you're not allowed to return anything in a class's constructor, which is what you're trying to do in boolMatrix::boolMatrix()

Can't see any more until you post the other files... but it looks good.

John A
Vampirical Lurker
Team Colleague
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
 

Also what does BoolMatrix.h look like?

What does your dat file look like.

Post an example please and use code tags.

[edit]I need sleep, I'll be back in the morning.[/edit]

Remember plan it first before you do any coding!

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

Hi ProgrammerJoe,

I uploaded the file, I hope it worked. Please let me know. Inside the main assignment are links to the input file. I'm not sure if they were cut out when I attached though.

I'm not sure what "tags" are. I haven't used them thus far in C++ other CSS HTML and ASP yes, but C++ not sure what they are.

I'm basically stuck at this point.

Attachments Project_5.doc (32.5KB)
nicolivolkov
Newbie Poster
18 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

I had almost the same problem 2 weeks ago ,but i've done it in c (we aren't learning c++ until next semester)
The ideea is the same ,try to convert it in c++

/*  Autor:Matei Dragos
    Grupa:133
    Problema:No1 din lab6.pdf 
    Enunt:Plecand de la o generatie de virusi data, sa se scrie un program care sa calculeze
          numarul de virusi ai fiecarei generatii si sa se afiseze configuratia corespunzatoare,
          timp de un numar dat de generatii, stiind ca populatia evolueaza astfel:
          a) un virus moare cand e izolat (are mai putin de 2 vecini) sau sufocat (mai mult
             de 3 vecini)
          b) un virus apare daca are 3 vecini.
   Observatie:Acest program a fost creat si rulat cu succes cu Visual C++ 2005 Express 
              Edition pe Win XP.


*/

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

#define SIZE 100


int vecini(int v[SIZE][SIZE],int i,int j)

{   
    int k,q,suma=0;

    for(k=i-1;k<=i+1;k++)
        for(q=j-1;q<=j+1;q++)
            suma=suma+v[k][q];


    if(suma<3 || suma>4) return 1;
    else if(suma==3) return 2;

}



int main()
{

    int v[SIZE][SIZE],n,i,j,virusi=0,d;
    int nr,generatii;

    printf("N= ");
    scanf("%d",&n);
    srand((unsigned)time(0));

    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            v[i][j]=rand()%2;//generating values(0 or 1)

    printf("Numarul de generatii: ");
    scanf("%d",&nr);
    printf("Matricea initiala :\n");

    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            if(v[i][j]==1) virusi++;
            printf("%d ",v[i][j]);
        }
        printf("\n");

    }

    printf("\nNumarul de virusi : %d",virusi);
    printf("\n");


    //adding a 0 border

    for(j=0;j<=n+1;j++)
        v[0][j]=v[n+1][j]=0;

    for(i=0;i<=n;i++)
        v[i][0]=v[i][n+1]=0;

    //elements checking
    generatii=nr;

    do 
    {
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            { 
                d=vecini(v,i,j);
                if(v[i][j]==1 && d==1)
                    v[i][j]=0;
                else if(v[i][j]==0 && d==2)
                    v[i][j]=1;
            }
        }
        generatii--;
    }while(generatii!=0);

    //afisarea
    virusi=0;
    printf("\nMatricea dupa %d generatii :\n",nr);


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

        for(j=1;j<=n;j++)
        {   

            printf("%d ",v[i][j]);
            if(v[i][j]==1) virusi++;

        }
        printf("\n");

    }


    printf("\nNumarul de virusi : %d\n",virusi);

    return 0;

}


I'll try to come later and post some comments and change the code in english,but right now i have to go

I hope it helped

Eko
Junior Poster in Training
60 posts since Nov 2006
Reputation Points: 12
Solved Threads: 1
 

>I'm not sure what "tags" are.
Did you click the link in my signature about code tags? It clearly describes how to use them. In case that doesn't make sense, just do this:
[code]
// code goes here!
[/code]


Your code then ends up looking like this

//Nicely formatted code with code tags.



Also try inlinecode tags for use in a sentance like this .

Oh, and perhaps you want to attach the code files rather than the document. That's sorta more helpful ;).

John A
Vampirical Lurker
Team Colleague
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
 

Hey Joe,

I'm not sure what code files you want. The only code I have written so far is what I've put above, the three member functions. I thought you wanted the assignemtn specs, sorry...

nicolivolkov
Newbie Poster
18 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

Please describe what this method does:

boolMatrix::boolMatrix()
{
     for(int row = 0; row < num_rows; row++){
         for(int col = 0; col < num_cols; col++){
              return false;
         }                          
     }
}


The function makes no sense

void boolmatrix::set (boolMatrix booleanMatrix)
{
     ifstream infile("location_alive.dat");
     int row, col;          
     
     
     while(infile){
           infile >> row >> col;
           booleanMatrix.set(row,col,"TRUE");
     }    
}

What happens if you readrow & col and they are out of bounds? You should check for errors.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

Well my logic was to initialize everything to false. then read in the values of the file which are coordinates to true (live) cells.

I'm not sure how to check for errors. This is why I'm here. I'm desparately needing help. Our class started with 28 people and it's down to 5. The teacher doesn't really explain this stuff very well. If you could help me, I'd really appreciate it.

nicolivolkov
Newbie Poster
18 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 
Well my logic was to initialize everything to false.

Good logic. How does this function do that? The first time you enter both loops you exit the entire function, never setting a thing.I'm not sure how to check for errors. This is why I'm here. I'm desparately needing help. Our class started with 28 people and it's down to 5. The teacher doesn't really explain this stuff very well. If you could help me, I'd really appreciate it.

if ((row < 0) || (row >= num_rows))
{
    // error condition
}


Display the values as you read them to make sure they are being read properly.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

OKay so the function should not be a value returning function?

What is it that needs to be set to false? The particular location of the array right? But in the default constructor there is no array?

I'm so confused!

nicolivolkov
Newbie Poster
18 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 
Good logic. How does this function do that? The first time you enter both loops you exit the entire function, never setting a thing.

Would it even compile...
He's returning a boolean from a constructor, AFAIK constructors aren't allowed to have returnvalues (but I admit my C++ is rusty). But in the default constructor there is no array?

You need to SET the values, not return them...
But first you must create the array.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Okay so I have my 2D array which is of type "boolMatrix" I'll call the array "booleanMatrix". So in my default constructor I hvae the nested for loops that go down the rows and across the column. Instead of returning false, does this work:

boolMatrix::boolMatrix()
{
    for(int row = 0; row< num_rows; row++){
         for(int col= 0; col<num_cols; col++){
booleanMatrix[row][col] = false;
}
}
}

I'm not clear on where to place the error checking?

Is this a start?

nicolivolkov
Newbie Poster
18 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

Okay so I have my 2D array which is of type "boolMatrix" I'll call the array "booleanMatrix". So in my default constructor I hvae the nested for loops that go down the rows and across the column. Instead of returning false, does this work:

boolMatrix::boolMatrix()
{
    for(int row = 0; row< num_rows; row++){
        for(int col= 0; col<num_cols; col++){
            booleanMatrix[row][col] = false;
        }
    }
}


MUCH better. :mrgreen: Although you want to format your code, so I took the liberty...;)I'm not clear on where to place the error checking?Error checking goes where you might have errors, such as reading in a value from the user or a file that's bogus.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You