peregruzka operatorov v yazike programmirovaniya c++

PPTX 44 sahifa 338,6 KB Bepul yuklash

Sahifa ko'rinishi (5 sahifa)

Pastga aylantiring 👇
1 / 44
starshiy prepodavatel kafedri “osnovi informatiki” lektor: sattarov akbar baxtiyarovich starshiy prepodavatel kafedri “osnovi informatiki” lektor: sattarov akbar baxtiyarovich lektsiya №12. peregruzka operatorov. shabloni funktsiy i klassov tashkentskiy universitet informatsionnix texnologiy imeni muxammada al-xorazmiy chto takoe peregruzka operatorov? na yazike programmirovaniya c++ sushestvuet vozmojnost peregruzki operatorov. mi mojem ispolzovat lyubie zadachi nad ob'ektami s pomoshyu operatorov. naprimer: int a, b, c; c = a + b; // tak mojno pisat myclass a,b,c; c = a + b; // v etom sluchai proizoydet oshibka chtobi predotvratit etu situatsiyu neobxodimo peregruzka operatorov! funktsiya operator dlya peregruzki operatorov ispolzuetsya funktsiya pod nazvaniem operator i posle etogo klyuchevogo slovo neobxodimo napisat peregrujaemogo operatora. eta funktsiya operator peregrujaet operatsii mejdu ob'ektami klassa i rabotaet tolko dlya elementov klassa. funktsiya operator ili mojet bit elementom klassa ili ne mojet ispolzovatsya. itak esli funktsiya operator ne yavlyaetsya elementom klassa, to obyazatelno dlya etoy funktsii neobxodimo sozdat klass friend …
2 / 44
latitude = lt; } void show() { cout using namespace std; class distance { private: int feet; // 0 to infinite int inches; // 0 to 12 public: // required constructors distance(){ feet = 0; inches = 0; } distance(int f, int i){ feet = f; inches = i; } // method to display distance void displaydistance() { cout = 60) { ++hours; minutes -= 60; } return time(hours, minutes); } // overloaded postfix ++ operator time operator++( int ) { // save the orignal value time t(hours, minutes); // increment this object ++minutes; if(minutes >= 60) { ++hours; minutes -= 60; } // return old original value return t; } prodoljenie int main() { time t1(11, 59), t2(10,40); ++t1; // increment t1 t1.displaytime(); // display t1 ++t1; // increment t1 again t1.displaytime(); // display t1 t2++; // increment t2 t2.displaytime(); // display t2 t2++; // increment t2 again t2.displaytime(); …
3 / 44
ktsii... template void swapargs(x &a, x &b) { x temp; temp = a; a = b; b = temp; } prodoljenie int main() { int i=10, j=20; double x=10.1, y=23.3; char a='x', b='z'; cout void swapargs(x &a, x &b) { x temp; temp = a; a = b; b = temp; } odnako esli vmesto pervoy i vtoroy stroke napisat drugoy kod, to budet oshibkoy. ispolzovanie lyubogo tipa dlya obobshennoy funktsii. #include using namespace std; template void myfunc(type1 x, type2 y) { cout void swapargs(x &a, x &b) { x temp; temp = a; a = b; b = temp; cout void swapargs (int &a, int &b) { int temp; temp = a; a = b; b = temp; cout using namespace std; // perviy vid shablona funktsii f(). template void f(x a) { cout void f(x a, y b) { cout class nazvanie_klassa{ ... } ili mojno ob'yavit sleduyushim …
4 / 44
out ob1(10, 0.23); myclass ob2('x', "templates add power."); ob1.show(); // show int, double ob2.show(); // show char, char * return 0; } spetsializirovanniy shablon klassa konstruktor template<> ispolzuetsya dlya spetsializirovannogo shablona klassa template class myclass { t x; public: myclass(t a) { cout class myclass { int x; public: myclass(int a) { cout specialization\n"; x = a * a; } int getx() { return x; } }; image2.jpeg image3.png image4.png image5.png image6.png image7.png image8.png image9.png image10.png image11.png image12.png image13.png image14.png image15.png image16.png image17.png /docprops/thumbnail.jpeg
5 / 44
peregruzka operatorov v yazike programmirovaniya c++ - Page 5

Ko'proq o'qimoqchimisiz?

Barcha 44 sahifani Telegram orqali bepul yuklab oling.

To'liq faylni yuklab olish

"peregruzka operatorov v yazike programmirovaniya c++" haqida

starshiy prepodavatel kafedri “osnovi informatiki” lektor: sattarov akbar baxtiyarovich starshiy prepodavatel kafedri “osnovi informatiki” lektor: sattarov akbar baxtiyarovich lektsiya №12. peregruzka operatorov. shabloni funktsiy i klassov tashkentskiy universitet informatsionnix texnologiy imeni muxammada al-xorazmiy chto takoe peregruzka operatorov? na yazike programmirovaniya c++ sushestvuet vozmojnost peregruzki operatorov. mi mojem ispolzovat lyubie zadachi nad ob'ektami s pomoshyu operatorov. naprimer: int a, b, c; c = a + b; // tak mojno pisat myclass a,b,c; c = a + b; // v etom sluchai proizoydet oshibka chtobi predotvratit etu situatsiyu neobxodimo peregruzka operatorov! funktsiya operator dlya peregruzki operatorov ispolzuetsya funktsiya pod nazvaniem operator i posle etogo klyu...

Bu fayl PPTX formatida 44 sahifadan iborat (338,6 KB). "peregruzka operatorov v yazike programmirovaniya c++"ni yuklab olish uchun chap tomondagi Telegram tugmasini bosing.

Teglar: peregruzka operatorov v yazike … PPTX 44 sahifa Bepul yuklash Telegram