Advertisement
limun11

genericke

Jul 11th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int kvadrirajINT(int broj)
  5. {
  6.     return broj*broj;
  7. }
  8. float kvadrirajFLOAT(float broj)
  9. {
  10.     return broj*broj;
  11. }
  12. double kvadrirdajDOUBLE(double broj)
  13. {
  14.     return broj*broj;
  15. }
  16. void main()
  17. {
  18.     int broj = 5;
  19.     float brojF = 5.55;
  20.     double brojD = 6.78;
  21.     cout << "int: " << kvadrirajINT(broj) << endl;
  22.     cout << "float: " << kvadrirajFLOAT(brojF) << endl;
  23.     cout << "double: "<<kvadrirdajDOUBLE(brojD)<<endl;
  24.     system("PAUSE");
  25. }
  26. ///////////////////////////////////////////////////////////////////////////////////////
  27. #include <iostream>
  28. using namespace std;
  29.  
  30. template <class T>
  31. T kvadriraj(T broj)
  32. {
  33.     return broj*broj;
  34. }
  35.  
  36. void main()
  37. {
  38.     cout << "int: " << kvadriraj(5) << endl;
  39.     cout << "int: " << kvadriraj <int>(5) << endl;
  40.     cout << "float: " << kvadriraj(5.5) << endl;
  41.     cout << "float: " << kvadriraj<float>(5.5) << endl;
  42.     system("PAUSE");
  43. }
  44. ///////////////////////////////////////////////////////////////////////////////////
  45. #include <iostream>
  46. using namespace std;
  47.  
  48. template <class t1, class t2>
  49. t1 saberi(t1 broj1, t2 broj2)
  50. {
  51.     return broj1 + broj2;
  52. }
  53.  
  54. void main()
  55. {
  56.     cout << "int + float: " << saberi(4, 5.5) << endl;
  57.     cout << "float + int: " << saberi(5.5, 4) << endl;
  58.  
  59.     system("PAUSE");
  60. }
  61. /////////////////////////////////////////////////////////////////////
  62. #include <iostream>
  63. using namespace std;
  64.  
  65. template<class Tip>
  66. void Zamijeni(Tip & broj1, Tip & broj2) {
  67.     Tip temp = broj1;
  68.     broj1 = broj2;
  69.     broj2 = temp;
  70. }
  71. void main() {
  72.     int a = 4, b = 20;
  73.     float c = 14.2, d = 5.4;
  74.     Zamijeni(a, b);
  75.     Zamijeni(c, d);
  76.     cout << "a = " << a << " b = " << b << endl;
  77.     cout << "c = " << c << " d = " << d << endl;
  78.  
  79. system("PAUSE");
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement