fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. namespace ALL_Vector {
  9.  
  10. class Vector {
  11. public:
  12. // Intitialize elem and sz before the actual function
  13. Vector(int size) :elem {new double[size]}, sz {size} {};
  14. ~Vector() {delete[] elem;};
  15.  
  16. double& operator[](int i) {
  17. return elem[i];
  18. };
  19. int size() {return sz;};
  20. private:
  21. double* elem;
  22. int sz;
  23. };
  24.  
  25.  
  26. void print_product(Vector& y) {
  27. double result {1};
  28.  
  29. for (auto x = 0; x < y.size() ; x++){
  30. if (y[x] > 0) {result *= y[x]; };
  31. }
  32.  
  33. cout << "The product of Vector y is: " << result << ", or so it would appear ;)\n";
  34. }
  35.  
  36. }
  37.  
  38.  
  39. /*
  40.   Self test of the Vector class.
  41. */
  42.  
  43. int main(){
  44. ALL_Vector::Vector myVector(15);
  45. cout << "The size of Vector y is: " << myVector.size() << "\n";
  46. myVector[0] = 12;
  47. myVector[2] = 7;
  48. myVector[3] = 19;
  49. myVector[4] = 2;
  50.  
  51. ALL_Vector::print_product(myVector);
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
The size of Vector y is: 15
The product of Vector y is: 3192, or so it would appear ;)