Toshkent – 2023 1-Tajriba ishi Malumotlarning oddiy sozlangan turlari



Yüklə 40,06 Kb.
tarix27.12.2023
ölçüsü40,06 Kb.
#199259
Zarifjon


MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI


Malumotlar tuzilmasi va algoritmlari fanidan


1-2-3 – Amaliy topshiriqlar

Bajardi:Ro`ziboyev Zarifjon


Tekshirdi : Bo`riyev Yusuf


Toshkent – 2023
1-Tajriba ishi
Malumotlarning oddiy sozlangan turlari
8-variant
8.Матрицани матрицага кўпайтиринг
2x3 matritsani 3x2 matritsaga ko`paytirish dasturi tuzildi.


Kodi:
#include
#include
using namespace std ;
vector> multiplyMatrices(const vector>& matrix1, const vector>& matrix2) {
if (matrix1[0].size() != matrix2.size()) {
cerr << "Xato: ko'paytirish uchun mos kelmaydigan matritsa o'lchamlari.\n";
return vector>(); }
vector> result(matrix1.size(), vector(matrix2[0].size(), 0));
for (size_t i = 0; i < matrix1.size(); ++i) {
for (size_t j = 0; j < matrix2[0].size(); ++j) {
for (size_t k = 0; k < matrix1[0].size(); ++k) {
result[i][j] += matrix1[i][k] * matrix2[k][j]; } } }
return result;}
int main() {
vector> matrixA = {{1, 2, 3}, {4, 5, 6}};
vector> matrixB = {{7, 8}, {9, 10}, {11, 12}};
vector> resultMatrix = multiplyMatrices(matrixA, matrixB);
cout << "natijaviy matritsa:\n";
for (size_t i = 0; i < resultMatrix.size(); ++i) {
for (size_t j = 0; j < resultMatrix[0].size(); ++j) {
cout << resultMatrix[i][j] << "\t"; }
cout << '\n'; }
return 0;}



2-Tajriba ishi
QIDIRUV USULLARINI TADQIQ QILISH
Topshiriq:
8.Binar qidiruvdan foydalanib massivdan berilgan kalitga karrali kalitli elementni va solishtirishlar sonini toping.


Kodi:
#include
#include
using namespace std;
struct Element {
int key1;
int key2;
Element(int k1, int k2) : key1(k1), key2(k2) {}
};

bool compareElements(const Element& e1, const Element& e2) {


if (e1.key1 < e2.key1)
return true;
else if (e1.key1 > e2.key1)
return false;
return e1.key2 < e2.key2;
}
int binarySearch(const vector& arr, const Element& target, int& comparisons) {
int left = 0;
int right = arr.size() - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (!compareElements(arr[mid], target) && !compareElements(target, arr[mid]))
return mid;
if (compareElements(arr[mid], target))
left = mid + 1;
else
right = mid - 1;

comparisons++;


}
return -1;
}

int main() {


vector elements = {
{1, 10},
{2, 20},
{3, 30},
{4, 40},
};

Element targetElement(3, 30);


int comparisons = 0;
int index = binarySearch(elements, targetElement, comparisons);

if (index != -1) {


cout << "bu element " << index <<"- index da da topildi" << endl;
} else {
cout << "Element mavjud emas" << endl;
}

cout << "Sonlarning solishtirishlari soni: " << comparisons << endl;



return 0;
}





3-Tajriba ishi
MA’LUMOTLARNI SARALASH USULLARINI TADQIQ QILISH
Topshiriq:
8.O‘tgan yildan beri ta’mirlanmagan mashinalarni ularning egalari ismlari bo‘yicha alifbo tartibida joylashtiring.


Kodi:
#include
#include
#include
#include
using namespace std;
struct Car {
string ownerName;
int lastRepairYear;
Car(const string& name, int year) : ownerName(name), lastRepairYear(year) {}
};
bool compareCars(const Car& car1, const Car& car2) {
return car1.ownerName < car2.ownerName;
}
int main() {
vector cars = {
{"Akmal", 2022},
{"Bobur", 2021},
{"Sarvar", 2021},
{"Davron", 2022},
};
vector unrepairedCars;
int currentYear = 2023;

for (const auto& car : cars) {
if (car.lastRepairYear < currentYear) {
unrepairedCars.push_back(car);
}
}
sort(unrepairedCars.begin(), unrepairedCars.end(), compareCars);
cout << "Oxirgi yildan beri tuzatilmagan mashinalar:" << endl;
for (const auto& car : unrepairedCars) {
cout << "Ega: " << car.ownerName << ", Oxirgi tuzatilgan yili: " << car.lastRepairYear << endl;
}
return 0;
}


Yüklə 40,06 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin