1. Ͳ Ͳ ++. 1

2. Ͳ . 2

3. ֲ, в ֲ Dz. 3

4. Ͳ ֲ : 5

5. ֲ; Dz ̲Ͳ ̲Ͳ; ; ̲ IJ ̒Ҳ ² . 5

6. ’ Dz; Ͳ ; ̲Ͳ . 7

7. ² ² ֲ . 8

8. Ͳ ֲ ++. 10

9. ֲ ² : 10

10. Ҳ Ҳ ̒Ҳ ̲ ֲ /++. 12

11. ++, ’ . 13

12. . 15

13. Ͳֲ ˲ ² . 16

14. Ͳ , . 19

15. ² . 22

16. ֲ MAIN(). 22

17. . 23

18. Ͳ , ˲ֲ ² ++. , , . 23

19. Ͳ ֲ. 24

20. ֲ . 25

21. ̲Ͳ . 25

22. ֲ NEW DELETE. 26

23. ֲ. 28

24. ² ++, ²̲ ² ² . 28

25. ++. 29

26. Ͳ- ֲ- , Dz THIS. 31

27. Ͳ Ͳ . 33

28. , ϲ. 35

29. : ղ , ²Ͳ ֲ, ˲Բ, . ! .

30. в. 43

31. ֲ Ѳ. 46

32. ² ; Ͳ -, . 50

33. Ͳ . 52

34. ² ++. ˲. 53

1. Ͳ Ͳ ++.

(++) - . ( ), ( ) .

: <> < >; <> < > = < >;

. . :

ʳ

ij

int ()

2

-32767..32768

unsigned ( )

2

0..65535

short ( )

2

int

long ( )

4

..

float ()

4

..

double ( )

8

..

char ()

1

-127..128

unsigned char ( )

1

0..255

. 1. . .

2. - u (unsigned) l (long).

:

int i = 0, size_of_array = 10;

float x, y, z;

char ch = A;

unsigned score = 0;

unsigned long lnum = 0L;

2. Ͳ .

++ .

1. ֳ , :

) 0 9, , : 100, 1024, -1, 0;

) 0 0 7, : 017, 0124;

) 0, , ( 0 9 A F a f), : 0X17, 0XA1; 0x12b.

2. ij , , : 1.2, 1-10, -1.5+05.

3. ( ) , , a 0. , ASCII. , , \n \t. ֳ esc- , (). - esc- , , \0 ( null-), 0; \013 , \v . , esc- :\\ ; \ ; \ .

4. ( ) , , String constant, . , , null- \0, - . , x x .

3. ֲ, в ֲ Dz.

. , 䳿 . , , , . , ᒺ .

1. (+,-,*,/,%( - )).

2. (==; !=; < ; >;<=; >=;). . ³ 1, , 0 .

3. .

, , . , 0 . : (&& ); (|| Δ); (! ); : x && y (x != 0) && (y != 0); !(x || y) (x = 0) && (y = 0);

!x (x == 0);

4. .

. : (& ( )); (| Δ ( )); (^ Δ); (<<(>>) ()); (~ ).

5. . <> = <>; <> op= <>; (op - + - * / % << >> & | ^) <=> <> = <> op <>;

6. .

( ), 1 ++ , 1 --. - , ++k ( ), , k++ ( ). , . : , .

7. ( ).

:

1 ? 2 : 3;

в ֲ:

! ~ ++ -- + - * ( )

* / % ( )

+ - ( )

<< >> ( )

< <= > >= ( )

== != ( )

& ( )

^ ( )

| ( )

&& ( )

|| ( )

? : ; ( )

= += -= *= /= %= &= ^= |= <<= >>=

( )

 

 

 

 

 

 

4. Ͳ ֲ :

ֲ ( IF; IF-ELSE; SWITCH );

: if<><> ;

: if<>< 1>; else < 2>;

: switch () {

case __1:

case __2:

case __N:

default : }

- .

. ó default '.

" ". , break.

ֲ ˲ ( FOR; WHILE; DO-WHILE );

for: for (1; 2; ) <>;

while ( ): while () <>;

