Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Vector Vector::operator+(const Vector & v1)
- {
- Vector result;
- result.x = this->x + v1.x;
- result.y = this->y + v1.y;
- result.z = this->z + v1.z;
- return result;
- }
- int Vector::operator*(const Vector & v1)
- {
- float result;
- result = (this->x)*v1.get_x() + (this->y)*v1.get_y() + (this->z)*v1.get_z();
- return result;
- }
- float Vector::get_x() const
- {
- return this->x;
- }
- float Vector::get_y() const
- {
- return this->y;
- }
- float Vector::get_z() const
- {
- return this->z;
- }
- Vector::Vector(float _x, float _y, float _z)
- {
- this->x = _x;
- this->y = _y;
- this->z = _z;
- }
- const int value = 0;
- Vector::Vector():x(value),y(value),z(value)
- {
- ;
- }
- Vector Vector::operator-(const Vector & v1)
- {
- Vector result;
- result.x = this->x - v1.x;
- result.y = this->y - v1.y;
- result.z = this->z - v1.z;
- return result;
- }
- Vector Vector::operator*(const int scalar)
- {
- Vector result;
- result.x = this->x*scalar;
- result.y = this->y*scalar;
- result.z = this->z*scalar;
- return result;
- }
- void Vector:: print() const
- {
- std::cout << "(" << this->x << "," << this->y << "," << this->z << ")" << std::endl;
- }
- void Vector::setter(float x, float y, float z)
- {
- this->x = x;
- this->y = y;
- this->z = z;
- }
- std::istream & operator>>(std::istream & is, Vector& v1)
- {
- //float x, y, z;
- //is >> x >> y >> z;
- //v1.setter(v1.x, v1.y, v1.z);
- //std::cout <<std::endl;
- return is >> v1.x >> v1.y >> v1.z;
- }
- std::ostream & operator<<(std::ostream & os, const Vector& v1)
- {
- os << "(" << v1.x << "," << v1.y << "," << v1.z << ")";
- std::cout<<std::endl;
- return os;
- }
- //
- //2
- std::istream & operator>>(std::istream & is, Matrix & m)
- {
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- is >> m.matrix[i][j];
- }
- }
- return is;
- }
- std::ostream & operator<<(std::ostream & os, const Matrix & m)
- {
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- os << m.matrix[i][j] << " ";
- }
- os << std::endl;
- }
- return os;
- }
- Matrix::Matrix()
- {
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- this->matrix[i][j] = 0;
- }
- }
- }
- void Matrix::setter(int i, int j,int number)
- {
- this->matrix[i][j] = number;
- }
- int Matrix::getter(int i, int j) const
- {
- return this->matrix[i][j];
- }
- Matrix Matrix::operator*(int scalar)
- {
- Matrix tmp;
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- tmp.matrix[i][j] = this->matrix[i][j] * scalar;
- }
- }
- return tmp;
- }
- Matrix Matrix::operator*(Matrix another)
- {
- int sum = 0;
- int tmp[3][3];
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- tmp[i][j] = 0;
- for (int k = 0; k < 3; k++)
- {
- tmp[i][j]+= (this->matrix[i][k])*(another.matrix[k][j]);
- }
- }
- }
- Matrix tmpo;
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- tmpo.setter(i, j, tmp[i][j]);
- }
- }
- return tmpo;
- }
- Matrix Matrix::operator++(int number)
- {
- Matrix old = *this;
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- (this->matrix)[i][j]++;
- }
- }
- return old;
- }
- Matrix & Matrix::operator++()
- {
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- (this->matrix)[i][j]++;
- }
- }
- return *this ;
- }
- int Matrix::operator*()
- {
- return (matrix[0][0] * matrix[1][1] * matrix[2][2]);
- }
- Matrix& Matrix::operator!()
- {int tmp= *(*this);
- if (tmp == 0)
- {
- std::cout << "There is no opposite matrix" << std::endl;
- return *this;
- }
- else
- {
- std::cout << "There is an opposite matrix" << std::endl;
- return *this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement