sobre matricesssssssss¡¡¡ayuda por favor!!

marianis
21 de Septiembre del 2004
hola!!!, necesito ayuda urgente!!!!
¿como hacer un programa que le pida al ususario el n° de columnas y filas de una matriz bidimensional, (porsupuesto que la forme) y que la rellene con números secuenciales.(y que esto aparezca en pantalla)?

por favor ayudenme,gracias!!

[email protected]

noel solw
21 de Septiembre del 2004
te envio un programa que realiza algo parecido a lo que tu necesitas. Espero que te sirve de ayuda.

// MatDina.cpp
// matriz dinamica dentro de una clase.
// written in borland c++, ver 4.5

#include <iostream.h>
#include <iomanip.h>

class Test
{
private:
int **a;
int rows,
cols;
void Init();
public:
Test(int ROWS,int COLS);
~Test();
void Show();
}; // CLASS TEST

Test::Test(int ROWS,int COLS) : rows(ROWS),cols(COLS)
{
cout << "constructor : " << rows << " x " << cols << endl;
a = new int*[rows];
for(int i = 0;i < rows;i++)
a[i] = new int[cols];
Init();
} // TEST CONSTRUCTOR

Test::~Test()
{
cout << "destructor : " << rows << " x " << cols << endl;
for(int i = 0;i < rows;i++)
delete []a[i];
delete []a;
} // TEST DESTRUCTOR

void Test::Init()
{
int counter = 1;
for(int i = 0;i < rows;i++)
for(int j = 0;j < cols;j++)
a[i][j] = counter++;
} // TEST INIT

void Test::Show()
{
for(int i = 0;i < rows;i++)
{
for(int j = 0;j < cols;j++)
cout << setw(5) << a[i][j];
cout << endl;
}
cout << endl;
} // TEST SHOW

int main()
{
Test a(4,5), b(7,3),c(3,7);
cout << endl;
a.Show();
b.Show();
c.Show();
return 0;
} // MAIN