Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
1
Добавлен:
01.05.2014
Размер:
3.97 Кб
Скачать
//Point1.cpp

#include <iostream.h>
#include <math.h>
#include "point1.h"

/////////////////CREATE_AND_DESTROY//////////////////

Point::Point(int count) //constructor
{ 
	n=count; 
	x=new double[n];
}


Point::Point(const Point& pt) //constructor of coping
{
	n=pt.n; x=new double[n];
	operator = (pt);
}

  Point::~Point() //destructor
  { 
	  delete[] x; 
  }

/////////////////////SET_POINT///////////////////////

void Point::setPoint(double pnt[])
{
	int i=0;
	while (i<n)
	{
		x[i]=pnt[i];
		i++;
	}

}


//////////////////////PRINT_POINT/////////////////////

void Point::printPoint()
{
	int i=0;
	while (i<n)
	{
		cout << x[i] << " ";
		i++;
	}

	cout << endl;

}

/////////////////PRINT_POINT_EXTENTED/////////////////

void Point::printPointEx(const char *string)
{
	cout << string << ": (";
	int i=0;
	while (i<n)
	{
		cout << x[i] << " ";
		i++;
	}

	cout << ")\n";

}

///////////////////Norma///////////////////////

double Point::norma()
{
	double ans=0;
    int i=0;
	while (i<n)
	{
        ans=ans+x[i]*x[i];
		i++;
	}

	return sqrt(ans);

}

///////////////////Vector_Length///////////////////////

double Point::VectorLength()
{
	double ans=0;
	int i=0;
	while (i<n)
	{
		ans=ans+x[i]*x[i];
		i++;
	}
	return sqrt(ans);

}

/////////////////Norma_of_vector//////////////////////

void Point::Norming()
{
	double temp=VectorLength();
	int i=0;
	while (i<n)
	{
        x[i]=x[i]/temp;
		i++;
	}

}


////////////////////sumCoordinates////////////////////////

double Point::sumCoordinates()
{
	double ans=0;
	int i=0;
	while (i<n)
	{
		ans=ans+x[i];
		i++;
	}

    return ans;
}

///////////////////////Inaccuracy//////////////////////////

void Point::Inaccuracy(double xmin[])
{
	cout << "Inaccuracy: ";
	int i=0;
	while (i<n)
	{
		cout << fabs(xmin[i]-x[i]) << " ";
		i++;
	}
	cout << endl;

}

/////////////////////////SummAB/////////////////////////////

Point Point::operator + (const Point &A)
{
	Point result(n);
	int i=0;
	while (i<n)
	{
		result.x[i]=x[i]+A.x[i];
		i++;
	}

	return result;

}

/////////////////////////MinusAB/////////////////////////////

Point Point::operator - (const Point &A)
{
	Point result(n);
	int i=0;
	while (i<n)
	{
		result.x[i]=x[i]-A.x[i];
		i++;
	}

	return result;

}

/////////////////////////MinusX/////////////////////////////

Point Point::operator - ()
{
	Point result(n);
	int i=0;
	while (i<n)
	{
		result.x[i]=-x[i];
		i++;
	}

	return result;

}

/////////////////////////Equal/////////////////////////////

Point& Point::operator = (const Point &A)
{
	int i=0;
	while (i<n)
	{
		x[i]=A.x[i];
		i++;
	}

	return *this;

}

///////////////////////EqualAlpha//////////////////////////

Point& Point::operator = (const double alpha)
{
	int i=0;
	while (i<n)
	{
		x[i]=x[i]*alpha;
		i++;
	}

	return *this;

}

//////////////////////DemuxAlpha////////////////////////////

Point Point::operator * (const double alpha)
{
	Point result(n);
	int i=0;
	while (i<n)
	{
		result.x[i]=x[i]*alpha;
		i++;
	}

	return result;

}

////////////////////////Demux//////////////////////////////

Point Point::operator * (const Point &A)
{
	Point result(n);
	int i=0;
	while (i<n)
	{
		result.x[i]=x[i]*A.x[i];
		i++;
	}

	return result;

}

///////////////////////operator[]///////////////////////////

double &Point::operator [] (int i)
{

	return x[i];

}

///////////////////////operator()///////////////////////////

Point& Point::operator () (const Point &A)
{
	int i=0;
	while (i<n)
	{
		x[i]=A.x[i];
		i++;
	}

	return *this;

}

///////////////////////operator()///////////////////////////

Point& Point::operator () (const double alpha)
{
	int i=0;
	while (i<n)
	{
		x[i]=alpha;
		i++;
	}

	return *this;

}



Соседние файлы в папке Лабораторная работа №62
  • #
    01.05.2014547 б1ObobshNuton.dsw
  • #
    01.05.201482.94 Кб1ObobshNuton.ncb
  • #
    01.05.201454.78 Кб1ObobshNuton.opt
  • #
    01.05.20141.23 Кб1ObobshNuton.plg
  • #
    01.05.20147.14 Кб1ON.CPP
  • #
    01.05.20143.97 Кб1Point1.cpp
  • #
    01.05.20141.41 Кб1Point1.h
  • #
    01.05.2014456 б1resource.h
  • #
    01.05.20142.14 Кб1Script1.rc