Advertisement
sellmmaahh

popravni-sept-2014-zad2

Jul 30th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdexcept>
  3. #include <vector>
  4.  
  5.  
  6.  
  7. using namespace std;
  8.  
  9. vector<double> Vektorcici (vector<double> A, vector<int> B)
  10. {
  11.     vector<double> C(0);
  12.     for (int i=0; i<B.size(); i++) {
  13.         if (B[i]>A.size()) throw range_error ("Greska.");
  14.     }
  15.     for (int i=0; i<B.size(); i++) {
  16.         C.push_back(A[B[i]]);
  17.     }
  18.     return C;
  19. }
  20. int main () {
  21. vector<double> A{1,6,3,9,45,2,5,7};
  22. vector<int> B{3,5,2,0,5};
  23. try {
  24. vector<double> C{Vektorcici(A,B)};
  25. for (auto x: C) cout<<x<<" ";
  26. }
  27. catch(const char poruka[]) {
  28.     cout<<poruka;
  29. }
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement