5- laboratoriya ishi standart algoritmlar va itеratorlar. Standart algoritmlar. Itеratorlar va ularning qo`llanilishi. Xotirani taqsimlovchilar va ularga qo`yilgan talablar. Standart bo`yicha taqsimlovchi. Ishning maqsadi


Download 19.75 Kb.
Sana19.06.2023
Hajmi19.75 Kb.
#1620555
Bog'liq
Dasturlash 2


O’ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI

MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI

Fan: Dasturlash - 2

AMALIY ISH
Guruh: SWD009-3
Bajardi: Tuychiyeva Maftuna
Tekshirdi: Shobdarov Elbek


Toshkent–2023
5- LABORATORIYA ISHI
Standart algoritmlar va itеratorlar. Standart algoritmlar. Itеratorlar va ularning qo`llanilishi. Xotirani taqsimlovchilar va ularga qo`yilgan talablar. Standart bo`yicha taqsimlovchi.
Ishning maqsadi: C++ dasturlash tilida standart algoritmlar, iteratorlar va xotirani taqsimlovchilar bilan ishlash ko’nikmalarini shakllantirish.

#include
#include
#include
#include
class Student {
public:
std::string name;
std::string surname;
std::string address;
std::string course;
std::string faculty;
double scholarship;

// Konstruktor


Student(const std::string& _name, const std::string& _surname, const std::string& _address,
const std::string& _course, const std::string& _faculty, double _scholarship)
: name(_name), surname(_surname), address(_address), course(_course), faculty(_faculty),
scholarship(_scholarship) {}
};

// Talabalarni stipendiyalar bo'yicha kamayish tartibida saralash uchun komparator funktsiyasi


bool compareByScholarship(const Student& s1, const Student& s2) {
return s1.scholarship > s2.scholarship;
}

int main() {


// Talabalar dekasini yarating
std::deque students;

// Talabalarni dequega qo'shing


students.push_back(Student("Jahon", "Doniyor", "123 Main St", "Computer Science", "Engineering", 5000.0));
students.push_back(Student("Alisa", "Sevinch", "456 Elm St", "Mathematics", "Science", 4500.0));
students.push_back(Student("Emir", "Javohir", "789 Oak St", "Physics", "Science", 5500.0));

// Talabalarni stipendiya bo'yicha kamayish tartibida tartiblang


std::sort(students.begin(), students.end(), compareByScholarship);

// Saralangan talabalarni chop etish


for (const auto& student : students) {
std::cout << "Name: " << student.name << " " << student.surname << std::endl;
std::cout << "Address: " << student.address << std::endl;
std::cout << "Course: " << student.course << std::endl;
std::cout << "Faculty: " << student.faculty << std::endl;
std::cout << "Scholarship: $" << student.scholarship << std::endl;
std::cout << std::endl;
}

return 0;


}



Ma'lumotlar berilgan bo'lsa ham, qaysi funksiyadan foydalanish kerak emasligi sababli kod yozilmaydi. Shuning uchun quyidagi kodda har bir batalyonda nechta askar borligi aniqlanadi va konsolega chiqariladi:
#include
#include
#include
using namespace std;
struct Asker {
string familiya;
string ismi;
string sharfi;
string batalyon;
string lavozim;
};
void askar_soni(vector& askarlar, string batalyon) {
int count = 0;
for (auto& askar : askarlar) {
if (askar.batalyon == batalyon) {
count++; }
}
cout << batalyon << " batalyonda " << count << " ta askar bor.\n";
}
int main() {
vector askarlar = {
{"Ismoilov", "Ismoil", "Kapitan", "Farg'ona", "Komandir"},
{"Aliyev", "Sardor", "Rutbador", "Chirchiq", "Tankchi"},
{"Nazarov", "Shahzod", "Serjant", "Farg'ona", "Topchi"},
{"Abdullayev", "Dostonbek", "Rutbador", "Tashkent", "Strelok"},
{"Qodirov","Nodirbek","Serjant","Chirchiq","Og'ir topchi"}
};
askar_soni(askarlar, "Farg'ona");
askar_soni(askarlar, "Chirchiq");
return 0;
}

Download 19.75 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling