Форум С++

 

Ответить на сообщение

Вернуться к теме

Вы отвечаете на сообщение:

Автор: Vitaliy113   (06.04.2010 в 16:08)
все, разобрался, все сделал, кому интересно вот код:

#include <stdafx.h>
#include <iostream>
#include <fstream>
#include <math.h>

using namespace std;
int i,j,n,m;
class TRMATR
{
int e,r;
int **M;
public:
int MT[250][250];
TRMATR(){};
TRMATR(int n,int m){
M=new int*[n];
for (i=1; i<n+1; i++)
M[i] = new int[m];
};
friend istream &operator>>(istream &stream, TRMATR &ob2);
friend ostream &operator<<(ostream &stream, TRMATR ob2);
};

istream &operator>>(istream &stream, TRMATR &ob2)
{
{
//system("cls");
cout<<"Enter the matrix elements:\n";

for(i=1;i<n+1;i++)
{
for(j=1;j<m+1;j++)
{
cout<<"element "<<i<<" "<<j<<"=";
stream>>ob2.M[i][j];
system("cls");
};
};
};
return stream;
}

ostream &operator<<(ostream &stream, TRMATR ob2)
{
{
cout<<" Initial matrix: \n";
for(i=1;i<n+1;i++)
{ cout<<" \n";
for(j=1;j<m+1;j++)
{
stream<<ob2.M[i][j]<<" ";
};
}
stream<<" \n" ;
}
cout<<"-----------------------------";
////////transposition/////////////
{
for(i=1;i<n+1;i++)
{
for(j=1;j<m+1;j++)
{
ob2.MT[j][i]=ob2.M[i][j];
};};};
{
cout<<"\n Transposed matrix: \n";
for(i=1;i<m+1;i++)
{ cout<<" \n";
for(j=1;j<n+1;j++)
{
stream<<ob2.MT[i][j]<<" ";
};};
stream<<" \n" ;
};
return stream;
}

void main()
{
cout<<"Enter number of rows: \n";
cin>>n;
cout<<"Enter number of columns: \n";
cin>>m;
TRMATR ob(n,m);
cin>>ob;
cout<<ob;
}


по аналогии можно сделать и матрицу MT, но мне это уже не нужно было)


Ваше имя:

Пароль:

Цитировать

Используйте тэги для выделения текста:
Код: [code][/code]
Жирный: [b][/b]
Наклонный: [i][/i]
URL: [url][/url]

Сообщение:

Прикрепить: