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

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

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

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

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

Ответ
 
Опции темы Поиск в этой теме
Старый 23.09.2012, 22:37   #1
ol-k_34
Пользователь
 
Регистрация: 08.02.2012
Сообщений: 31
По умолчанию use of undefined type..

Привет всем! Программа реализации двух классов. Выдает ошибку use of undefined type 'Vector4' . не знаю как ее исправить. можете чем помочь или подсказать?
Код:
#include<iostream>
#include<conio.h>
#include<locale.h>

using std::cout;
using std::cin;
using std::endl;

const int N = 4;
class Vector4;

class Matrix4
{
protected:
			double _matrix[N][N];
public:
			Matrix4 () {};
			~Matrix4 () {};
			friend class Vector4;
			friend void Vector4::MultVectorMatrix(const Matrix4& Matrix, const Vector4& Vector);
			void InputMatrix();
			void OutputMatrix();
			void NumberMatrix(int Number);
			void MatrixVec(const Matrix4& Vector);
			Matrix4 operator*(const Matrix4& Matrix)const;
			Matrix4 operator+(const Matrix4& Matrix)const;
};

class Vector4
{
			
protected:
			double _vector[N];
public:
			Vector4 () {};
			~Vector4 () {};
			void MultVectorMatrix(const Matrix4& Matrix, const Vector4& Vector);
			void InputVector();
			void OutputVector();
			Vector4 operator*(const Vector4& Vector)const;
			Vector4 operator+(const Vector4& Vector)const;
};
//--------------------Реализация класса Matrix4-------------------
void Matrix4::InputMatrix()
{
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			cin >> _matrix[i][j];
		}
	}	
}
void Matrix4::OutputMatrix()
{
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			cout << " " << _matrix[i][j];
		}
		cout << endl;
	}
}
void Matrix4::NumberMatrix(int Number)
{
	for (int i = 0; i < N; ++i)
		{
			for (int j = 0; j < N; ++j)
			{
				_matrix[i][j] = _matrix[i][j]*Number;
				cout << _matrix[i][j] << " ";
			}
			cout << endl;
		}
}
Matrix4 Matrix4::operator +(const Matrix4& Matrix)const
{
	Matrix4 ResultMatrix(*this);

	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			ResultMatrix._matrix[i][j] = this->_matrix[i][j] + Matrix._matrix[i][j];
		}
	}

	return ResultMatrix;
}
Matrix4 Matrix4:: operator*(const Matrix4& Matrix)const
{
	Matrix4 ResultMatrix(*this);

	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < N; ++j)
		{	
			ResultMatrix._matrix[i][j] = 0;
			for (int k = 0; k < N; ++k)
			{
				ResultMatrix._matrix[i][j] += this->_matrix[i][k]*Matrix._matrix[k][j];
			}
		}
	}
	return ResultMatrix;
}

//-------------------------Реализация класса Vector4----------------------
void Vector4::InputVector()
{
	for (int i = 0; i < N; ++i)
	{
		cin >> _vector[i];
	}
}
void Vector4::OutputVector()
{
	for (int i = 0; i < N; ++i)
	{
		cout << " " << _vector[i]; 
	}

	cout << endl;
}
Vector4 Vector4::operator +(const Vector4& Vector)const
{
	Vector4 ResultVector(*this);
		for (int i = 0; i < N; ++i)
		{
			ResultVector._vector[i] = this->_vector[i] + Vector._vector[i];
		}
		return ResultVector;
}
void Vector4::MultVectorMatrix(const Matrix4& Matrix, const Vector4& Vector)
{	
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			_vector[i] += Matrix._matrix[i][j]*Vector._vector[i];
		}
		cout << _vector[i] <<" ";
	}
}
void main()
{
	Matrix4 x,y,c,d;
	int num;
	Vector4 a,b,g;
	setlocale(LC_ALL,"Russian");
	cout << "Введите первую матрицу:" << endl;
	x.InputMatrix();
	cout << "Введите вторую матрицу:" << endl;
	y.InputMatrix();
	cout << "Введите первый вектор:" << endl;
	a.InputVector();
	cout << "Введите первый вектор:" << endl;
	b.InputVector();
	cout << "Первая матрица:" << endl;
	x.OutputMatrix();
	cout << "Вторая матрица:" << endl;
	y.OutputMatrix();
	cout << "Первый вектор: " << endl;
	a.OutputVector();
	cout << "Второй вектор: " << endl;
	b.OutputVector();
	c = x*y;
	cout << "Произведение первой и второй матрицы равно:" << endl;
	c.OutputMatrix();
	d = x + y;
	cout << "Сумма матриц равна:" << endl;
	d.OutputMatrix();
	cout << "Введите число на которое будет умножена матрица: ";
	cin >> num;
	x.NumberMatrix(num);
	cout << "Умножение матрицы на вектор:" << endl;
	cout << "Умножение вектора на матрицу:" << endl;
	MultVectorMatrix(x,a);
	cout << "Сложение векторов:" << endl;
	g = a + b;
	g.OutputVector();
	getch();
ol-k_34 вне форума Ответить с цитированием
Ответ


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



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Could not convert variant of the type (String) into type (Boolean) Silly Student C++ Builder 0 19.11.2011 13:06
Отличие type T = Object от type T = Class? Warn Общие вопросы Delphi 8 04.11.2011 19:20
Could not convert variant of type (Olestr) into type (Double) java_91 Общие вопросы Delphi 1 18.02.2011 18:46
The type name 'GreenShalControl' does not exist in the type Beton_net WPF, UWP, WinRT, XAML 0 15.02.2011 11:24
Could not convert variant of type (UnicodeString) into type (Double) postaveche БД в Delphi 11 13.12.2010 16:41