Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : Defines the entry point for the console application.
- //
- #include <iostream>
- #include "windows.h"
- #include <string>
- using namespace std;
- class v3d {
- public:
- double* arr;
- v3d() {
- cout << "Tworzymy..." << endl;
- arr = (double*)calloc(3, sizeof(double));
- }
- ~v3d() {
- cout << "Przed free: ";
- free(arr);
- cout << " i po free." << endl;
- }
- v3d operator + (const v3d& b)
- {
- v3d temp1;
- temp1.arr[0] = arr[0] + b.arr[0];
- temp1.arr[1] = arr[1] + b.arr[1];
- temp1.arr[2] = arr[2] + b.arr[2];
- return temp1;
- }
- v3d& operator += (const v3d& b)
- {
- arr[0] += b.arr[0];
- arr[1] += b.arr[1];
- arr[2] += b.arr[2];
- return *this;
- }
- v3d& operator -= (const v3d& b)
- {
- arr[0] -= b.arr[0];
- arr[1] -= b.arr[1];
- arr[2] -= b.arr[2];
- return *this;
- }
- v3d& operator = (const v3d& b)
- {
- this->arr[0] = b.arr[0];
- this->arr[1] = b.arr[1];
- this->arr[2] = b.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] = 0;
- a -= b;
- 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