Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 20.02.2010, 21:37   #1
Dimanng
Новичок
Джуниор
 
Регистрация: 20.02.2010
Сообщений: 1
Вопрос Not implemented in type

Написал вот такую программку на C++, но почему-то выдаёт ошибки:
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
char bufRus [256];
char* Rus(char* mes)
{ CharToOem (mes, bufRus);
return bufRus;
}
class Matrix
{
private:
public:
int Rows;
int Cols;
double **Elems;

Matrix(int r, int c)
{
Rows = r;
Cols = c;
Elems = new double*[r];
for (int i=0; i<r; ++i)
Elems[i] = new double [c];
}
Matrix(const Matrix &a)
{
Rows = a.Rows;
Cols = a.Cols;
Elems = new double*[Rows];
for (int i=0; i<Rows; ++i)
Elems[i] = new double [Cols];

for (int i=0;i<a.Rows;i++)
for (int j=0;j<a.Cols;j++)
Elems[i][j]=a.Elems[i][j];
}
~Matrix();

static Matrix* adding(const Matrix& a, const Matrix& b)
{
if(a.Cols!=b.Cols || a.Rows!=b.Rows) cout << "matrix not added";
Matrix* c = new Matrix(a.Rows, b.Cols);

for (int i = 0; i < a.Rows; i++)
for (int j = 0; j < b.Cols; j++)
c->Elems[i][j] = a.Elems[i][j] + b.Elems[i][j];
return c;
}
static Matrix* subtract(const Matrix& a, const Matrix& b)
{
if(a.Cols!=b.Cols || a.Rows!=b.Rows) cout << "matrix not subtracted";
Matrix* c = new Matrix(a.Rows, b.Cols);

for (int i = 0; i < a.Rows; i++)
for (int j = 0; j < b.Cols; j++)
c->Elems[i][j] = a.Elems[i][j] - b.Elems[i][j];
return c;
}
static Matrix* multiply(const Matrix& a, const double n)
{
Matrix* c = new Matrix(a.Rows, a.Cols);
for (int i=0; i<a.Rows; ++i)
for (int j=0; j<a.Cols; ++j)
c->Elems[i][j] = a.Elems[i][j] * n;
return c;
}

static Matrix* multiply(const Matrix& a, const Matrix& b)
{
if (a.Cols != b.Rows) cout << "matrix not multiplied";
Matrix* c = new Matrix(a.Rows, b.Cols);

for (int i = 0; i < a.Rows; i++)
for (int j = 0; j < b.Cols; j++)
{
double Sum = 0;
for (int n = 0; n < b.Rows; n++)
Sum += a.Elems[i][n] * b.Elems[n][j];
c->Elems[i][j] = Sum;
}
return c;
}
/* static Matrix* divide(const Matrix& a, const Matrix& b)
{
Matrix* c = multiply(a, *(Matrix*)invers(b));
for (int i=0; i<c->Rows; ++i)
for (int j=0; j<c->Cols; ++j)
if(fabs(c->Elems[i][j]) < epsilon)
c->Elems[i][j]=0.0;
return c;
}

static Matrix* divide(const Matrix& a, const double b)
{
Matrix* c = new Matrix(a);
for (int i=0; i<c->Rows; ++i)
for (int j=0; j<c->Cols; ++j)
{
c->Elems[i][j] /= b;
if(fabs(c->Elems[i][j]) < epsilon)
c->Elems[i][j]=0.0;
}
return c; */


Matrix* operator + (const Matrix& a) const
{
return adding(*(Matrix*)this, a);
}

Matrix*operator - (const Matrix& a) const
{
return subtract(*(Matrix*)this, a);
}

Matrix* operator * (const Matrix& a) const
{
return multiply(*(Matrix*)this, a);
}

Matrix* operator * (const double a) const
{
return multiply(*(Matrix*)this, a);
}

/* Matrix* operator / (const Matrix& a) const
{
return divide(*(Matrix*)this, a);
}

Matrix* operator / (const double a) const
{
return divide(*(Matrix*)this, a);
} */
bool is_symmetric()
{
if(Cols != Rows)
return false;
for (int i=1; i<Rows; ++i)
for(int j=0; j<i; ++j)
if(Elems[i][j]!=Elems[j][i])
return false;
return true;
}
void print()
{

for (int i=0; i<Rows; ++i)
{
for (int j=0; j<Cols; ++j)
std::cout<<Elems[i][j]<<"\t";
std::cout<<std::endl;
}
}


};
int main ()
{
Matrix m1(3, 3);
Matrix m2(2, 2);
Matrix m3(2, 2);

cout<<"M1:"<<endl;
for(int i=0; i<m1.Rows; ++i)
for (int j=0; j<m1.Cols; ++j)
m1[i][j] = rand()%20;
m1.print();

cout<<endl<<"M2:"<<endl;
for(int i=0; i<m2.Rows; ++i)
for (int j=0; j<m2.Cols; ++j)
{
m2[i][j] = rand()%20;
m3[i][j] = rand()%20;
}
m2.print();
cout<<endl<<"M3:"<<endl;
m3.print();

/*
cout<<endl<<"M1-M2:"<<endl; // разная размерность матриц
(m1-m2)->print();
*/

cout<<endl<<"M2 - M3:"<<endl;
(m2-m3)->print();

cout<<endl<<"M2 / M3:"<<endl;
(m2 / m3)->print();


cout<<endl<<"M1 is symmetric: "<<(m1.is_symmetric() ? "Yes" : "No");

system("pause > nul");
return 0;
};

Вот список ошибок:
[C++ Error] Unit1.cpp(168): E2094 'operator+' not implemented in type 'Matrix' for arguments of type 'int'
[C++ Error] Unit1.cpp(175): E2094 'operator+' not implemented in type 'Matrix' for arguments of type 'int'
[C++ Error] Unit1.cpp(176): E2094 'operator+' not implemented in type 'Matrix' for arguments of type 'int'
[C++ Error] Unit1.cpp(191): E2093 'operator/' not implemented in type 'Matrix' for arguments of the same type
Помогите кто чем может. Спасибо.
Dimanng вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Определение Content-Type HTL Работа с сетью в Delphi 6 18.02.2010 12:32
unsafe type Sergey2 Общие вопросы Delphi 0 08.08.2009 18:01
Method must have a return type????? Bobrik Помощь студентам 5 18.05.2009 18:09
Как побороть ошибку "tStream.seek not implemented" Altera Работа с сетью в Delphi 5 18.03.2009 19:31
New Type Манжосов Денис :) Общие вопросы Delphi 5 30.07.2008 12:34