#include <iostream>
using namespace std;
// arelem;
// arsize;
template <class arelem, class arsize>
// ;
arsize find (arelem ar[], arsize size, arelem & element)
{
// ;
arsize ret_pos = -1;
for (long i = 0; i < size; i++)
if (ar[i] == element) {
ret_pos = i;
break;
}
return ret_pos;
}
int main(void)
{
long size;
cin >> size;
double *pinta = new double[size];
for (long i = 0; i < size; i++)
pinta[i] = i;
double value;
cin >> value;
cout << find(pinta, size, value) << endl;
delete[] pinta;
char* str = "string like array";
char ch;
cin >> ch;
cout << find(str, 17, ch) << endl;
return 0;
}
, . , . , .
4.12. .
#include <iostream>
using namespace std;
template <class retype, class atype, class btype>
retype max (atype aval, btype bval)
{
return aval > bval? aval: bval;
}
int main(void)
{
short x = 11;
float y = 11.3;
// double;
// ;
cout << max<double>(x, y) << endl;
return 0;
}
4.5.
, .
4.5.1.
1. ,
2. , .
3. , .
4. , , .
5. , .
6. , .
7. , .
8. , .
9. , .
10. , .
11. , .
12. , .
13. , .
14. , .
15. , .
|
|
16. , .
17. , , .
18. , .
19. , , .
20. , .
4.5.2.
1. , 3.8.1. .
2. , 3.8.2. .
5.
5.1. pair
. utility.
first second. . . make_pair(), .
, . , . && ||. , , false true , , . .
5.1. pair.
#include <iostream>
#include <utility>
#include <string>
using namespace std;
int main (void)
{
// ;
pair<int, string> showPair1(1, "Ivanov"), showPair2;
// make_pair();
showPair2 = make_pair(2, "Petrov");
if (showPair1!= showPair2) {
// ;
pair<int, string> showPair3(showPair1);
cout << showPair3.first << ". " << showPair3.second << endl;
}
cout << (showPair1 > showPair2? showPair1: showPair2).second << endl;
return 0;
}
5.2. complex
complex . <complex>.
: real imag. . real imag .
, , , .
. : (real, imag). : real, (real), (real,imag). .
, , : abs(), arg(), polar(), norm().
|
|