Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // przeciazanie1.cpp : Defines the entry point for the console application.
- //
- #include <iostream>
- #include "stdafx.h"
- #include <conio.h>
- #include <cstdlib>
- #include <vector>
- #include <algorithm>
- class Wektor
- {
- private:
- float* b;
- int length;
- public:
- Wektor(int n, int m);
- Wektor();
- ~Wektor();
- Wektor(const Wektor &wektor);
- void Wyswietl() const;
- int Dlugosc() const;
- void operator+=(float n);
- void operator~();
- Wektor operator<<(int x);
- Wektor operator>>(int x);
- };
- Wektor::Wektor(int n, int m)
- {
- this->length = n;
- b = new float[n];
- for (int i = 0;i < n;i++)
- {
- b[i] = m;
- }
- }
- Wektor::Wektor()
- {
- this->length = 0;
- b = new float[length];
- }
- Wektor::Wektor(const Wektor &wektor)
- {
- this->length = wektor.length;
- b = new float[wektor.length];
- for (int i = 0;i < wektor.length;i++)
- {
- b[i] = wektor.b[i];
- }
- }
- void Wektor::Wyswietl() const
- {
- printf("[");
- for (int i = 0;i < length;i++)
- {
- printf("%0.2f,", b[i]);
- }
- printf("]");
- }
- int Wektor::Dlugosc() const
- {
- return length;
- }
- Wektor::~Wektor()
- {
- delete[] b;
- }
- void Wektor::operator~()
- {
- int pom = length - 1;
- for (int i = 0;i <length/2;i++)
- {
- std::swap(b[i], b[pom]);
- pom--;
- }
- }
- void Wektor::operator+=(float n)
- {
- float *a;
- a = new float[length+1];
- for (int i = 0;i < length;i++)
- {
- a[i] = b[i];
- }
- a[length] = n;
- this->length = length + 1;
- free(b);
- b = a;
- }
- Wektor Wektor::operator<<(int x)
- {
- float a_tmp = 0;
- for (int i = 0;i < length;i++)
- {
- if (i == x)break;
- a_tmp = b[i];
- b[i] = b[length - i - 1];
- b[length - i - 1] = a_tmp;
- }
- return *this;
- }
- Wektor Wektor::operator>>(int x)
- {
- float a_tmp = 0;
- for (int i = 0;i < length;i++)
- {
- if (i == x)break;
- a_tmp = b[length-i-1];
- b[length - i - 1] = b[i];
- b[i] = a_tmp;
- }
- return *this;
- }
- int main()
- {
- Wektor w1;
- Wektor w2(3, 10);
- printf("{%d} W1: ", w1.Dlugosc());
- w1.Wyswietl();
- printf("\n{%d} W2: ", w2.Dlugosc());
- w2.Wyswietl();
- Wektor w3 = w2;
- w3 += 1.0;
- w3 += 2.10;
- w3 += 2.11;
- w3 += 2.13;
- w3 += 5.18;
- printf("\n{%d} W3: ", w3.Dlugosc());
- w3.Wyswietl();
- w3 >> 3;
- printf("\n{%d} W3: <<", w3.Dlugosc());
- w3.Wyswietl();
- w3 << 3;
- printf("\n{%d} W3 >>: ", w3.Dlugosc());
- w3.Wyswietl();
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement