cshift() - - Tiplarni dinamik tarzda aniqlash. Reja: Tiplarni dinamik tarzda aniqlash

|
Tiplarni dinamik tarzda aniqlash. Reja: Tiplarni dinamik tarzda aniqlash
|
bet | 59/143 | Sana | 20.07.2024 | Hajmi | 0,81 Mb. | | #268096 |
Bog'liq Tiplarni dinamik tarzda-fayllar.orgcshift() - 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);
|
|
| |