Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <iostream>
- #include <time.h>
- using namespace std;
- template <typename T>
- class MyVector {
- private:
- vector <T> arr;
- double Radius;
- int Size_ = arr.size();
- public:
- MyVector(double r, T v0) {Radius=r; arr.push_back(v0);}
- //MyVector(){Radius=50; arr[0]=0;}
- int Size (){ return Size_;}
- void Clear (){arr.clear(); Size_=0;}
- //void Swap(MyVector v){arr.swap(v.arr);}
- T operator[](int i){ return arr[i];}
- template <typename T2>
- friend void Swap (MyVector<T2> v1, MyVector<T2> v2);
- template <typename T1>
- friend ostream& operator<<(ostream& os, MyVector<T1>& v);
- friend double random();
- void Start();
- };
- template <typename T2>
- void Swap (MyVector<T2> v1, MyVector<T2> v2){
- v1.arr.swap(v2.arr);
- }
- double random(){
- double m=RAND_MAX;
- return 10*rand()/m;}
- template <typename T>
- void MyVector<T>::Start()
- { int i=0;
- while (abs(arr[i]-arr[0])<Radius)
- {
- i++;
- arr.push_back(arr[i-1] + random());
- }
- Size_ = arr.size();
- };
- template <typename T1>
- ostream& operator<<(ostream& os, MyVector<T1>& v)
- {for (int it = 0 ; it < v.arr.size(); it++)
- { os << v.arr[it] << " ";}
- os<<endl;
- return os;
- }
- int main (){
- srand(time(0));
- MyVector<int> v1 (100, 1);
- MyVector<int> v2(100,0);
- v1.Start();
- v2.Start();
- cout<<v1.Size()<<" "<<v2.Size()<<endl;
- cout<<v1<<v2;
- Swap(v2, v1);
- cout<<v1<<v2;
- v1.Clear();
- v2.Clear();
- cout<<v1.Size()<<" "<<v2.Size()<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement