• Slice sinfi.
  • Tiplarni dinamik tarzda




    Download 1,83 Mb.
    bet53/131
    Sana13.05.2024
    Hajmi1,83 Mb.
    #228405
    1   ...   49   50   51   52   53   54   55   56   ...   131
    Bog'liq
    Tiplarni dinamik tarzda

    cshift() - berilgan son qiymat bo‘yicha indeks asosida massivni aylana shaklida surib yangi massiv qaytaradi. Agar son musbat bo‘lsa chapga suriladi, manfiy bo‘lsa, o‘nga suriladi.
    6.3-dastur. shift() va cshift()dan foydalanish.


    #include "stdafx.h" #include #include using namespace std; int main(){
    int myints[] = { 5, 25, 55, 85, 115 };
    valarray varr (myints, sizeof(myints)/sizeof(myints[0])); valarray varr_one, varr_two;
    cout << "Massivning eski qiymatllar: ";
    for (int &x: varr_one) cout << '\t' << x; cout << endl;

    varr_one = varr.shift(-2);


    cout << "Massivning shift(-2) qiymatllar: "; for (int &x: varr_one) cout << '\t' << x;
    cout << endl;

    varr_one = varr.shift(2);


    cout << "Massivning shift(2) qiymatllar: "; for (int &x: varr_one) cout << '\t' << x;
    cout << endl;

    varr_one = varr.cshift(2);


    cout << "Massivning cshift(2) qiymatllar: "; for (int &x: varr_one) cout << '\t' << x;
    cout << endl;

    varr_one = varr.cshift(-2);


    cout << "Massivning cshift(-2) qiymatllar: "; for (int &x: varr_one) cout << '\t' << x;
    cout << endl;

    system("pause"); return 0;
    }


    6.3-dastur.output

    Massivning eski qiymatllar:
    Massivning shift(-2) qiymatllar: 0 0 5 25 55
    Massivning shift(2) qiymatllar: 55 85 115 0 0
    Massivning cshift(2) qiymatllar: 55 85 115 5 25
    Massivning cshift(-2) qiymatllar: 85 115 5 25 55

    Valarray ning standart amallari




    valarray operator+() const; valarray operator-() const; valarray operator~() const;
    valarray operator!() const;

    Valarray tiplari ustida amallar:


    valarray& operator*= (const valarray& rhs); valarray& operator/= (const valarray& rhs); valarray& operator%= (const valarray& rhs);
    valarray& operator+= (const valarray& rhs);

    valarray& operator-= (const valarray& rhs); valarray& operator^= (const valarray& rhs); valarray& operator&= (const valarray& rhs); valarray& operator|= (const valarray& rhs); valarray& operator<<= (const valarray& rhs);
    valarray& operator>>= (const valarray& rhs);

    Valarray tipi va odatiy oddiy tiplar ustida amallar:

    valarray& operator*= (const T& val); valarray& operator/= (const T& val); valarray& operator%= (const T& val); valarray& operator+= (const T& val); valarray& operator-= (const T& val); valarray& operator^= (const T& val); valarray& operator&= (const T& val); valarray& operator|= (const T& val); valarray& operator<<= (const T& val);
    valarray& operator>>= (const T& val);

    Yuqorida keltirilgan operatorilar Valarray sinfining funksiyalari hisoblandi.
    Valarray tiplari bilan bajariladigan amallarni qayta aniqlash mumkin. Bunda birinchi amal Valarray tipi = Valarray tipi * Valarray tipi, ikkinchi amal Valarray tipi = oddiy tip * Valarray tipi, uchinchi tip Valarray tipi = Valarray tipi* oddiy tip ketma ketligi asosida aniqlangan.
    [*] - amalini qayta aniqlash:


    template valarray operator* (const valarray& lhs, const valarray& rhs);

    template valarray operator* (const T& val, const valarray& rhs);

    template valarray operator* (const valarray& lhs, const T& val);

    [*] - amalini qayta aniqlash:


    template valarray operator* (const valarray& lhs, const valarray& rhs);

    template valarray operator* (const T& val, const valarray& rhs);

    template valarray operator* (const valarray& lhs, const T& val);

    [/] - amalini qayta aniqlash:


    template valarray operator/ (const valarray& lhs, const valarray& rhs);

    template valarray operator/ (const T& val, const valarray& rhs);

    template valarray operator/ (const valarray& lhs, const T& val);

    [%] - amalini qayta aniqlash:

    template valarray operator% (const valarray& lhs, const valarray& rhs);

    template valarray operator% (const T& val, const valarray& rhs);

    template valarray operator% (const valarray& lhs, const T& val);

    [+] - amalini qayta aniqlash:


    template valarray operator+ (const valarray& lhs, const valarray& rhs);

    template valarray operator+ (const T& val, const valarray& rhs);

    template valarray operator+ (const valarray& lhs, const T& val);

    [-] - amalini qayta aniqlash:


    template valarray operator- (const valarray& lhs, const valarray& rhs);

    template valarray operator- (const T& val, const valarray& rhs);

    template valarray operator- (const valarray& lhs, const T& val);

    [^] - amalini qayta aniqlash:


    template valarray operator^ (const valarray& lhs, const valarray& rhs);

    template valarray operator^ (const T& val, const valarray& rhs);

    template valarray operator^ (const valarray& lhs, const T& val);

    [&] – mantiqiy amalini qayta aniqlash:


    template valarray operator& (const valarray& lhs, const valarray& rhs);

    template valarray operator& (const T& val, const valarray& rhs);

    template valarray operator& (const valarray& lhs, const T& val);

    [|] – mantiqiy amalini qayta aniqlash:


    template valarray operator| (const valarray& lhs, const valarray& rhs);

    template valarray operator| (const T& val, const valarray& rhs);

    template valarray operator| (const valarray& lhs, const T& val);

    [<<] – chapga surish amalini qayta aniqlash:


    template valarray operator<< (const valarray& lhs, const valarray& rhs);

    template valarray operator<< (const T& val, const valarray& rhs);

    template valarray operator<< (const valarray& lhs, const T& val);

    [>>] – o‘ngga surish amalini qayta aniqlash:


    template valarray operator>> (const valarray& lhs, const valarray& rhs);

    template valarray operator>> (const T& val, const valarray& rhs);

    template valarray operator>> (const valarray& lhs, const T& val);

    [&&] – tezkor mantiqiy amalini qayta aniqlash:


    template valarray operator&& (const valarray& lhs, const valarray&
    rhs);

    template valarray operator&& (const T& val, const valarray& rhs);

    template valarray operator&& (const valarray& lhs, const T& val);

    [||] – tezkor mantiqiy amalini qayta aniqlash:


    template valarray operator|| (const valarray& lhs, const valarray&
    rhs);

    template valarray operator|| (const T& val, const valarray& rhs);

    template valarray operator|| (const valarray& lhs, const T& val);

    [==] – mulohaza amalini qayta aniqlash:


    template valarray operator== (const valarray& lhs, const valarray&
    rhs);

    template valarray operator== (const T& val, const valarray& rhs);

    template valarray operator== (const valarray& lhs, const T& val);

    [!=] – mulohaza amalini qayta aniqlash:


    template valarray operator!= (const valarray& lhs, const valarray&
    rhs);

    template valarray operator!= (const T& val, const valarray& rhs);

    template valarray operator!= (const valarray& lhs, const T& val);

    [<] – mulohaza amalini qayta aniqlash:


    template valarray operator< (const valarray& lhs, const valarray&
    rhs);

    template valarray operator< (const T& val, const valarray& rhs);

    template valarray operator< (const valarray& lhs, const T& val);

    [>] – mulohaza amalini qayta aniqlash:


    template valarray operator> (const valarray& lhs, const valarray&
    rhs);

    template valarray operator> (const T& val, const valarray& rhs);

    template valarray operator> (const valarray& lhs, const T& val);

    [<=] – mulohaza amalini qayta aniqlash:


    template valarray operator<= (const valarray& lhs, const valarray&
    rhs);

    template valarray operator<= (const T& val, const valarray& rhs);

    template valarray operator<= (const valarray& lhs, const T& val);

    [>=] – mulohaza amalini qayta aniqlash:


    template valarray operator>= (const valarray& lhs, const valarray&
    rhs);

    template valarray operator>= (const T& val, const valarray& rhs);

    template valarray operator>= (const valarray& lhs, const T& val);


    Slice sinfi. Bu - xizmatchi sinf bo‘lib, valarray sinfning merosxo‘ridir va bir o‘lchovli to‘plam ostilarni yaratishda ishlatiladi. Agar valarray massivni ikki o‘lchovli matritsa sifatida qarasak, undan bir o‘lchovli vektorni hosil qilish mumkin.
    Bu sinf slice_array tipdagi obʻyektni tavsiflovchi parametrlarni saqlaydi. Agar to‘plam osti bilvosita yaratilgan valarray sinf tipida bo‘lsa, sinf obʻyekti
    valarray obʻyekti uchun argument sifatida ko‘rsatiladi. To‘plam ostida saqlanadigan qiymatlar valarray tipini oladi va quyidagi xususiyatlarni o‘z ichiga oladi:
    valarraydagi boshlang‘ich indeks.
    massivning umumiy uzunligi va undagi elementlar soni;
    valarray elementlarning ketma-ket indekslari orasidagi qadam yoki masofani aniqlash.
    Agar qism to‘plam yordamida aniqlangan massiv doimiy valarrayning kichik bo‘lagi bo‘lsa, bu massiv yangi valarraydir. Doimiy valarray tipidagi to‘plam bir qism to‘plam yordamida aniqlangan bo‘lsa, dastlabki valarray uchun mos havolalar semantikasidir. O‘zgarmas bo‘lgan valarray lar uchun baholash mexanizmi vaqt va xotira sarflaydi.
    Qism to‘plam asosida aniqlangan bo‘lsa va farqlansa, barcha elementlariga murojaat bo‘lsa, valarray tipidagi massivlar uchun amallar bajarilishi kafolatlanadi. Slice sinfi uchun Slice konstruktori ishlatiladi. Bir-biridan bir xil masofada bo‘lgan va belgilangan element bilan boshlanadigan, bir necha elementlardan
    iborat valarray bir to‘plam ostisini yaratadi.
    Slice sinfining funksiyalari quyidagilar:

    Download 1,83 Mb.
    1   ...   49   50   51   52   53   54   55   56   ...   131




    Download 1,83 Mb.