C++ Учебник

  • View
    249

  • Download
    37

Embed Size (px)

Text of C++ Учебник

1 C++C++-. AT&TBellLaboratories1985. C++ C :- ;- - ;- C(, , ).20 , . C++ .C++, . , , . C++, . . . , . , C++ . ,, , . C++ , . , , . . C++ . , , . ,,- .2 C++, ., :- C++ ?- C++?pC++, .2.1. C++1., 2,3 3,7. , :Program Zad1.cpp#include int main(){double a = 2.3;double b = 3.7;double p, s;/* */p = 2*(a+b);/* */s = a*b;/* */cout n;,, cin true, cin false.. 6. . 6, . n - 1, 2,, , n, ENTER. (, 18, ,), i , i (i = 1, 2, , n).: :double a, b, c;cin >> a >> b >> c; a, b c . 1.12.2 3.3 ENTER a 1.1, b 2.2 c 3.3. , 1.1 2.2 ENTER3.3 ENTER1.1 ENTER2.2 3.3 ENTER1.1 ENTER2.2 ENTER3.7 ENTER 1.1 2.2 3.3 4.4 ENTER , 4.4 , . . - .: :int a;cin >> a;a(a int), .1.25,ENTER. :cin1 .25 \n19 cin >> a; a 1, , . - , a , one, ENTER. , cin >> a; cina-..a( ), fail. , .. , -, ...7 .2.4. C++, . - ,-. (source) . , ,. one\n fail20,. , . ";cin >> x;AddNode(x);cout > c; }while(c=='y');}- Create3 .template void BinOrdTree::Create3(T x, BinOrdTree l, BinOrdTree r){root = new node; root->inf = x;24 Copy(root->Left, l.root); Copy(root->Right, r.root);}- MinTree . . - ,, . -, . , . :min L min L min M template void BinOrdTree::MinTree(T &x, BinOrdTree &mint){T a=RootTree(); if(LeftTree().empty()) {x = a;mint = RightTree(); } elseRXX RKLLRKRLL25 {BinOrdTree t, t1;t=*this;*this = LeftTree();MinTree(x, t1);mint.Create3(a, t1, t.RightTree()); }}-DeleteNode .-. .template BinOrdTree BinOrdTree::DeleteNode(T const& x){T a=RootTree(); if(a==x && LeftTree().empty()) return RightTree();if(a==x && RightTree().empty()) return LeftTree(); if(a==x) {T c;BinOrdTree tmin;RightTree().MinTree(c, tmin);Create3(c, LeftTree(),tmin);return *this; } if(x x; t=t.DeleteNode(x); t.print();} 1. , , int. 2. int. , . 3. int. , . 4. , :) a d;)n- d ( 0- ). 5. CreateBinTree(d, n), n , :27) n) 1

n-1n-12 2

... ... ... ... 22 n-1n-1 1 11 1 n nn n 6. , : ::= |( ); ::= +|-|*|/; ::= 0|1|...|9, , . 7. , : ::= |( ); ::= +|-|*|/; ::= 0|1|...|9, , .8.,. , .9.., . 10. , . , , . 281. B. Stroustrup, C++ Programming Language. Third Edition, Addison Wesley, 1997.2. . , , . , 1974.3. . , C++ , , . 1993.4. . , C++, ., , 2001.5. . , , ., , 1993.