This repository was archived by the owner on Jan 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.cpp
More file actions
50 lines (43 loc) · 1.24 KB
/
program.cpp
File metadata and controls
50 lines (43 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <cstring>
template <typename T>
T maxn(T const ar[],int ile);
template <> const char * maxn(const char * const ar[], int ile);
int main(){
using namespace std;
const int IntSize = 5; const int DoubleSize = 4; const int IleNapisow = 5;
int tablicaInt[IntSize] = {49,17,33,5,2};
double tablicaDouble[DoubleSize] = {87.1,13,19,76.2};
const char * napisy[IleNapisow] = {
"Czesc",
"Jak sie masz kochanie.",
"Napisz szablon funkcji",
"Przetestuj program",
"New Retro Wave"
};
cout << "Maksymalna wartość z tablicy int: ";
cout << maxn(tablicaInt,IntSize) << endl;
cout << "Maksymalna wartość z tablicy double: ";
cout << maxn(tablicaDouble,DoubleSize) << endl;
cout << "Najdłuższy napis z tablicy: ";
cout << maxn(napisy,IleNapisow) << endl;
}
template <typename T>
T maxn(T const ar[],int ile){
T max = ar[0];
for(int i=1;i<ile;i++){
if(ar[i]>max) { max = ar[i]; }
}
return max;
}
template <> const char * maxn(const char * const ar[], int ile){
const char * max = ar[0];
int max_dlugosc = strlen(ar[0]);
for(int i=1;i<ile;i++){
int nowa_dlugosc = strlen(ar[i]);
if(nowa_dlugosc>max_dlugosc){
max = ar[i]; max_dlugosc = nowa_dlugosc;
}
}
return max;
}