Toshkent axborot texnologiyalari universiteti mustaqil ish




Download 104,69 Kb.
Sana21.05.2024
Hajmi104,69 Kb.
#247621
Bog'liq
4- ish dasturlash






MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI
UNIVERSITETI

MUSTAQIL ISH


Guruh:530-23.
Bajardi: Safarov Sunnatillo
Tekshirdi: Ishniyozov Odil

1.Har – xil turdagi to’plamlar berilgan. Agar to’plam double turida bo’lsa, uning elementlarini fibonachchi sonlari bilan to’ldiruvchi, agar to’plam string turida bo’lsa, uning “anaqa” qiymatli elementlarini o’chiruvchi funksiya shablonini tuzing.

#include
#include
#include
#include

int fibonacci(int n) {


if (n <= 1)
return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}

template


std::vector fill_with_fibonacci(const std::vector& arr) {
std::vector result;
for (const auto& elem : arr) {
if (std::is_same::value) {
result.push_back(fibonacci(static_cast(elem)));
} else {
result.push_back(elem);
}
}
return result;
}

template<>


std::vector fill_with_fibonacci(const std::vector& arr) {
std::vector result;
for (const auto& elem : arr) {
if (elem != "aniq") {
result.push_back(elem);
}
}
return result;
}

int main() {


std::vector double_array = {1.0, 2.0, 3.0, 4.0, 5.0};
std::vector string_array = {"aniq", "element", "aniq", "to'plam", "aniq"};

auto filled_double_array = fill_with_fibonacci(double_array);


std::cout << "Double to'plam: ";
for (const auto& elem : filled_double_array) {
std::cout << elem << " ";
}
std::cout << std::endl;

auto filled_string_array = fill_with_fibonacci(string_array);


std::cout << "String to'plam: ";
for (const auto& elem : filled_string_array) {
std::cout << elem << " ";
}
std::cout << std::endl;

return 0;


}

2.last_manfiy_at() funksiya yarating. Array konteyneri oxirgi manfiy son indexini topsin.

#include
#include

int last_negative_at(const std::vector& arr) {


int last_negative_index = -1;
for (int i = 0; i < arr.size(); ++i) {
if (arr[i] < 0) {
last_negative_index = i;
}
}
return last_negative_index;
}

int main() {


std::vector numbers = {5, -3, 8, 0, -2, -7, 10};

int last_negative_index = last_negative_at(numbers);

if (last_negative_index != -1) {
std::cout << "Oxirgi manfiy son indexi: " << last_negative_index << std::endl;
} else {
std::cout << "Arrayda manfiy son yo'q" << std::endl;
}

return 0;


}
3.Array konteyneri yarating. Unda Inson ma’lumotlari(ismi, familiyasi, yili) bo’lsin. Berilgan array massivini yarating va ma’lumotlarni familiya bo’yicha saralang.
#include
#include
#include
class Person {
public:
std::string name;
std::string surname;
int birth_year;

Person(const std::string& n, const std::string& s, int by) : name(n), surname(s), birth_year(by) {}

friend std::ostream& operator<<(std::ostream& os, const Person& person) {
os << person.surname << " " << person.name << " (" << person.birth_year << ")";
return os;
}

static bool sortBySurname(const Person& a, const Person& b) {


return a.surname < b.surname;
}
};

int main() {

std::vector
people = {
{"Jorayev", "Doniyor", 1990},
{"abdullayev", "Sardor", 1985},
{"Boboyev", "Aziz", 1988},
{"Muxiddinov", "Shoxrux", 1992}
};

std::sort(people.begin(), people.end(), Person::sortBySurname);


std::cout << "Familiya bo'yicha saralangan Insonlar:" << std::endl;
for (const auto& person : people) {
std::cout << person << std::endl;
}

return 0;


}

Download 104,69 Kb.




Download 104,69 Kb.

Bosh sahifa
Aloqalar

    Bosh sahifa



Toshkent axborot texnologiyalari universiteti mustaqil ish

Download 104,69 Kb.