Thread: Hey people, help needed again ^_^

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    16

    Help needed on project, (using a class to allocate a 2d matrix)

    Well, now I'm on assignment 2 and am once again flustered. This time around, we have to use a class to dynamically allocate a 2D Matrix and later integrate it into the previous assignment (My last topic with the 1st assignment)

    Anyway, here's what I have so far.

    Code:
    // main.cpp
    // Donald Parker
    // 09/16/2003
    
    // main.cpp
    // Donald Parker
    // 09/16/2003
    
    #include <iostream>
    #include "matrix.h"
    using namespace std;
    
    #define ROWS = 5
    #define COLS = 10
    
    int main()
    {
    	
    	Matrix table(3,4);
    	Type k = 0;
    	for(int i=0;i<3;i++)
    		for(int j=0;j<4;j++)
    		{
    			table.set(i,j,k++);
    			cout<<table.get(i,j);
    		}
    
    	return 0;
    }
    
    // matrix.cpp
    // Donald Parker
    // 09/16/2003
    
    #include "matrix.h"
    
    Matrix::Matrix()
    {
    	Type *array;
    	_rows = ROWS;
    	_cols = COLS;
    	array = new Type[ROWS*COLS];
    }
    
    Matrix::Matrix(int rows, int cols)
    {
    	Type *array;
    	_rows = rows;
    	_cols = cols;
    	array = new Type[rows*cols];
    }
    
    Matrix::~Matrix()
    {
    }
    
    void Matrix::set(int row, int column, Type symbol)
    {
    	array[row*_rows+column] = symbol;
    
    }
    
    Type Matrix::get(int row, int column)
    {
    	return array[row*_rows+column];
    }
    
    // matrix.h
    // Donald Parker
    // 09/16/2003
    #include <iostream>
    using namespace std;
    
    const int ROWS = 5;
    const int COLS = 10;
    
    #define Type char
    
    class Matrix{
    
    public:
    	Matrix();
    	~Matrix();
    	Matrix(int,int);
    	void set(int,int,Type);
    	Type get(int,int);
    private:
    	Type array[ROWS*COLS];
    	int _rows;
    	int _cols;
    };
    Yeah, you all know my real name now since I'm too lazy to go back and delete it.

    So what can I do.

    This time, I won't be back on until later tonight, so I can't discuss more throughly until then.

    Edit: Sorry for the unclear message title before. You can delete this post, and I'll make a clearer one tomorrow.
    Last edited by Shinobi-wan; 09-16-2003 at 07:40 PM.

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Thank you for reading these and posting threads with a specific topic.
    Away.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Katrina Aftermath: Woeful Incompetence (rant).
    By anonytmouse in forum A Brief History of Cprogramming.com
    Replies: 61
    Last Post: 09-05-2005, 07:39 AM
  2. Will you sign up to fight?
    By mithrandir in forum A Brief History of Cprogramming.com
    Replies: 246
    Last Post: 01-27-2002, 01:48 PM
  3. People these days...
    By Aran in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 11-03-2001, 04:22 PM
  4. Religious Bull****
    By Witch_King in forum A Brief History of Cprogramming.com
    Replies: 119
    Last Post: 10-23-2001, 07:14 AM
  5. IT people - weird genius or simply narrow-minded, antisocial, lazy people
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 10-11-2001, 05:00 AM