Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- using namespace std;
- template <class T>
- T MaxT( T* tab, int n)
- {
- T temp = tab[0];
- if(n<1||tab==NULL)
- {
- string wyjatek="T MaxT(T*tab, int n):Niepoprawne dane";
- throw wyjatek;
- }
- for(int i=1;i<n;i++){
- if(temp<tab[i]){
- temp=tab[i];
- }
- }
- return temp;
- }
- int main()
- {
- int tabInt[5] = {1,8,3,4,5};
- string tabString[5] = {"Alicja","Marek","Paweł","Zosia","Adam"};
- try{
- cout<<"Maksimum dla liczb całkowitych w tablicy to: ";
- cout<<MaxT<int>(tabInt,5)<<endl<<endl;
- cout<<"Maksimum dla stringow w tablicy to: ";
- cout<<MaxT<string>(tabString,5)<<endl;
- }catch(const char* err){
- cout<<err<<endl;
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement