Shablon funksiyalar yordamida
3
|
16
|
LO7
|
|
A
|
Ma'lumot turini parametr sifatida jo'natish orqali algoritmni u ishlaydigan konkret ma'lumot turlaridan ajratib olish mumkin
|
|
|
|
|
B
|
Bir nechta shablon sinflariga ega bolish mumkin
|
|
|
|
|
C
|
Funksiyani u ishlayotkan aniq sinf tipidan ajratib olish mumkin
|
|
|
|
|
D
|
Bir nechta bazaviy sinflarni ta’minlash mumkin
|
|
|
|
182
|
|
Shablonlardan foydalanish afzalliklari shundaki—
|
3
|
17
|
LO7
|
|
A
|
O’zgaruvchilar bilan ishlash algoritmi aniqlangan va tayyorlangan bo’lsa, u kodni o’zgartirmagan holda xar qanaqa turdagi (tipdagi) o’zgaruvchisiga nisbatan qo’llanilishi
|
|
|
|
|
B
|
U qandaydir tashkil etilgan o’zgaruvchilarni saqlash va ular bilan ishlash uchun mo’ljallanganligi
|
|
|
|
|
C
|
U qandaydir tashkil etilgan o’zgaruvchilarni vizuallashtirishga mo’ljallangan
|
|
|
|
|
D
|
Xar qanday tip o’zgaruvchisiga nisbatan kodni qayta yuklash orqali qo’llanilishi mumkin
|
|
|
|
183
|
|
Shablonlar qanday turlarga bo’linadi?
|
3
|
16
|
LO7
|
|
A
|
Sinf shabloni, funksiya shabloni
|
|
|
|
|
B
|
Template shabloni, sinf shabloni
|
|
|
|
|
C
|
Template shabloni, class shabloni
|
|
|
|
|
D
|
Funksiya shabloni, protsedura shabloni
|
|
|
|
184
|
|
Funksiya shabloni bilan Funksiyani qayta yuklash o’rtasidagi farq nimada?
|
3
|
17
|
LO7
|
|
A
|
funksiya shablonlarida amal ham bir hil yo'l bilan bajariladi
|
|
|
|
|
B
|
funksiya shablonlarida amal turli hil yo'l bilan bajariladi
|
|
|
|
|
C
|
funksiya shablonlarida hech qanday amal bajarilmaydi
|
|
|
|
|
D
|
farq yo’q
|
|
|
|
185
|
|
Funksiya Shabloni e'loni va aniqlanishidan oldin …. . . . . . . . ifodasi yoziladi.
|
3
|
16
|
LO7
|
|
A
|
template <>
|
|
|
|
|
B
|
template ()
|
|
|
|
|
C
|
template {}
|
|
|
|
|
D
|
Tamplete ()
|
|
|
|
186
|
|
Funksiya shablonida <> qavslar ichida nimalar beriladi?
|
3
|
17
|
LO7
|
|
A
|
funksiya kirish parametrlari, chiqish qiymati va lokal o'zgaruvchilar
|
|
|
|
|
B
|
funksiya chiqish parametrlari, chiqish qiymati va lokal o'zgaruvchilar
|
|
|
|
|
C
|
funksiya kirish parametrlari, kirish qiymati va lokal o'zgaruvchilar
|
|
|
|
|
D
|
funksiya chiqish parametrlari, kirish qiymati va lokal o'zgaruvchilar
|
|
|
|
187
|
|
template
T summa(T a, T b) {
return ( a + b);
}
Yuqoridagi misolda T ning o'rniga . . . . . . boshqa identefikator qo'yish mumkin
|
3
|
16
|
LO7
|
|
A
|
Istalgan
|
|
|
|
|
B
|
Butun qiymatli
|
|
|
|
|
C
|
Haqiqiy qiymatli
|
|
|
|
|
D
|
Mantiqiy toifadagi
|
|
|
|
188
|
|
Dastur natijasi qaysi qatorda tog’ri keltirilgan?
#include
using namespace std;
template
void fun(const T&x)
{
static int count = 0;
cout << "x = " << x << " count = " << count << endl;
++count;
return;
}
int main()
{
fun (1);
cout << endl;
fun(1);
cout << endl;
fun(1.1);
cout << endl;
return 0;
}
|
3
|
17
|
LO7
|
|
A
|
x = 1 count = 0
x = 1 count = 1
x = 1.1 count = 0
|
|
|
|
|
B
|
x = 1 count = 0
x = 1 count = 0
x = 1.1 count = 0
|
|
|
|
|
C
|
x = 1 count = 0
x = 1.1 count = 0
x = 1 count = 0
|
|
|
|
|
D
|
Xatolik
|
|
|
|
189
|
|
Dastur natijasi qaysi qatorda tog’ri keltirilgan?
#include
using namespace std;
template
T max(T x, T y)
{
return (x > y)? x : y;
}
int main()
{
cout << max(3, 7) << std::endl;
cout << max(3.0, 7.0) << std::endl;
cout << max(3, 7.0) << std::endl;
return 0;
}
|
3
|
17
|
LO7
|
|
A
|
Xatolik
|
|
|
|
|
B
|
7
7.0
7.0
|
|
|
|
|
C
|
7.0
7
7.0
|
|
|
|
|
D
|
7.0
7.0
3.0
|
|
|
|
190
|
|
Dastur natijasi qaysi qatorda tog’ri keltirilgan?
#include
using namespace std;
template
class Test
{
private:
T val;
public:
static int count;
Test() { count++; }
};
template
int Test::count = 0;
int main()
{
Test a;
Test b;
Test c;
cout << Test::count << endl;
cout << Test::count << endl;
return 0;
}
|
3
|
16
|
LO7
|
|
A
|
2
1
|
|
|
|
|
B
|
1
2
|
|
|
|
|
C
|
0
0
|
|
|
|
|
D
|
1
0
|
|
|
|
191
|
|
Dastur natijasi qaysi qatorda tog’ri keltirilgan?
#include
#include
using namespace std;
template
class A {
T x;
U y;
static int count;
};
int main() {
A a;
A b;
cout << sizeof(a) << endl;
cout << sizeof(b) << endl;
return 0;
}
|
3
|
17
|
LO7
|
|
A
|
2
8
|
|
|
|
|
B
|
8
2
|
|
|
|
|
C
|
4
6
|
|
|
|
|
D
|
6
4
|
|
|
|
192
|
|
Dastur natijasi qaysi qatorda tog’ri keltirilgan?
#include
#include
using namespace std;
template
class A {
T x;
U y;
V z;
static int count;
};
int main()
{
A a;
A b;
cout << sizeof(a) << endl;
cout << sizeof(b) << endl;
return 0;
}
|
3
|
16
|
LO7
|
|
A
|
16
24
|
|
|
|
|
B
|
24
16
|
|
|
|
|
C
|
8
16
|
|
|
|
|
D
|
16
8
|
|
|
|
193
|
|
Dastur natijasi qaysi qatorda tog’ri keltirilgan?
#include
using namespace std;
template
int arrMin(T arr[], int n)
{
int m = max;
for (int i = 0; i < n; i++)
if (arr[i] < m)
m = arr[i];
return m;
}
int main()
{
int arr1[] = {10, 20, 15, 12};
int n1 = sizeof(arr1)/sizeof(arr1[0]);
char arr2[] = {1, 2, 3};
int n2 = sizeof(arr2)/sizeof(arr2[0]);
cout << arrMin(arr1, n1) << endl;
cout << arrMin(arr2, n2);
return 0;
}
|
3
|
17
|
LO7
|
|
A
|
10
1
|
|
|
|
|
B
|
Kompilyatsiyada xatolik
|
|
|
|
|
C
|
12
2
|
|
|
|
|
D
|
2
12
|
|
|
|
194
|
|
Dastur natijasi qaysi qatorda tog’ri keltirilgan?
#include
using namespace std;
template
void fun()
{ i = 20;
cout << i;}
int main()
{ fun<10>();
return 0; }
|
3
|
16
|
LO7
|
|
A
|
Kompilyatsiyada xatolik
|
|
|
|
|
B
|
10
|
|
|
|
|
C
|
20
|
|
|
|
|
D
|
10.20
|
|
|
|
195
|
|
Dastur natijasi qaysi qatorda tog’ri keltirilgan?
#include
using namespace std;
template
T max (T &a, T &b)
{
return (a > b)? a : b;
}
template <>
int max (int &a, int &b)
{
cout << "Called ";
return (a > b)? a : b;
}
int main ()
{
int a = 10, b = 20;
cout << max (a, b);
}
|
3
|
17
|
LO7
|
|
A
|
Called 20
|
|
|
|
|
B
|
Called 10
|
|
|
|
|
C
|
Called 30
|
|
|
|
|
D
|
Kompilyatsiyada xatolik
|
|
|
|
196
|
|
Dastur natijasi qaysi qatorda tog’ri keltirilgan?
#include
using namespace std;
template
T min (T &a, T &b)
{
return (a > b)? a : b;
}
template <>
int min (int &a, int &b)
{
cout << "Called ";
return (a > b)? a : b;
}
int main ()
{
int a = 10, b = 20;
cout << min (a, b);
}
|
3
|
16
|
LO7
|
|
A
|
Called 10
|
|
|
|
|
B
|
Called 20
|
|
|
|
|
C
|
Called 30
|
|
|
|
|
D
|
Kompilyatsiyada xatolik
|
|
|
|
197
|
|
Dastur natijasi qaysi qatorda tog’ri keltirilgan?
#include
using namespace std;
template struct funStruct
{
static const int val = 2*funStruct::val;
};
template<> struct funStruct<0>
{
static const int val = 1 ;
};
int main()
{
cout << funStruct<10>::val << endl;
return 0;
}
|
3
|
17
|
LO7
|
|
A
|
1024
|
|
|
|
|
B
|
Kompilyatsiyada xatolik
|
|
|
|
|
C
|
1
|
|
|
|
|
D
|
2
|
|
|
|
198
|
|
Dastur natijasi qaysi qatorda tog’ri keltirilgan?
#include
using namespace std;
template struct funStruct
{
static const int val = 3*funStruct::val;
};
template<> struct funStruct<0>
{
static const int val = 1 ;
};
int main()
{
cout << funStruct<10>::val << endl;
return 0;
}
|
3
|
16
|
LO7
|
|
A
|
59049
|
|
|
|
|
B
|
Kompilyatsiyada xatolik
|
|
|
|
|
C
|
9
|
|
|
|
|
D
|
3
|
|
|
|
199
|
|
Dastur natijasi qaysi qatorda tog’ri keltirilgan?
#include
using namespace std;
template struct funStruct
{
static const int val = 2*funStruct::val;
};
template<> struct funStruct<0>
{
static const int val = 1 ;
};
int main()
{
cout << funStruct<10>::val << endl;
return 0;
}
|
3
|
17
|
LO7
|
|
A
|
32
|
|
|
|
|
B
|
Kompilyatsiyada xatolik
|
|
|
|
|
C
|
1024
|
|
|
|
|
D
|
16
|
|
|
|
200
|
|
Dastur natijasi qaysi qatorda tog’ri keltirilgan?
#include
using namespace std;
template
int arrMin(T arr[], int n)
{
int m = max;
for (int i = 0; i < n; i++)
if (arr[i] < m)
m = arr[i];
return m;
}
int main()
{
int arr1[] = {11, 20, 15, 12};
int n1 = sizeof(arr1)/sizeof(arr1[0]);
char arr2[] = {5, 2, 3};
int n2 = sizeof(arr2)/sizeof(arr2[0]);
cout << arrMin(arr1, n1) << endl;
cout << arrMin(arr2, n2);
return 0;
}
|
3
|
17
|
LO7
|
|
A
|
11
2
|
|
|
|
|
B
|
2
11
|
|
|
|
|
C
|
3
2
|
|
|
|
|
D
|
2
3
|
|
|
|
201
|
|
10>0>10>0>10>0>10> |