• 5-savol : 8-misol
  • JAVOBLAR: 1-dasturda nechta global funksiya yaratilgan: Bu dasturda hech qanday global funksiya yaratilmagan. 2-dasturda nechta stack to’plam mavjud
  • 3- Dastur davst.push ("belgi - "+ to_string(int(i))+ to_string(i)); qanday vazifani bajaradi
  • 4- Ikki xil tipdagi stek to‘plam elementlarini almashtirish dastur fragmentini yozing
  • -savol : Dasturda nechta unordered_multiset to‘plam mavjud?




    Download 122,84 Kb.
    bet9/12
    Sana15.05.2024
    Hajmi122,84 Kb.
    #234504
    1   ...   4   5   6   7   8   9   10   11   12
    Bog'liq
    3-mustaqil ish dasturlash Abduganiyev

    4-savol : Dasturda nechta unordered_multiset to‘plam mavjud?


    Javob : Ushbu dasturda 3 ta unordered_multiset to'plam mavjud:

    1. first - unordered_multiset


    2. second - unordered_multiset
    3. third - unordered_multiset

    Bu to'plamlar quyidagi qatorda yaratilgan:


    unordered_multiset< string> first, second, third;


    Shuningdek, dasturda yana 3 ta unordered_set to'plam ham mavjud:

    1. myset - unordered_set


    2. myset_str - unordered_set
    3. myset_one - unordered_set

    Demak, ushbu dasturda jami 6 ta to'plam (3 ta unordered_set va 3 ta unordered_multiset) mavjud.




    5-savol :
    8-misol
    #include
    #include
    #include
    #include
    #include
    #include
    using namespace std;
    int main() {
    stack st, st_one, st_two;
    stack> vst;
    vst.emplace("str1");
    vst.emplace("str2");
    vst.push("eostr");
    for (int i= 0; i < 255; i++)
    {
    vst.push("belgi - " +
    to_string(int(i)) + to_string(i));
    }
    for (int i = 0; i < 50; ++i)
    st.push(i * 15);
    for (int i = 0; i < 105; i++)
    st_one.emplace(i * 10);
    st_two = st;
    st.swap(st_one);
    cout <<
    st.size() << " " <<
    st_one.size() << " " <<
    st_two.size() << " " << vst.size() << endl;
    while (!vst.empty())
    {
    cout <<
    vst.top() << " :
    stack dagi o'rni " << vst.size() << endl;
    vst.pop();
    }
    int size = st.size();
    while (size--) {
    cout << st.top() << " : stack
    dagi o'rni " << st.size() << endl;
    st.pop();
    }
    while(st.size() !=0) {
    cout << st_two.top() << " :
    stack dagi o'rni " << st_two.size()
    << endl;
    st_two.pop();
    }
    while(!st.empty()) {
    cout << st.top() << " : stack
    dagi o'rni " << st.size() << endl;
    st.pop();
    }
    cout <<
    st.size() << " " <<
    st_one.size() << " " <<
    st_two.size() << " " << vst.size() << endl;
    cout << " stack st " << (st.empty() ?
    "" : "not ") << " empty" << endl;
    cout << " stack vst" << (vst.empty()
    ? "" : "not ") << " empty" << endl;
    cout << " stack st_one "
    <<
    (st_one.empty()
    ? "" : "not
    ") << " empty" << endl;
    system("pause");
    return 0;
    }


    JAVOBLAR:
    1-dasturda nechta global funksiya yaratilgan:
    Bu dasturda hech qanday global funksiya yaratilmagan.
    2-dasturda nechta stack to’plam mavjud:
    Jami 4 ta stack mavjud.

    1. stack st


    2. stack st_one
    3. stack st_two
    4. stack> vst
    3- Dastur davst.push ("belgi - "+ to_string(int(i))+ to_string(i)); qanday vazifani bajaradi:
    Ushbu qator vst nomli stack> ga yangi elementlar qo'shadi. Aniqroq aytganda:

    1. to_string(int(i)) - i o'zgaruvchining qiymatini string formatiga o'tkazadi.


    2. to_string(i) - i o'zgaruvchining qiymatini string formatiga o'tkazadi.
    3. "belgi - " + to_string(int(i)) + to_string(i) - "belgi - " satrini i qiymatining string ifodasi bilan birlashtirib yangi satr hosil qiladi.
    4. vst.push("belgi - " + to_string(int(i)) + to_string(i)) - hosil qilingan yangi satrni vst stackiga qo'shadi.
    4- Ikki xil tipdagi stek to‘plam elementlarini almashtirish dastur fragmentini yozing:

    Ikkita har xil tipda bo'lgan stack'larni almashtirish uchun quyidagi kodni yozish mumkin:





    Download 122,84 Kb.
    1   ...   4   5   6   7   8   9   10   11   12




    Download 122,84 Kb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    -savol : Dasturda nechta unordered_multiset to‘plam mavjud?

    Download 122,84 Kb.