• Ushbu misol qo’shimcha har bir talaba ixtiyoriy bittasini ishlasin.
  • 2-topshiriq. Structga doir(classda ham ishlanglar).
  • Gurux: prg-005 Bajardi: Tursunboyeva Aziza Tekshirdi: Shobdarov Elbek




    Download 10,58 Mb.
    Sana18.05.2024
    Hajmi10,58 Mb.
    #241280
    Bog'liq
    Dasturlash 5-topshiriq


    O‘zbekiston Respublikasi axborot texnologiyalari va kommunikatsiyalarini
    rivojlantirish vazirligi Muhammad al-Xorazmiy nomidagi Toshkent
    axborot texnologiyalari universiteti

    5-Amaliy ishi


    Gurux:PRG-005
    Bajardi: Tursunboyeva Aziza
    Tekshirdi: Shobdarov Elbek


    1. topshiriq: Fayl, oxirida qo’shimcha misol mavjud faylga.


    #include
    #include
    #include
    #include
    int main() {
    std::ofstream file("matn_fayli.txt");
    std::string matn;
    std::cout << "Matn kiriting (Ctrl+D yoki Ctrl+Z tugmalarini bosing to'xtash uchun):" << std::endl;
    std::ostringstream oss;
    oss << std::cin.rdbuf();
    matn = oss.str();
    file << matn;
    file.close();
    std::istringstream iss(matn);
    std::string soz;
    std::string eng_uzun_soz;
    size_t uzunlik = 0;
    while (iss >> soz) {
    if (soz.length() > uzunlik) {
    uzunlik = soz.length();
    eng_uzun_soz = soz;
    }
    }
    std::cout << "Eng uzun so'z: " << eng_uzun_soz << std::endl;
    std::cout << "Uzunlik: " << uzunlik << " belgi" << std::endl;
    return 0;
    }


    Ushbu misol qo’shimcha har bir talaba ixtiyoriy bittasini ishlasin.

    #include
    #include
    #include
    using namespace std;
    int main() {
    const char* faylNom = "talaba.txt";
    ifstream fayl(faylNom);
    if (!fayl.is_open()) {
    cerr << "Xatolik: Faylni ochib bo'lmadi." << endl;
    return 1;
    }
    string qidirilayotganFamiliya;
    cout << "Qidirilayotgan talaba familiyasini kiriting: ";
    getline(cin, qidirilayotganFamiliya);

    string qator;


    bool topildi = false;
    while (getline(fayl, qator)) {
    size_t pozitsiya = qator.find(qidirilayotganFamiliya);
    if (pozitsiya != string::npos) {
    cout << "Talaba topildi: " << qator << endl;
    topildi = true;
    break;
    }
    }
    if (!topildi) {
    cout << "Uzr, talaba topilmadi." << endl;
    }
    fayl.close();
    return 0;
    }

    2-topshiriq. Structga doir(classda ham ishlanglar).

    #include
    #include
    #include
    struct Oquvchi {
    std::string familiya;
    std::string ism;
    int tugilganYil;
    std::string tugilganOy;
    int tugilganKun;
    };
    int main() {
    std::vector oquvchilar = {
    {"Ismoilov", "Ismoil", 2000, "Mart", 15},
    {"Aliyev", "Ali", 2001, "Fevral", 20},
    };
    std::cout << std::setw(15) << "Familiya" << std::setw(15) << " Ism" << std::setw(15) << "Tug'ilgan Yil" << std::setw(15) << "Tug'ilgan Oy" << std::setw(15) << "Tug'ilgan Kun" << std::endl;
    std::cout << "----------------------------------------------" << std::endl;
    for (const auto& oquvchi : oquvchilar) {
    std::cout << std::setw(15) << oquvchi.familiya
    << std::setw(15) << oquvchi.ism
    << std::setw(15) << oquvchi.tugilganYil
    << std::setw(15) << oquvchi.tugilganOy
    << std::setw(15) << oquvchi.tugilganKun
    << std::endl;
    }

    return 0;


    }

    1-Amaliy ishi










    1. Amaliy ishi






    1. Amaliy ishi


    4-Amaliy ishi



    1. Misol:



    #include
    using namespace std;

    void checkCharacter(char c) {


    if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
    cout << "Bu harf belgi" << endl;
    } else if (c >= '0' && c <= '9') {
    cout << "Bu son belgi" << endl;
    } else {
    cout << "Bu oddiy belgi" << endl;
    }
    }

    int main() {


    char input;
    cout << "Bir belgi kiriting: ";
    cin >> input;
    checkCharacter(input);
    return 0;


    1. Misol:




    #include
    #include

    int main() {


    std::string A = "String turidagi A satrning toq uzunlikdagi soʻzlarini B satrga, soʻng juft uzunlikdagi soʻzlarni C satrga joylashtiruvchi dastur";
    std::string B, C;
    for (int i = 0; i < A.length(); ++i) {
    std::string word;
    while (A[i] != ' ' && i < A.length()) {
    word += A[i];
    ++i;
    }
    if (word.length() % 2 == 1) {
    B += word + ' ';
    } else {
    C += word + ' ';
    }
    }
    std::cout << "B satr: " << B << std::endl;
    std::cout << "C satr: " << C << std::endl;
    return 0;
    }

    Download 10,58 Mb.




    Download 10,58 Mb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Gurux: prg-005 Bajardi: Tursunboyeva Aziza Tekshirdi: Shobdarov Elbek

    Download 10,58 Mb.