0

here are my codes:

#ifndef STUDENT_H
#define STUDENT_H


class student
{
    public:
        void enterDetails();
        void enterModule();
        void displayDetails();


    private:
        char name[100];
        char studID[100];
        char address[100];
        char module[100];

};


#endif 

i want to add a 2d array "M[row][col]" in my class but i don't know how to do it anyone help?

3
Contributors
2
Replies
13
Views
3 Years
Discussion Span
Last Post by Edward_3
0

i want to add a 2d array "M[row][col]" in my class but i don't know how to do it anyone help?

whats the problem with that?
i think it would be same with class concept(i've not started yet with class concept) .
just declare variable with 2 dimension will make it 2d array.

int ar[10][10];//this is 2d array

Edited by Learner010

0

Hi nitish.mohiputlall,
It is better if you declare pointer variables then do "dynamically allocated array".
For 1D array:

char *array
//create 1D array
array = new char[size]

//use 1D array

// delete 1D array
delete [] array

For 2D array, similarly:

//create 2D array
char **array = new *char[ROWS];
for( int i = 0; i < ROWS; i++ )
    array[i] = new char[COLS];

//use 2D array

// delete 2D array
for( int i = 0; i < ROWS; i++ )
    delete[] array[i];
delete [] array;

Somthing like that, you could google the keywords for more information. Hope it helps.

Edited by Edward_3: typing error

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.