do-while ( ): do <>; while ();

ֲ BREAK; CONTINUE;

break; - .

continue; while do-while. for - 3.

5. ֲ; Dz ̲Ͳ ̲Ͳ; ; ̲ IJ ̒Ҳ ² .

, '. , , , ( C++) .

: <> * <_>;

: int * _; // _ - int; char * _; // _ - char

' - .

: ' ( malloc (), calloc ()).

.

int ; int *_ = &; // _ // & -

*_ = 10; // 10

++*_; // 1

cout *_; //

. (*)++; ' ++*_; - .

- , null. 1 2 - , :

1 < 2 : "1 , , 2";

1 <= 2 : "1 , , 2";

1 > 2 : "1 , , 2";

1 >= 2 : "1 , , 2";

2 - 1 , 2 1;

p1 + k k- , , 1.

p1 - k k- , , 1.

'.

' <stdiib.h> (<cstdlib> std):

void* malloc (size_t size); - size ' Heap null, ' . pi = (int*) malloc (sizeof(int)); // 1 .

void* calloc (size_t n, size_t size) ; - ', n ' size null, ' . p = (int*) calloc(5, sizeof(int));

void* realloc (void* p, size_t size); - ', , size , null, . ' , , . p_i = (int*) realloc (p_i, 10*sizeof(int));

void free (void* p); - ', . free (p);

 

 

6. ’ Dz; Ͳ ; ̲Ͳ .

: <> <_> [_];

<> , 0 _ - 1.

:

int rr [10] ; 10

for (int = 0; < 10; ++)

rr [] = *;

: - , , [] - *(rr + ) , &rr [] - rr + . :

char text [ ] = {'','','1','1','','\0'}; - .

int* arr = new int [ ]; void* malloc (sizeof(int) * < >);

char* arr = new char [ ]; void* malloc (sizeof(char) * < >);

++ 1.

( ):

<_> <_> [_] [_];

, , , , .

7. ² ² ֲ .

1. .

: int printf (char* format, arg1,arg2,..);

, , format. ᒺ: , , , % . ʳ printf . -. .

%[][ ][.]-

