#ifndef	__MATRIX_H
#define	__MATRIX_H
/*
 * Simple Vector & Matrix classes for numerical calculations.
 *
 * Copyleft (C) 1993 NIEE Hackers League
 * Copyleft (C) 1993 Yury Kuznesoft
 * Copyleft (C) 1993 Tony Kozienko
 * Copyleft (C) 1993 Serg Ippolitov
 * Portion Copyleft A. Mudroff
 *
 * This code may seems not very elegant, because of stupid
 * restrictions of tc++ 1.0 (this compiler was choosen as
 * everywhere running). Seems that AT&T 2.1 frontend
 * can understand this (stupid) constructions.
 * Ugly implementation of gauss, inv, etc. show the great
 * Mudroff's programming style.
 * Future improvments will (somewhere in time) include
 * templates, exceptions, etc.
 * 			Tony.
 */
#ifndef __IOSTREAM_H
#include <iostream.h>
#endif   /* __IOSTREAM_H */
#ifndef  __MATH_H
#include <math.h>
#endif  /* __MATH_H */
#ifndef __STDLIB_H
extern "C" {
void        _Cdecl exit(int __status);
}
#endif  /* __STDLIB_H */
typedef double Float;

class Matrix;

class Vector
{
public:
	Vector( int );
	Vector( int, const Float* );
	Vector( Vector& );
	Vector (istream&, ostream&);
	~Vector();

	int size() const { return n; }
	Vector& operator =( Vector& );

	Float& operator []( int ) const;
	Vector operator +( Vector& ) const;
	Vector operator -( Vector& ) const;
	Float operator *( Vector& ) const;
	Vector operator *( Float ) const;
	Vector operator /( Float ) const;
	Vector operator *( Matrix& ) const;

	Float norma() const;
	Float max() const;
 	Float min() const;
	Float distance(Vector& ) const;

	friend ostream& operator <<( ostream&, Vector& );
	friend istream& operator >>( istream&, Vector& );
protected:
	void checkComp( Vector& ) const;
private:
	Float* data;
	int n;
};

typedef Vector* pVector;

class Matrix
{
public:
	Matrix( int, int, Float = 0. );
	Matrix( int, int, const Float* );
	Matrix( Matrix& );
	Matrix( istream&, ostream& );
	~Matrix();

	int sizeN() const { return n; }
	int sizeM() const { return m; }
	Vector row( int ) const;
	Vector column( int ) const;
	Matrix& operator =( Matrix& );

	Vector& operator []( int ) const;
	Matrix operator +( Matrix& ) const;
	Matrix operator -( Matrix& ) const;

	Vector operator *( Vector& ) const;
	Matrix operator *( Matrix& ) const;
	Matrix operator *( Float ) const;
	friend Matrix operator *( Float a, Matrix& b );

	Vector gauss( Vector vec) const;
	Float  det() const;
	Matrix trans() const;
	Matrix inv() const;
	int    sym() const;
	Float  Sp() const; //след матрицы
      Vector SobNum() const;  //собств.числа матрицы
	friend ostream& operator <<( ostream&, Matrix& );
	friend istream& operator >>( istream&, Matrix& );
private:
	int n, m;
	Vector** data; // fucking tc++ 1.0 !!!

	void allocData();
};

#endif	/* __MATRIX_H */
