SHARE
TWEET

Untitled

a guest Apr 21st, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<vector>
  3.  
  4. using namespace std;
  5.  
  6. class VectorN
  7. {
  8. private:
  9.     int i = 0;
  10.     unsigned int n;
  11.     vector<unsigned int> v;
  12. public:
  13.     VectorN(unsigned int n){
  14.         v.resize(n);
  15.     };
  16.  
  17.     ~VectorN(){
  18.  
  19.     };
  20.     unsigned getSize() const{
  21.          return v.size();
  22.     };
  23.  
  24.     int getValue(unsigned int i) const{
  25.         return v[i];
  26.     };
  27.  
  28.     void setValue(unsigned int i, int value){
  29.         v[i] = value;
  30.     };
  31.  
  32.     bool operator == (const VectorN& v2){
  33.         for (i = 0; i < v.size() ; i++)
  34.             if (this->v[i]!= v2.v[i]) {return false;}
  35.         return true;
  36.     };
  37.  
  38.     bool operator != (const VectorN& v2){
  39.         for (i = 0; i < v.size() ; i++)
  40.             if (this->v[i] != v2.v[i]) {return true;}
  41.         return false;
  42.     };
  43.  
  44.     VectorN operator+ (const VectorN& v2){
  45.         VectorN v3(this->n);
  46.         for (int i=0;i<this->n;i++){
  47.             v3.v[i] = this->v[i] + v2.v[i];
  48.         }
  49.         return v3;
  50.     }
  51. };
  52. VectorN operator *(const VectorN &vec, double c) {
  53.     VectorN v1(vec.n);
  54.     for (int i = 0; i<vec.getSize();i++){
  55.         v1.v[i]=vec.v[i]*c;
  56.     }
  57.     return v1;
  58. }
  59.  
  60. VectorN operator *(double c, const VectorN &vec){
  61.     return vec*c;
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top