- : + (' ) - ( ) ϳ '.

- printf

d, i

int

o

int

x, X

int

16-

u

int

c

int

s

char*

\0 ,

f

double

[-]m.dddddd ( 6 )

e, E

double

[-]m.ddddddE xx

g, G

double

%e %f

p

void*

%

 

, %

: char* s = Holiday; printf (\n %-10.5s, s); /* : Holid______ */

 

2. .

: int scanf (char* format, arg1,arg2,..);

, format , . . format ': , , , ' , , % . : %[][ ]- - * ( ) ϳ '.

- scanf

d

int*

i

int*

-

o

int*

x

int*

16-

u

int*

c

char*

s

char*

f, e, g

double*

%

 

%,

-: scanf (\n %*2d % %*2d,&ch);

 

8. Ͳ ֲ ++.

-         cin ( ᒺ ), ;

-         cout ( ᒺ ), ;

-         cerr , ;

-         cprn ( ᒺ ), ;

<< , >>.

. <iomanip>, #include. ' , , .

, , . hex, oct, dec 16-, 8-, 10-. showbase, noshowbase 0 0x . uppercase, nouppercase 16- . 䳺 fixed ( ). scientific . setprecision (n) - precision (n) n ( 6).

9. ֲ ² :

C/C++

- . , , . . '.

C++

C/C++

(ANSI-): static extern( ) -> ;

(static extern( )) < ( void)> _ (< ->) { // -; return <( )>; }

. , ( ) . . 4. ( & г). /* n , */


void itostr ( int n )

{ int temp;

if ( n < 0 )

{

putchar ('-') ; n = -n;

}

if (temp = n/10) itostr (temp); /* */ putchar ( n%10 + ' 0');

}

, , , . . ϳ . - putchar , . , n%10 - , n%10 + ' 0' - .


. <math.h>. double, n - int; double.

sin (x) - ; cos (x) - ; tan (x) - ;

typedef: typedef double (*p_function) (double);


p_function - , double double. - ( ).

typedef double (*p_fun) (double);

void fun(p_fun f)

{

cout << f(3.1415) << endl;

}

int main() { fun(cos);}


 

. <math.h>. double, n - int; double.

sin (x) - ; cos (x) - ; tan (x) - .

 

10. Ҳ Ҳ ̒Ҳ ̲ ֲ /++.

( 䳿) (ᒺ) , . ( ) ( 񳺿 ).

' ' C/C++

' ' -

' ' -

extern ( )

auto( )

,

'

static

, '

register

'

 

 

11. ++, ’ .

(++) , , ( ). . :


struct tag_name

{

<_1> mem_1;

<_2> mem_2;

...

<_n> mem_n;

};

mem_1, mem_2 , ... , mem_n , ( ) tag_name. , , , , :

struct tag_name <->;


.

1. . , , , .

2. struct , ++ .

3. , , .


.

䳿:

-         ;

-         ;

-         .

.

, . ,

struct Person group [25];

25 Person.


 

.


, , , . .

/* */

struct Date

{ /* , */

unsigned day, month, year;

}

struct Person

{ /* , */

int num;

char name [20];

char address [20];

struct Date birthday;

};


.


. , . () , , .

- , . ( , ).

/* last */

struct Person

{

unsigned key;

char name [20];

struct Person *last;

};

/* build_list n */

struct Person* build_list (unsigned n)

{

struct Person *p, *q;

int i;

q = NULL;

for (i=1; i<=n; i++)

{

p = (struct Person*)malloc (sizeof(struct Person));

if ( p != NULL )

{

p->key = i;

p->last = q;

q = p;

}

}

return q;

}


12. .

(++) , ( ) ᒺ . . , ᒺ . ᒺ , . , ᒺ .


ᒺ:

union tag_name

{

<_1> mem_1;

<_2> mem_2;

...

<_n> mem_n;

};

/* ᒺ table ival, fval, *ps */

union table

{ int ival;

float fval;

char *ps;} u, *pu;


u , - . , ,

u.ival = 1; , - , . ϳ pu = (union table)malloc (sizeof(union table)); ᒺ : pu->fval = 1.0; .

(++).

( ) , , , , . ᒺ: enum tag_enum {< >};

C/C++

(++) - , . . :

struct bit_field

{

<_1> mem_l : nl; // nl -

<_2> mem_2 : n2; // 2 -

<_> mem_n : nn; // nn -

};

 

13. Ͳֲ ˲ ² .

, , (). .

, , , , ( ), , . . , - fopen , FILE .

: FILE* fopen ( char* filename, char* mode);

, , , , , :

r ();

w ( ) () ;

a ;

r+ ( ), ;

w+ , ;

a+ .

FILE; NULL. , , t , ( 䳺 ), b .

int fflash (FILE* fp); - , .

( ) - int fclose (FILE* fp); 0 EOF ( , stdio.h) .

FILE *fp;

fp = fopen (A:\\my_file, w); /* \\ */

if (fp != NULL)

{

/* , : */

fclose (fp);

}

.

1. int fgetc (FILE*fp); - . EOF, .

2. int fputc (int ch, FILE*fp); - ch . ch EOF, .

3. char * fgets (char *s, int n, FILE *fp); - s () , fp, : 1). \n ( ); 2). ; 3). n-1 .

ϳ \0 . \0 \n. , s, NULL.

4. int fputs (char *s, FILE*fp); - s . 0 EOF, .

5. int fprintf (FILE *fp , char *format, ); - , fp, format. ³ , printf (. ).

6. int fscanf (FILE *fp , char *format, ); - , format, . ³ , scanf (. ).

7. int feof (FILE *fp); - 0 ( ), 0 ( Ͳ) .

8. int ferror (FILE *fp); - 0 ( ), fp 0 ( Ͳ) .

9. void rewind (FILE *fp); - . .

.

( , ), , .

1. int fgetpos ( FILE *fp, fpos_t *pos); - pos , fpos_t ( long int), fp. 0, pos .

2. int fsetpos ( FILE *fp, fpos_t *pos); - fp , pos. fgetpos. 0, pos .

