Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "windows.h"
- #include <string>
- #include <new>
- using namespace std;
- class v3d {
- public:
- double* arr;
- v3d() {
- cout << "Tworzymy... ";
- arr = new double[3];
- cout << this << " gotowe." << endl;
- }
- ~v3d() {
- cout << "Usuwamy... " << this;
- delete[] arr;
- cout << " gotowe." << endl;
- }
- v3d(const v3d& other)
- {
- arr = new double[3];
- arr[0] = other.arr[0];
- arr[1] = other.arr[1];
- arr[2] = other.arr[2];
- }
- v3d operator + (const v3d& other)
- {
- v3d temp;
- temp.arr[0] = arr[0] + other.arr[0];
- temp.arr[1] = arr[1] + other.arr[1];
- temp.arr[2] = arr[2] + other.arr[2];
- return temp;
- }
- v3d& operator += (const v3d& other)
- {
- arr[0] += other.arr[0];
- arr[1] += other.arr[1];
- arr[2] += other.arr[2];
- return *this;
- }
- v3d operator - (const v3d& other)
- {
- v3d temp;
- temp.arr[0] = arr[0] - other.arr[0];
- temp.arr[1] = arr[1] - other.arr[1];
- temp.arr[2] = arr[2] - other.arr[2];
- return temp;
- }
- v3d& operator -= (const v3d& other)
- {
- arr[0] -= other.arr[0];
- arr[1] -= other.arr[1];
- arr[2] -= other.arr[2];
- return *this;
- }
- v3d operator * (const v3d& other)
- {
- v3d temp;
- temp.arr[0] = arr[1] * other.arr[2] - arr[2] * other.arr[1];
- temp.arr[1] = arr[2] * other.arr[0] - arr[0] - other.arr[2];
- temp.arr[2] = arr[0] * other.arr[1] - arr[1] - other.arr[0];
- return temp;
- }
- v3d& operator = (const v3d& other)
- {
- if (this != &other)
- {
- arr[0] = other.arr[0];
- arr[1] = other.arr[1];
- arr[2] = other.arr[2];
- }
- return *this;
- }
- double len() {
- return pow(pow(arr[0], 2) + pow(arr[1], 2) + pow(arr[2], 2), 0.5);
- }
- string to_str() {
- return "[" + to_string(arr[0]) + ", " + to_string(arr[1]) + ", " + to_string(arr[2]) + "]";
- }
- };
- int main()
- {
- v3d a, b, sum;
- a.arr[0] = 12;
- a.arr[1] = -56;
- a.arr[2] = 5e-3;
- b.arr[0] = 7 - 3e2;
- b.arr[1] = 24.789;
- b.arr[2] = 1;
- sum = a*b;
- cout << sum.to_str() << endl << sum.len() << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement