Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int kvadrirajINT(int broj)
- {
- return broj*broj;
- }
- float kvadrirajFLOAT(float broj)
- {
- return broj*broj;
- }
- double kvadrirdajDOUBLE(double broj)
- {
- return broj*broj;
- }
- void main()
- {
- int broj = 5;
- float brojF = 5.55;
- double brojD = 6.78;
- cout << "int: " << kvadrirajINT(broj) << endl;
- cout << "float: " << kvadrirajFLOAT(brojF) << endl;
- cout << "double: "<<kvadrirdajDOUBLE(brojD)<<endl;
- system("PAUSE");
- }
- ///////////////////////////////////////////////////////////////////////////////////////
- #include <iostream>
- using namespace std;
- template <class T>
- T kvadriraj(T broj)
- {
- return broj*broj;
- }
- void main()
- {
- cout << "int: " << kvadriraj(5) << endl;
- cout << "int: " << kvadriraj <int>(5) << endl;
- cout << "float: " << kvadriraj(5.5) << endl;
- cout << "float: " << kvadriraj<float>(5.5) << endl;
- system("PAUSE");
- }
- ///////////////////////////////////////////////////////////////////////////////////
- #include <iostream>
- using namespace std;
- template <class t1, class t2>
- t1 saberi(t1 broj1, t2 broj2)
- {
- return broj1 + broj2;
- }
- void main()
- {
- cout << "int + float: " << saberi(4, 5.5) << endl;
- cout << "float + int: " << saberi(5.5, 4) << endl;
- system("PAUSE");
- }
- /////////////////////////////////////////////////////////////////////
- #include <iostream>
- using namespace std;
- template<class Tip>
- void Zamijeni(Tip & broj1, Tip & broj2) {
- Tip temp = broj1;
- broj1 = broj2;
- broj2 = temp;
- }
- void main() {
- int a = 4, b = 20;
- float c = 14.2, d = 5.4;
- Zamijeni(a, b);
- Zamijeni(c, d);
- cout << "a = " << a << " b = " << b << endl;
- cout << "c = " << c << " d = " << d << endl;
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement