[ create a new paste ] login | about

Link: http://codepad.org/vAuUf5pO    [ raw code | fork ]

C++, pasted on Mar 21:
#include <iostream>
using namespace std;
 
class Matrix 
{
private:
		int** matrix1;
public:
	void create (int Nlines,int Ncolumns)    // создание матрицы
	{
		matrix1 = new int*[Nlines];

		for (int i =0; i<Nlines; i++)
			matrix1[i] = new int [Ncolumns];
		
	}
 void add_data (int Nlines,int Ncolumns)    // добавление в матрицу значений
 {
	 int p = 1;
	 for (int i =0; i<Nlines; i++){
				for (int k = 0; k<Ncolumns; k++){

					matrix1[i][k] = p*10+p;
					p++;
			
				}
				
			}
 }
	void show_matrix (int Nlines,int Ncolumns)   // показ на экран
	{
			for (int i =0; i<Nlines; i++){
				for (int k = 0; k<Ncolumns; k++){

					cout << matrix1[i][k] << " ";
			
				}
				cout << endl;
			}
	}
	void replace (int Nlines,int Ncolumns)    // замена матрицы
	{
		int** temp;
		temp = new int*[Ncolumns];

		for (int i =0; i< Ncolumns;i++)
			temp [i] = new int [Nlines];


		for (int i =0; i<Nlines; i++)
		{
			for (int k = 0; k<Ncolumns; k++)
			{
				temp[k][i] = matrix1[i][k];
			}
		}

		for (int i =0; i< Nlines;i++)
			delete [] matrix1[i];
		delete [] matrix1;

matrix1 = temp;		


	}
	
};	
 
int main()
{
	int lines =0;
	int columns =0;
	cout << "enter n lines : ";
	cin>> lines;
	cout << endl << "enter n columns : ";
	cin>> columns;
	

	Matrix obj;

	
	obj.create(lines,columns);
	obj.add_data(lines,columns);
	obj.show_matrix(lines,columns);
	obj.replace(lines,columns);
	obj.show_matrix(columns,lines);

}


Create a new paste based on this one


Comments: