Professional Documents
Culture Documents
Task 1 A3
Task 1 A3
Task 1 A3
#include<cmath>
using namespace std;
class vector
{
double* x;
double* y;
double* z;
public:
vector()
{
x = new double;
y = new double;
z = new double;
*x = 0;
*y = 0;
*z = 0;
}
vector(double a, double b, double c)
{
x = new double;
y = new double;
z = new double;
*x = a;
*y = b;
*z = c;
}
vector(const vector& c)
{
x = new double;
y = new double;
z = new double;
*x = *c.x;
*y = *c.y;
*z = *c.z;
}
~vector()
{
//cout << "destructor called for " << *x << " " << *y << " " << *z <<
endl;
delete x;
delete y;
delete z;
}
vector operator=(const vector& c)
{
*x = *c.x;
*y = *c.y;
*z = *c.z;
return *this;
}
vector operator+(const vector& c)
{
vector t;
*t.x = (*x + (*c.x));
*t.y = (*y + (*c.y));
*t.z = (*z + (*c.z));
return t;
}
vector operator-(const vector& c)
{
vector t;
*t.x = (*x - (*c.x));
*t.y = (*y - (*c.y));
*t.z = (*z - (*c.z));
return t;
}
vector operator ++()
{
++(*x);
++(*y);
++(*z);
return *this;
}
vector operator ++(int)
{
vector temp;
*temp.x = (*x)++;
*temp.y = (*y)++;
*temp.z = (*z)++;
return temp;
}
vector operator --()
{
--(*x);
--(*y);
--(*z);
return *this;
}
vector operator --(int)
{
vector temp;
*temp.x = (*x)--;
*temp.y = (*y)--;
*temp.z = (*z)--;
return temp;
}
float len()
{
float t;
t = float(sqrt((*x * (*x)) + (*y * (*y)) + (*z * (*z))));
return t;
}
float Angle(vector& a)
{
float t;
float dot;
dot = (*this * a);
t = acos((dot) / ((this->len()) * a.len()));
return t;
}
float operator*(const vector& c)
{
float t;
t = (*x * (*c.x)) + (*y * (*c.y)) + (*z * (*c.z));
return t;
}
friend bool operator ==(const vector& c1, const vector& c2);
friend bool operator !=(const vector& c1, const vector& c2);
friend bool operator <(const vector& c1, const vector& c2);
friend bool operator >(const vector& c1, const vector& c2);
friend ostream& operator <<(ostream& c1, const vector& c2);
friend istream& operator >>(istream& c1, const vector& c2);
};
bool operator==(const vector& c1, const vector& c2)
{
}
bool operator!=(const vector& c1, const vector& c2)
{
}
bool operator<(vector& c1, vector& c2)
{
float len1, len2;
len1 = c1.len();
len2 = c2.len();
if (len1 < len2)
{
return true;
}
else
{
return false;
}
}
bool operator>(vector& c1, vector& c2)
{
float len1, len2;
len1 = c1.len();
len2 = c2.len();
if (len1 > len2)
{
return true;
}
else
{
return false;
}
}
ostream& operator<<(ostream& c1, const vector& c2)
{
cout << *c2.x << "i ";
if (*c2.y >= 0)
{
cout << " + " << *c2.y << "j ";
}
else
{
cout << *c2.y << "j ";
}
if (*c2.z >= 0)
{
cout << " + " << *c2.z << "k ";
}
else
{
cout << *c2.z << "k ";
}
cout << endl;
return c1;
}
istream& operator>>(istream& c1, const vector& c2)
{
cout << endl;
cout << " x-component : ";
cin >> *c2.x;
cout << " y-component : ";
cin >> *c2.y;
cout << " z-component : ";
cin >> *c2.z;
return c1;
}
int main()
{