67
Вступ. Основні елементи мови С/ C ++ Основні керуючі конструкції мови С / C ++ (розгалуження та цикли ). Адресація, вказівники та масиви М етоди сортування масивів

Об’єктно-орієнтоване програмування

  • Upload
    sclnau

  • View
    42

  • Download
    7

Embed Size (px)

DESCRIPTION

Презентації з дисципліни «Об’єктно-орієнтоване програмування»

Citation preview

  • . /C++ /C++ ( ).,

  • .

  • 1. : ; ; : , , ; , . ; : ? ' ! | / \ ~ ( ) [ ] { } < > # % ^ & - + * = ' : , , , . . . , :Sum sum sUm SUM sUM

  • . : , , . 1. , . 2. , , , (e E) . : [ _ ][ . _ ][ [-] ] ( ), E (e) ( ). : 2.2 , 220-2, 22.-1, .221. 3. . - , . , \ ( ) escape- ( 1.1).

  • 4. , . " !\n" : const ' = ; const - ', , . : const float pi = 3.14l5926; const maxint = 32767; const const int. , /* */ , . - .

  • - , . :

    auto continuefloatinterruptshortunsignedasmdefaultforlongsignedvoidbreakdofarnearsizeofvolatilecasedoublegotopascalstaticwhilecdeclelsehugeswitchstructcharenumifregistertypedefconstexternintreturnunion

  • :

    , , . main() - - . : main() { return 0; }#include - -;#include - ;#include - ;#include -

  • : 1. char - , ASCII. ' char . char -128 127. 2. int - -32768 32767. , short - () long (4 ) - . 3. float - . ( - 3.14159), - 3.4+8. 4. double - , float: +(1.7 10- 308 ... 1.7 10308).

  • , , . , '. , . : int name; float var, var1; double temp; char ch; long height; ( ) : int height = 33 ; float income = 2834.12 ; char val = 12 ; , char, short, int, long signed ( ) unsigned ( ). (unsigned) ' , (signed).

  • scanf() printf(). printf() . printf(): printf(" "[, 1[, 2, [...]]]); ' : , , . . : #include void main() { int a=10,b=20,c=30; printf(" a==%d \n b==%d \n c==%d \n",a,b,c); }

  • printf(): %d - ; %o - ; %u - (unsigned) %x - ; %f - float double ; %e % - ; %g - f ; %c - (char); %s - ; %p - %ld - long ( ); %lo - long ( ); %p - ; %lu - unsigned long.

  • printf ("%d", c); cprintf (": %d", c);printf ("%d+%d=%d", a, b, c ); a, b, cprintf ("%d+%d=%d", a, b, a+b );

  • * int x = 1234;printf ("%d", x);1234printf ("%9d", x); 1234 9 5 4

  • float x = 123.4567;printf ("%f", x);123.456700printf ("%9.3f", x); , 6 123.456 9 , 3 printf ("%e", x);1.234560e+02 : 1,23456102printf ("%10.2e", x); 1.23e+02 10 , 2

  • scanf(). : scanf(" ",&1[,&2[, ...]]); . printf() , , , scanf () . scanf() , printf(). #include main() { int a,b,c; printf("A="); scanf("%d",&a); printf("B="); scanf("%d",&b); c=a+b; printf("A+B=%d",c); }

  • * ?int a, b;scanf ("%d", a);scanf ("%d", &a, &b);scanf ("%d%d", &a);

    scanf ("%d %d", &a, &b);scanf ("%f%f", &a, &b);

    &a%d%d&a, &b %d%d

  • 3. , , , . .

    + a+b-a-b* a*b/ a/b% a%6

    + ( ) +5- ( ) -x++ ( 1) i++, ++i-- ( 1)j--, --j

  • : . () , (). () , . () , . , () .

  • = "". .

    a = b b a += b . a = a + ba -= b . a = a - ba *= b . a = a * ba /= b . a = a / ba %= b . a = a % ba > ba &= b . a = a & ba |= b . a = a | ba ^= b 2 , a = a ^ b

  • ?: ?: - . : ? _1 : _2 . . , _1. ?: _1. , _2 . - (_1 _2).

    < = >!=

    && (and)| | (or)! (not)

  • sizeof() ', . : 1). '_ ; sizeof ; 2). sizeof ('_); sizeof() , , , . , sizof(int) int.

  • if switch while do : while for

  • : if () ; [else ] , , . 1. /* */ #include #include void main() { float a,b,c; printf("i a :\n"); scanf("%f",&a); printf("i b :\n"); scanf("%f",&b); if (b==0) printf("i !\n"); else { c=a/b; printf("a : b == %g",c); }; }

  • main() { int x; printf(" \n"); scanf("%d", &x); if ( x >= 25 && x
  • : switch() { case : ; break; case : ; break; .............................................................. case : ; break; [default: ;] }

  • - switch . switch (, switch ). . , - , . default , , . ' break case- ( while, do, for, switch), , switch-

  • 1: switch(i) { case -1: n++; break; case 0: z++; break; case 1: p++; break; }

  • while , . : while ();

    : 1. ; 2. , break; 3. return; , , , .

  • : (
  • do:while , , , . : do; while ();

    , . , repeat operator until , , do ... while ,

  • 2. #include #include void main() { int n,i; float fact; printf(" n!.\n"); printf("i n :\n"); scanf("%d",&n); i = 1; fact = 1; do { fact *= i; i++; } while (i
  • break : break; break do, for, while switch. switch case. - , ' . break , , . continue : continue; continue do, for, while. . do while . for .

  • for . , . : for([];[_];[_]) ; . : 1. () , ; 2. ( ). 0, , , ; 3. ; 4. , ; 5. 2. - continue 4.

  • . 8 1 ( ).: .for (i = 8; i >= 1; i -- ) { i2 = i*i; i3 = i2*i; printf("%4d %4d %4d\n", i, i2, i3); }

  • : goto ; /* ... */ : ; goto , . , . , . , goto . , goto. , .

  • 1. 2. 3.

  • () - . - , , , . , , , , , ' void. void - . ' ( ) ' '. NULL stdio.h () . "*". : [] * - ; - , - ( ).

  • ' : near - , 16- ( ), 64- ; far - , 32- , : 1 ; huge - , far, , ; , , , huge; - - ; : int *pi; /* - - int */ float *pf; /* - - float */ int ml [5]; /* - ' 5 int; ml - -, */ int *m2[10]; /* m2 - ' 10 int, m2 - - */ int (*m3)[10]; /* - 10 int; m3 - - */

  • , , : 1. , , , ; 2. ; 3. ' : , , , , ; 4. ; 5. .

  • - & *: : & ' - ; ; * '- - ; , , ; - : '__ = & ' ; : int i, *pi; /* pi - */ pi = &i; /* pi 'i' */ & - . & ' , , .

  • , : #include char c; /* */ main() { char *pc; /* */ pc=&c; for(c='A';c
  • * ?

    int m = 4, n, *pI; pI = &m; printf ("m = %d", * pI); // n = 4*(7 - *pI); // n = 4*(7 - 4) = 12*pI = 4*(n m); // m = 4*(12 4) = 32printf("&m = %p", pI); // int *pI, i, A[] = {1, 2, 3, 4, 5, 999};pI = A; // A[0] Awhile ( *pI != 999 ) { // while( A[i] != 999 ) *pI += 2; // A[i] += 2; pI++; // i++ ( ) }*%p

  • - : 1. , , , : pi = &j; pi = NULL;2. ( main()) - , static; (NULL); 3. , ; : pi = p; - ; 4. - calloc() malloc() - . C++ new; = new []; new ', ;

  • *A215 ()A[0]A[1]A[2]A[3]A[4] A[2] () : 2 : 15 , 3.

    510152025

    01234

  • : 1. ' , ( ) - ; 2. . - : , , . : 1. ; : a. ; : int [5]; b. , ; : int [] = { 1, 2, 3 };

  • 2. ; :a. ; ; b. ( ); , ; ; (). - , ,. : '_ [--];

  • : int [10]; nt *p = ; /* - */ (sizeof(Type) * - ) .

    int A [ ];const int N = 5;Nint A [ 5 ]; :

  • int A[4] = { 8, -3, 4, 6 };float B[2] = { 1. }; char C[3] = { 'A', '1', '' }; ! :

  • *: : : :const int N = 5; int A[N], i;printf(" 5 :\n");for( i=0; i < N; i++ ) { printf ("A[%d] = ", i ); scanf ("%d", & A[i] ); }A[0] = A[1] = A[2] = A[3] = A[4] = 512345613for( i=0; i < N; i++ ) A[i] = A[i]*2;printf(":\n");for( i=0; i < N; i++ ) printf("%4d", A[i]);: 10 24 68 112 26

  • *#include #include main(){const int N = 5;int A[N], i; // // // getch();}: 5 , 2

  • * : .// , A[0] for ( i=1; i < N; i++ ) if ( A[i] > ) // A[i]

  • * RAND_MAX ( RAND_MAX = 32767) [0,RAND_MAX] x = rand(); // x = rand(); // : srand ( 345 ); // 345 #include //

  • *

    [0,N-1]:

    : [a,b]: int random(int N) { return rand()% N; }x = random ( 100 ); // [0,99] x = random ( z ); // [0,z-1] x = random ( z ) + a; // [a,z-1+a] x = random (b a + 1) + a; // [a,b]

  • : ( ).: A[0] A[N-1], A[1] A[N-2], :for ( i = 0; i < N; i++ ) // A[i] A[N-1-i] N-1

    3597

    7953

    01N-2N-1

    01N-2N-1

  • . , - ( ), - , - , - . ( ): '- [1][2] ... int: int [m][n] ; m (), n (). 2 . : [i][j]- 2 ; i-, j- ; , ;

  • 4. . N M 1- 3- .13jA[1][j]A[3][j]for ( j = 0; j
  • " " . . . (N-1)-, - (N-2)- .. , . ( -is), 0 1 , - . 1.

  • const n=10; int a[n], i, c, is; /* : */ do { is=0; for (i=1;ia[i]) { c=a[i]; a[i]=a[i-1]; a[i-1]=c; is=1; } } while (is);

  • 2. : , , . , . , . , N-1 .

  • const int n=20; int b[n]; int imin, i, j, a; /* : */ for (i=0;i
  • 3. , - "" - a[i] a[1], a[2], :, a[i-1], . .

  • :const int n=20; int b[n]; int i,j,c; /* : */ for (i=1;i=0&&a[j]>c;j--) a[j+1]=a[j]; a[j+1]=c; }

  • , { k1, k2, :, kn } B1, {k1}, B2, 1 - , k1, 2 - k1. k1 . B1 B2 . (n2), .

  • double * quick(double *s,int low,int hi) { double cnt,aux; int i,j; if (hi>low) { i=low; j=hi; cnt=s[i]; while(i < j) { if (s[i+1]