• Дастур коди
  • Дастур натижаси
  • Ma’lumotlar tuzilmasi va algoritmlar




    Download 151.06 Kb.
    Sana02.01.2024
    Hajmi151.06 Kb.
    #129561
    Bog'liq
    3-labaratoriya ish
    ттт77, Surayyo nazorat ishi, 13.1 ma\'ruza, 1 amaliy, 1699934324 (1), 3-topshiriq Bajarilish muddati, 8-Ameliy jumis, Arxiv ishi nazariyasi va amalyoti X.A.Buriyev .pdf 2 (1), mustaqil ish 2 semestr, Stansiya va podstansiyalarning elektr qismi, Министрество высшего и среднего образования республики узбекиста, AF5F643D 1097 4329 92AD FBBF30CA2304 5MK0tVA7ogjlOvBmZ prxDqN tMmOvyc, reyting-daftar-351201103311, Doc1


    Muhammad Al-Xorazmiy nomidagi


    Toshkent axborot texnologiyalari universiteti
    “Ma’lumotlar tuzilmasi va algoritmlar”
    3-Labaratoriys ish

    Bajardi:


    3-labaratoriys ish

    Масала № 10


    Г файлнинг компоненталари хакикий сонлардан иборат тупламлар булсин. Хар бир туплам учун мусбат элементлар сонини хисоблаб уларни печатга чикариш ва у файлга ёзиш керак.

    Дастур коди:

    #include


    #include
    #include

    // Туплам турдаги компонентани айирган класс


    class Tuple {
    public:
    int a, b, c;

    Tuple(int a, int b, int c) : a(a), b(b), c(c) {}

    // Мусбат элементлар сонини hisoblash методи
    int countPositive() const {
    int count = 0;
    if (a > 0) count++;
    if (b > 0) count++;
    if (c > 0) count++;
    return count;
    }
    };

    int main() {


    std::ifstream inputFile("input.txt"); // Файл номи
    std::ofstream outputFile("output.txt"); // Натижа учун файлинг номи

    if (!inputFile.is_open()) {


    std::cerr << "File not found or could not be opened." << std::endl;
    return 1;
    }

    int tupleCount; // Тупламлар сони


    inputFile >> tupleCount;

    // Тупламларни ўқиб олиш ва файлга ёзиш


    for (int i = 0; i < tupleCount; ++i) {
    int a, b, c;
    inputFile >> a >> b >> c;

    Tuple tuple(a, b, c);

    // Тупламадаги мусбат элементлар сони
    int positiveCount = tuple.countPositive();

    // Файлга ёзиш


    outputFile << "Tuple " << i + 1 << ": " << positiveCount << " positive elements" << std::endl;
    }

    // Файлларни yopish


    inputFile.close();
    outputFile.close();

    return 0;


    }

    Дастур натижаси:


    Download 151.06 Kb.




    Download 151.06 Kb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Ma’lumotlar tuzilmasi va algoritmlar

    Download 151.06 Kb.