Advertisement
Guest User

simplevektor2

a guest
May 25th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "SimpleVektor.h"
  3.  
  4. std::ostream& operator<<(std::ostream& os, const SimpleVektor& rhs) {
  5.  
  6.     os << "V[" << rhs.len << "]";
  7.     for (int i = 0; i < rhs.len; i++)
  8.     {
  9.         os << rhs.daten[i];
  10.         if (i < rhs.len - 1) os << ", ";
  11.     }
  12.     return os;
  13. }
  14.  
  15. SimpleVektor::SimpleVektor()
  16. {
  17.     len = 1;
  18.     int *daten = new int[1];
  19.     daten[0] = 0;
  20. }
  21.  
  22. SimpleVektor::SimpleVektor(int n)
  23. {
  24.     len = n;
  25.     int *daten = new int[len];
  26.     for (int i = 0; i < len; i++)
  27.     {
  28.         daten[i] = 0;
  29.     }
  30. }
  31.  
  32. SimpleVektor::SimpleVektor(const SimpleVektor &v)
  33. {
  34.     len = v.len;
  35.     int *daten = new int[len];
  36.     for (int i = 0; i < len; i++)
  37.     {
  38.         daten[i] = v.daten[i];
  39.     }
  40. }
  41.  
  42. void SimpleVektor::operator<<=(int nval)
  43. {
  44.     for (int i = 0; i < len; i++)
  45.     {
  46.         daten[i] = nval;
  47.     }
  48. }
  49.  
  50. void SimpleVektor::operator+=(int nval)
  51. {
  52.     for (int i = 0; i < len; i++)
  53.     {
  54.         daten[i] += nval;
  55.     }
  56. }
  57.  
  58. bool SimpleVektor::operator<(const SimpleVektor &v)
  59. {
  60.     return len < v.len;
  61.  
  62. }
  63.  
  64. void SimpleVektor::operator=(const SimpleVektor &rhs)
  65. {
  66.     delete[] daten;
  67.     this->len = rhs.len;
  68.     int *daten = new int[this->len];
  69.     for (int i = 0; i < this->len; i++)
  70.     {
  71.         this->daten[i] = rhs.daten[i];
  72.     }
  73. }
  74.  
  75. std::ostream& SimpleVektor::operator<<(std::ostream& os)
  76. {
  77.     os << "V[" << len << "]";
  78.     for (int i = 0; i < len; i++)
  79.     {
  80.         os << daten[i];
  81.         if (i < len - 1) os << ", ";
  82.     }
  83.     return os;
  84. }
  85.  
  86. SimpleVektor::~SimpleVektor()
  87. {
  88.     delete[] daten;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement