Читайте также: |
|
Заголовочний файл vector.h
#ifndef _vector
class vector {
public:
double x1;
double y1;
double x2;
double y2;
vector(double x3, double y3, double x4, double y4);
vector();
void add(vector c);
void add(double c);
void add(double x3, double y3, double x4, double y4);
void sub(vector c);
void sub(double c);
void sub(double x3, double y3, double x4, double y4);
void mul(double c);
System::String^ ToString();
void ReWrite(double x3, double y3, double x4, double y4);
double Length();
vector operator +(vector c);
vector operator +(int c);
vector operator +(double c);
vector operator +=(vector c);
vector operator +=(int c);
vector operator +=(double c);
vector operator -(vector c);
vector operator -(int c);
vector operator -(double c);
vector operator -=(vector c);
vector operator -=(int c);
vector operator -=(double c);
vector operator *(int c);
vector operator *(double c);
vector operator *=(int c);
vector operator *=(double c);
vector operator ++();
vector operator --();
bool operator ==(vector c);
bool operator >(vector c);
bool operator >=(vector c);
bool operator <(vector c);
bool operator <=(vector c);
bool operator!=(vector c);
};
#define _vector
#endif
Реалізація vector.cpp
#include "stdafx.h"
#include "vector.h"
vector::vector(double x3, double y3, double x4, double y4){
x1 = x3;
y1 = y3;
x2 = x4;
y2 = x4;
};
vector::vector(){
x1 = 0;
y1 = 0;
x2 = 0;
y2 = 0;
};
void vector::add(vector c){
x1 += c.x1;
y1 += c.y1;
x2 += c.x2;
y2 += c.y2;
};
void vector::add(double c){
x2 += c;
y2 += c;
};
void vector::add(double x3, double y3, double x4, double y4){
x1 += x3;
y1 += y3;
x2 += x4;
y2 += y4;
};
void vector::sub(vector c){
x1 -= c.x1;
y1 -= c.y1;
x2 -= c.x2;
y2 -= c.y2;
};
void vector::sub(double c){
x2 -= c;
y2 -= c;
};
void vector::sub(double x3, double y3, double x4, double y4){
x1 -= x3;
y1 -= y3;
x2 -= x4;
y2 -= y4;
};
void vector::mul(double c){
x2 *= c;
y2 *= c;
};
System::String^ vector::ToString(){
return "("+x1.ToString()+" "+y1.ToString()+")"+"("+x2.ToString()+" "+y2.ToString()+")";
};
void vector::ReWrite(double x3, double y3, double x4, double y4){
x1 = x3;
y1 = y3;
x2 = x4;
y2 = y4;
};
#include <math.h>
double vector::Length(){
return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
};
vector vector::operator +(vector c){
c.add(x1,y1,x2,y2);
return c;
};
vector vector::operator +(int c){
vector d = vector(x1,y1,x2,y2);
d.add(c);
return d;
};
vector vector::operator +(double c){
vector d = vector(x1,y1,x2,y2);
d.add(c);
return d;
};
vector vector::operator +=(vector c){
vector d = vector(x1,y1,x2,y2);
d.add(c);
add(c);
return d;
};
vector vector::operator +=(int c){
vector d = vector(x1,y1,x2,y2);
d.add(c);
add(c);
return d;
};
vector vector::operator +=(double c){
vector d = vector(x1,y1,x2,y2);
d.add(c);
add(c);
return d;
};
vector vector::operator -(vector c){
c.sub(x1,y1,x2,y2);
return c;
};
vector vector::operator -(int c){
vector d = vector(x1,y1,x2,y2);
d.sub(c);
return d;
};
vector vector::operator -(double c){
vector d = vector(x1,y1,x2,y2);
d.sub(c);
return d;
};
vector vector::operator -=(vector c){
vector d = vector(x1,y1,x2,y2);
d.sub(c);
sub(c);
return d;
};
vector vector::operator -=(int c){
vector d = vector(x1,y1,x2,y2);
d.sub(c);
sub(c);
return d;
};
vector vector::operator -=(double c){
vector d = vector(x1,y1,x2,y2);
d.sub(c);
sub(c);
return d;
};
vector vector::operator *(int c){
vector d = vector(x1,y1,x2,y2);
d.mul(c);
return d;
};
vector vector::operator *(double c){
vector d = vector(x1,y1,x2,y2);
d.mul(c);
return d;
};
vector vector::operator *=(int c){
vector d = vector(x1,y1,x2,y2);
d.mul(c);
mul(c);
return d;
};
vector vector::operator *=(double c){
vector d = vector(x1,y1,x2,y2);
d.mul(c);
mul(c);
return d;
};
vector vector::operator ++(){
vector d = vector(x1,y1,x2,y2);
d.add(1);
add(1);
return d;
};
vector vector::operator --(){
vector d = vector(x1,y1,x2,y2);
d.sub(1);
sub(1);
return d;
};
bool vector::operator ==(vector c){
if((x1==c.x1)&&(y1==c.y1)&&(x2==c.x2)&&(y2==c.y2)){
return true;
}else{
return false;
};
};
bool vector::operator >(vector c){
if(Length()>c.Length()){
return true;
}else{
return false;
};
};
bool vector::operator >=(vector c){
if(Length()>=c.Length()){
return true;
}else{
return false;
};
};
bool vector::operator <(vector c){
if(Length()<c.Length()){
return true;
}else{
return false;
};
};
bool vector::operator <=(vector c){
if(Length()<=c.Length()){
return true;
}else{
return false;
};
};
bool vector::operator!=(vector c){
if((x1==c.x1)&&(y1==c.y1)&&(x2==c.x2)&&(y2==c.y2)){
return false;
}else{
return true;
};
};
ДОДАТОК Б. Електронні матеріали (диск)
Дата добавления: 2014-12-19; просмотров: 131 | Поможем написать вашу работу | Нарушение авторских прав |