Muhammad al-Xorazmiy nomidagi
Toshkent Axborot Texnologiyalari Universitetining
Dasturiy injenering fakulteti
312-21
-guruh talabasi
Qilichev Abbosbek
ning
Mobil ilovalarni ishlab chiqish fani
2-AMALIY ISHI
Bajardi: Qilichev Abbosbek
Tekshirdi: Achilov Baxodir
Toshkent 2024-yil
1-masala.
14.
B soni va 10 ta butun sondan tashkil topgan musbat sonlar to'plami berilgan. Shu to'plamda B sonidan
katta bo'lgan, eng kichik elementni tartib raqamini chiqaruvchi programma tuzilsin. Agar berilgan
to'plamda B sonidan katta son topilmasa, ikkita 0 chiqarilsin.
Dart
void main() {
List sonlar = [3, 7, 12, 5, 20, 8, 15, 25, 30, 10];
int B = 10;
int engKichikIndex = tap(sonlar, B);
if (engKichikIndex != -1) {
print("Eng kichik element tartib raqami: ${engKichikIndex + 1}");
} else {
print("Ikkita 0 chiqarildi.");
}
}
int tap(List sonlar, int B) {
int engKichikIndex = -1;
int engKichikSon = 999999; // Bundan kichik son topilmaydi
for (int i = 0; i < sonlar.length; i++) {
if (sonlar[i] < engKichikSon && sonlar[i] > B) {
engKichikSon = sonlar[i];
engKichikIndex = i;
}
}
return engKichikIndex;
}
Python
def b_kattasi_index(sonlar, B):
# Eng kichik sonning tartib raqamini aniqlash uchun indekslarni hisoblaymiz
eng_kichik_index = None
eng_kichik_son = float('inf') # Boshlang'ich qiymat eng katta sonlar ro'yxati ichida bo'lishi kerak
for i, son in enumerate(sonlar):
if son < eng_kichik_son and son > B:
eng_kichik_son = son
eng_kichik_index = i
return eng_kichik_index if eng_kichik_index is not None else (0, 0)
# Test ma'lumotlari
sonlar = [3, 7, 12, 5, 20, 8, 15, 25, 30, 10]
B = 10
# Natijani chiqarish
result = b_kattasi_index(sonlar, B)
if isinstance(result, int):
print("Eng kichik element tartib raqami:", result + 1) # Tartib raqamlari 1 dan boshlanadi
else:
print("Ikkita 0 chiqarildi.")
2-masala.
14.O'ngga siklik siljishni amalga oshiruvchi ShiftRight3(A, B, C) funksiyasini hosil qiling. Ya'ni A ning
qiymati B ga, B ning qiymati C ga, C ning qiymati A ga o'tib qolsin. Bu funksiya orqali (A1, B1, C1) va
(A2, B2, C2) sonlarini siljiting.
Dart
void main() {
// Funksiya chaqirilishidan oldin qiymatlar
int A1 = 1, B1 = 2, C1 = 3;
int A2 = 4, B2 = 5, C2 = 6;
print('Siljitishdan oldin:');
print('A1: $A1, B1: $B1, C1: $C1');
print('A2: $A2, B2: $B2, C2: $C2');
// ShiftRight3 funksiyasi chaqirilishi
var result1 = ShiftRight3(A1, B1, C1);
var result2 = ShiftRight3(A2, B2, C2);
// Natijalarni chiqarish
print('Siljitishdan keyin:');
print('A1: ${result1[0]}, B1: ${result1[1]}, C1: ${result1[2]}');
print('A2: ${result2[0]}, B2: ${result2[1]}, C2: ${result2[2]}');
}
// ShiftRight3 funksiyasi
List ShiftRight3(int A, int B, int C) {
int temp = C;
C = B;
B = A;
A = temp;
return [A, B, C];
}
3-masala
14.
OOP:
Class:
Flowers
Dart
class Flowers {
String name;
String color;
double price;
// Klassning konstruktori
Flowers(String name, String color, double price) {
this.name = name;
this.color = color;
this.price = price;
}
// Metodlar
void bloom() {
print("$color rangdagi $name ochdi!");
}
void wither() {
print("$color rangdagi $name solib ketdi...");
}
void showInfo() {
print("[$name] Rangi: $color, Narxi: \$$price");
}
}
void main() {
// 'Flowers' klassidan obyektlar yaratish
Flowers rose = Flowers("Gul", "Qizil", 25.99);
Flowers tulip = Flowers("Lale", "Sariq", 19.99);
// Metodlarni chaqirish
rose.bloom();
tulip.wither();
// Obyekt haqida ma'lumot olish
rose.showInfo();
tulip.showInfo();
}
|