Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. //pierwsze
  6. template <typename T, typename K>
  7. auto add1(T a, K b){
  8. return a+b;
  9. }
  10. //drugie
  11. template <typename T, typename K, typename F>
  12. auto add2(T a, K b, F f ){
  13. return f(a,b);
  14. }
  15. //trzecie
  16. template<class T, int N, T k=0>
  17. class Wektor
  18. {
  19. private:
  20.  
  21. T tab[N];
  22.  
  23. public:
  24.  
  25. T & operator[](int j) {return tab[j];}
  26. const T & operator[](int j) const {return tab[j];}
  27.  
  28.  
  29.  
  30. Wektor()
  31. {
  32. for(int i=0;i<N;i++)
  33. {
  34. tab[i]=k;
  35. cout<< tab[i]<<" ";
  36. }
  37. }
  38. };
  39.  
  40.  
  41. int a1=5, a2=4;
  42. string b1 = "doo", b2 = "sth";
  43. float c1 = 3.14f, c2 = 9.2f;
  44.  
  45. int main()
  46. {
  47. cout << "Pierwsze zadanie"<< endl;
  48. cout << add1(a1, c1) << endl;
  49. cout << add1(b1,b2) << endl;
  50. cout << add1(c1,c2) << endl;
  51. //cout << addsth<string,string>("dd","aaad") << endl;
  52. cout << "\nDrugie zadanie" << endl;
  53. auto fun= [](auto &a, auto&b){
  54. return a+b;
  55. };
  56. cout << add2(a1, c2, fun)<< endl;
  57. cout << add2(b2, b1, fun)<< endl;
  58. cout << "\n Trzecie zadanie"<< endl;
  59. Wektor<int,3,4> wekt;
  60. cout <<'\n';
  61. Wektor<int,5> r;
  62.  
  63.  
  64.  
  65.  
  66. cin.get();
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement