![]() |
|
Программирование >> Расширенная версия языка c++
Приложение В. Ответы на вопросы упражнений 56 х i; Z = k; three d() { X = 0; у = 0; z - 0; } void get (int si, int fij, int ik) i = x; j у; k = z; friend three d operator+ (three dob, int i) ; friend threed operatorr (int i, threed ob) ; threed operator+(three d ob, int i) three d temp; temp.x = ob.x + i; temp.у = cb,y + i; temp, z z + i; return temp; three d operator+ (int i, three d ob) { three d temp; temp . X . X + i ; temp . у . у + i ; temp.z .z + i; . return temp; intmain { ) three dol(10, 10, 10) ; in X, y, z; ol 1 + 10; ol.get(x, y, z) ; iCOUt X: X , Y: << y; cou z \n ; ol = -20 + ol; ol.get (x, y, z) ; cou , y; cou z \n ; return Самоучитель 0++ 8. #include <iostream> using namespace class three d ( int X, y, z; public: three d{int i, int jnt k) x Д , у ] ; z = к; threedO ( x = 0; у 0; z = 0; } void get (int Si, int , int 5k) ( i = x; j = y; k = z; int operator= (three d ob2) ; int operator ! = (three dob2) ; int operator II (three dob2) ; int ob2) return x==ob2.x &S у==оЬ2 . у && z==ob2.z; int ob2) return Ь2.х SS yi=ob2.y ss z!=ob2.z; int ob2) return xob2. ;< 2 у 2 . у 5 S zob2.z ; three dol(10, 10, 10), o2 (2, 3, 41, o3 (0, 0, 0); if(ol==ol) cout ol == ol\n ; if(ol!=o2) cou ol != o2\n ; if(o3l(Ql) cou ol или оЗ равняется истинаХп г return 0; Приложение В. Ответы на вопросы и решения упражнений. 9. Оператор [] обычно перегружается для того, чтобы использовать привычный индексный синтаксис для доступа к элементам инкапсулированного в классе массива. Проверка усвоения материала в целом 1. . В данной программе для простоты не б1л реализован контроль ошибок. Однако в реально функционирующем приложении такой контроль обязателен linclude <iostreaiii> ttinclude <cstring> using namespace std; class strtype ( char s[80J; public: strtype 0 { * \0; } strtype (char *p) (s, p) ; } char *get{) { return s; } strtype operator+(strtype s2) ; . . .. ; strtype s2) int operator<(strtype s2); . in (strtype s2); strtype s2) strtype tp; \: . f . strcpy (temp.s, s) ; strcpy (temp, s, s2.s); ,. . .. return temp; strtype strcpy(s, s2.s); return int { return Cmp(s, s2.s) < 0;
|
© 2006 - 2025 pmbk.ru. Генерация страницы: 0
При копировании материалов приветствуются ссылки. |