3. int fseek ( FILE *fp, long offset, int from_where ); - fp , offset , from_where offset>0 offset<0. : SEEK_SET (=0) ; SEEK_CUR (=1) ; SEEK_END (=3) . 0, .

 

 

14. Ͳ , .

( ) (++) - , , . - , . , , . #: #define <> < >

: #define MAX_SIZE 10 int main () { int arr [MAX_SIZE] ; }

1. - "", :

#define MAX_SIZE =10

#define MAX_SIZE 10;

.

2. - . C/C++ .

3. #undef <>

, .

4. ## .

:

#defn <>(<>) < >

 

:

̳ , , .


:

#define cube(x) ** int main ()

{ int = 1;

float x = 1.0;

cout cube () endl;//

cout cube (x) endl;// !

}

#undef cube

:

// ##

#define concat(left, right) left ## right int main ()

{ ab

int concat (a, b) = 100; // cout concat (a, b) endl;

 

:

#define max(x, ) ( > ) ? : int main ()

{ int = 1, j =2;

float x = 1.0, = 2.0; int m = max (, j) ; cout m endl; float f = max(x, y) ; cout f endl;

}


 

- , :

int main ()

{ int = 10, j = 20;

float x = 10,0, = 20,0;

cout cube ( + j) endl; //???

cout max (x, y) endl; //???

}

- :

 

(cout ( > )) ? : ( endl);

:

#define cube() (()*()*())

#define max(x, ) ((() > ()) ? () : ())

: int main ()

{ int = 1, j = 2;

float x = 1.0, = 2.0;

cout cube ( + j) endl; //!!!

cout max (x, y) endl; //! ! !

}


 

, : cout cube (++) endl; cout cube (++i) endl;

' . header- ( ), , , , , , ,

#include header-> #include " header-"

, - , , .

.

#if, #elif, #else #endif. :

#if __1

#elif __2

#elif __3

#else #endif

#if (), #峳£ #endif

#else (elif else-if)

. VERSION, :

#define VERSION #if VERSION == 1

#define INCLUDE_FILE "file_l.h #elif VERSION == 2

#define INCLUDE_FILE "file_2.h #else

#define INCLUDE_FILE "file_3.h #endif #include INCLUDE FILE

, , :

#ifndef <> #define <> // , #endif

, <> #def ine . , #endif.

typedef

typedef

' . . typedef unsigned short WORD_; word_ unsigned short.

typedef :

typedef double (*p_function) (double);

15. ² .

#include <iostream>

using namespace std;

- ,

, .

main().

ҳ , !

16. ֲ MAIN().

C main: argc argv.

: int main (int argc, char * argv []) {...}

argc integer .

argv char - . . .


argv [0] - '

argv[1] -

argv[2] -

argv [argc-1] -

argv [argc] NULL

 

int main(int argc, char *argv[])

{

for (int i = 0; i != argc; i++)

{

cout << argv[i] << endl;

}

system("PAUSE");

return EXIT_SUCCESS;

}


 

17. .

. //

#include <iostream>

using namespace std;

// - Main()

int main()

{ //

cout << " "+"!!!";

//

cout << " ";

int i; //

cin >> i; //

cout << i; //

system(PAUSE); //

return 0;

}

? , , /* */ , , . , , . , // . , C -, .

ϳ #include <iostream>, - \ . , using namespace std; std. , cout, . - main() -.

 

++

18. Ͳ , ˲ֲ ² ++. , , .

ᒺ- . -, ᒺ () , , . -, ᒺ ᒺ. , ᒺ , . , . : .

, ++ , , ,  .

C++

, ' ', , . . ( C++), . C++ ', . ' - - , 䳿 - . - , , , . - .

19. Ͳ ֲ.

. , inline ( , ). , ("") . inline- , : . - ' . - - , - . , , inline - , , , . , .

.

inline double cube (double x) {return x*x*x;} int main ()

{

double res, s = 10;

res = cube (++s); // : s = 11, res = 100

}

20. ֲ .

. , , , .

. //

void InitScreen (int width = 80, int height = 24, char background = )

{// }

int main ()

{// :

InitScreen (60) ;

InitScreen (60, 20);

InitScreen (60, 20, *#'); // :

InitScreen (**'); }

21. ̲Ͳ .

-. & '. -.

.

int val = 10; // // - val int & r_val = val;

val r_val , . '. , - :

int val = 10;

int & r_val;

r_val = val; // !

- . , . . - by-reference ( ).

. //

void change (int &a, int &b)

{ int temp = a; a = b; b = temp;

}

int main ()

{ int x = 10, = 20;

change (x, y);

cout x y; // x !

}

, -, .

- .

 

 

 

 

 

22. ֲ NEW DELETE.

new

C + + ' 䳿, ', , new. ' new ( new) ', ', ' . , : MyType * fp - new My (1.2);

malloc (sizeof (MyType)), , this (1,2). , fp, ', . ' , . , new , ', . ϳ , '.

new - , . , new :

* fp = new ;

, ' - ', , ' . ' , .

delete

new delete, , ' ( free ()). 㳺 , new ', delete ': delete fp;

' '.

delete ', new. ' ' malloc () ( calloc () realloc ()), delete, . new delete malloc () free (), , ' . , delete . delete, . ' .

23. ֲ.

- .

³ , .

.

void fun (int ) ;

int fun (int ); // !

void fun (int , int j);

void fun (double x) ;

void fun (int *pi) ;

void fun (int &i); // !

void fun (char *s) ;

void fun (const char *s); // !!!!

void fun (const char s); // !

24. ² ++, ²̲ ² ² .

++ , , ( ). . :


struct tag_name

{

<_1> mem_1;

<_2> mem_2;

...

<_n> mem_n;

};

mem_1, mem_2 , ... , mem_n , ( ) tag_name. , , , , :

struct tag_name <->;


.

1. . , , , .

2. struct , ++ .

3. , , .

 

25. ++.

C++

, ' ', , . . ( C++), . C++ ', . ' - - , 䳿 - . - , , , . - .

C++.

class <_>

{

// -

private: // -

<_1> <_1>;

<_2> <_2>;

// -

public: // -

<_> <_1> (<_>);

<_> <_2> (<_>);

};

?

() - - .

() , () , . , , .

³ - , - .

- , - .

, - .

 

?

- , , - . , , , . ' , - . , ' - ' () , . ( , - ) , void.

//

Student (double av_mark_, double ex_mark_, char * name_ = "Noname" )

{

av_mark = av_mark_;

ex_mark = ex_mark_;

strncpy (name, name_, sizeof(name));

name [sizeof(name)-1] = '\0';

cout "Create Student " name endl;

}

student new delete.

?

new, delete. , , , . - , - - . , . , . ' - , .

C++ ', .

 

 

26. Ͳ- ֲ- , Dz THIS.

- .

- . inline-. , , , . , . : : . , , ' :

Student : : Student (double av_mark_, double ex mark , char * name ).

this.

' this () . this . ³ this , , ', . , this () . , this ', . ', this, this. . , :


struct ss

{ int si;

char sc;

ss(int in, char en) // ' .

{ this->si = in; this->sc = en; }

void print(void) // '.

{ cout << "\n si = " << this->si;

cout << "\n sc = " << this->se; }

};

this , ' . this , .


this , ', . , , ' ' , this. ij, ' , ' , ' ', . - . ' ', , , , . , . ', this. , , this , , , ' ZOB, ZOB *const ', . X ': X factor(5); X, ' factor,

this &factor.

27. Ͳ Ͳ .

- () , , , , , , . static, ' . ' ( # - ' ). .

, , ' - , . , ( ) const, , ' !

sizeof ', .

class Example

{ public :

static int num; //

int key;

Example (int key_) : key (key_) {} };

int Example :: num;// ' , = 0

int main(int argc, char *argv[])

{Example e (1), f (10);

cout Example :: num endl; // '

Example :: num = 100;

cout e.num endl; // '

cout f.num. endl; // '

e.num = 1000;

cout e.num endl;

cout f.num endl;}

- - , ' , this. static , . ' , . , - . !

28. , ϲ.

'. ij, , , , ' . C + + - (Constructor function), . ' . , - ' . ', , , . , . ' ' , . ' - . , , (destructor). '. ' 䳿. , ' ', . ' ' , ~ () . '. ' , . ' . .

. . ' . , , :

.

, . , , . , , . , . - , .

.

, Student f () , , , . . ! ij , - . , . ³ . , , , ' , . : <'_> (const <'_> & );

- . - ﳿ . , , ' new. - ( ), ', , - .

29. : ղ , ²Ͳ ֲ, ˲Բ, .

, .

- '- , ', ', . ' ϲ² : SubBase - ղ ² Base, TO SubBase Base. :

class SubBase : <_> Base

{

//

};

.

1. () (public) (protected) . (private) .

2. .

3. . .

4. , ( ) . .

5. , .


.

class Base

{protected : //

double money; int key; public : //

Base (double money_ = 1000, int key_ = 1) :

money (money_) , key (key_) {cout "Create Base" endl;} double show_money () {return money;} int show_key () {return key;}

};

class SubBase : public Base

{public :

//

SubBase (double money_, int key_)

{

cout "Create SubBase" endl;

money = money_; key = key_; }};

.

class Base

{protected : //

double money; int key;

public : //

Base (double money_ = 1000, int key_ = 1): money (money_), key (key_)

{ }

double show_money () {return money;}

int show_key () {return key;}

};

class SubBase : public Base

{

public :

// SubBase (double money_, int key_): Base(money_, key_) { }

};


:

public

private

protected

public

protected public

protected

private

protected

public

protected protected

private (IJ

)

private

protected

public

private private

 

.

:

- ;

- ;

 

 

 

.

' .

, .

' , :

         ;

         ;

         .

is-a.

SubBase sb;

Base bb = SubBase ();//

b = sb; //

Base & bbb = sb; //

Base *p = &sb; //

// sb = b; // !

ֳ , , .

, , , , - :

void fun (Base & b) { b.meth();}

fun (b); // | fun (sb); //

, - , fun() .

, , , . . ( , ).

.

1. ( ) :


class Base

{ public:

void meth ()

{ cout << "In Base: meth() " << endl; }

};

class SubBase : public Base

{//

void meth ()

{ cout << "In SubBase: meth() " << endl;}};

int main (void) {

Base b; //

SubBase sb; //

b.meth (); //

sb.meth (); //

return 0;

}


' (- ) ( ). , , '. ' ( ', # - ) ' .

2. .

ϳ ' - (), . ³ (virtual) . , , . ' ' - . - , . virtual '.


class Base

{ public:

virtual void virt () //

{

cout << "In class Base" << endl;

}

};

class SubBase : public Base

{public :

// . C virtual

virtual void virt ()

{ cout << "In class SubBase" << endl;} };


, fun (Base & b), , '.

г , virt() , . ³ , .

, ' , '. , .

. . . , : , , .

. , , , . , .

(ABC Abstract Base Class).

, . . , ', , . , ', , (is-a), , : , , . ' , . , . , .


class Figure //

{ protected :

double x_cntr, y_cntr; //

public:

Figure (double x = 0, double y = 0) : x_cntr (x), y_cntr (y) {}

//

virtual double Square () const = 0;

};

class Rhombus : public Figure //

{ private :

double len, angle;

public :

Rhombus (double l = 0,double a = 0,double x = 0,double y = 0);

double Square () const { return len*len*sin(angle); }

};


 

 

 

 

 

 

 

30. в.

, , ' , . ++ , , . () , . , complex, . , 䳿 , : complex a, b; complex c = a + b; c = a*b;

1. .

, ( ) . . friend, .

friend void excellent (Student &s); //

void excellent (Student &s) // -

{ s.av_mark = 60; s.ex_mark = 40; }

.

1. ', friend , .

2. - .

2. this.

- ( ) this. , , .

operator@, @ , . . -, - . -, - .

- :

<_> operator@ (< __2>);

this, . , a@b, a b , : a.operator@ (b)

:

friend <_> operator@ (<__1>, < __2>);

a@b : operator@ (a,b)

 

- : <_> operator@ ();

this, . @a : a.operator@ ()

:

friend <_> operator@ (<_>);

@a : operator@ (a)

.

1. , = - . , , = .

2. , , ', (, , ). = .

3. ' ﳿ .

. , , , ( # ). ++ ೿ -. , , . :

// : <_> operator++ ();

// : <_> operator++ (int unused);

, :

// : friend <_> operator++ (<_>);

// : friend <_> operator++ (<_>, int unused);

.

.

1. : + , , , .

2. , % . .

3. , , x**y x y.

4. :

sizeof . ( ) .* ( ) :: ( ) ?: ( ) , .

.

1. , (- ) .

2. , , (, , ), ' .

3. - , . - : = () () ( ) [] ( ) -> ( ).

 

31. ֲ Ѳ.

(template - English) - C++, , ' .

?

C++ ' ( , ) . ' , , , , ' . :

;

- , ;

- .

.

' , , . , , . , .

, , , - .

1. .

( )- , . template, - ' .

class, C++, typename, . ϳ .

, . ( - )


template <typename Type>

Type maxi (Type a, Type b)

{ return (a < b)? b : ; }

, ?

maxi, , maxi , , , . (instantiation) . , .

// . 1 2 - . class ( typename) !

template <class Typel, class Type2>

Typel maxi (Typel a, Type2 b)

{return ((Typel)a < b)? (Typel) b : a;}

- , , :

// - size

template <class Type, int size>

Type min_( Type (&r_array) [size] )

{ Type min_val = r_array[0] ; for ( int = 1; < size; i++ ) if ( r_array[i] < min_val )min_val = r_array[i];return min_val;}

, .

template <class Type, int size> Type min_( Type (&r_array) [size] );

, ( ) . , .

() , . , -. .

2. .

( ) , . , . :

template <class Type> class class_id { // };

- , template. , , , :

template <class Type> __ class_id <> :: func_id (_) { // }

: class_id <int> c_i; class_id <double> c_d;

_ class_id, int, c_dToro class_id, double . , , . class, , typename.

:

^ .

^ , .

^ , , , .

(STL -Standard Template Library), .

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

32. ² ; Ͳ -, .

++

iostream , ++. ++ . , . ( ), . .

'. , , . 䳺 . ++- , . , . , ' , . , '.

 

++.

 

ifstream , .

:

ifstream :: ifstream (char* pFileName,

int mode = ios::in,

int prot = filebuff::openprot);

, . . .

ofstream , .

:

ofstream :: ofstream (char* pFileName,

int mode = ios::out,

int prot = filebuff::openprot);

, . . .

mode

ios::ate

ios::app

ios::in

³ ( istream)

ios::out

³ ( ostream)

ios::nocreate

ios::noreplace

ios::binary

³ () ( )

 

prot ( )

filebuff::openprot

( )

filebuff::sh_none

filebuff::sh_read

filebuff::sh_write

, , bin_file : ofstream bin (bin_file, ios::binary | ios::ate);

- bad() 1, :

if (bin.bad()) {cerr << Opening file error;}

- clear() ( ):

bin.clear();

33. Ͳ .

C++.

3 : , , . - ' , . .

bitset

<bitset>

queue

<queue>

list

<list>

set

,

<set>

stack

<stack>

vector

<vector>

map

-

<map>

 

vector <int> v (n); // n

v.push_back (-1); //

v.pop_back (); //

v.insert (v.begin (), 5, 100); // 5 100

v.insert (v.end(), 5, 100); // 5 100

vector <int> :: iterator p = v.begin (); // p

v.erase (p-5, v.end()); //

34. ² ++. ˲.

.

,

. . (,

student.h). #if ndef, . . (student.)

, , 볺 - use student. .

DevCpp.

1. -> -> ( main.cpp- , , use_student.cpp

).

2. -> -> ( " ?" ). (, student.h) . #ifndef stud_h #define stud_h. #endif

3. -> -> ( " ?" ). (, student, cpp) . #include student.h". use_student..

4. , .