Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа №62 / Point1
.cpp//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