You are on page 1of 35

1.

ANSI/ISO C++. C++. ++.


/ .
. ANSI/ISO C++.
C++ 80- Bell Labs
(Bjarne Stroustrup) .
C , , . C 1971
UNIX, .
(Accredited Standarts Committee),
( American National Standarts
Institute - ANSI), C++.
ISO - International Standards Organization (
) . C++,
ANSI/ISO C++, ANSI C++.
ANSI , C++ .
, , ANSI
Mac, Windows Alpha,
.
++ . C++
.
C - .
, , , , ,
.

:
1) (A,B,C,.,Y,Z) (a,b,c,,y,z) ;
2) 0 9;
3) :
+ (), - (), * ( ), / ( ), = (), > (), < ( ), ;
( ), & ( ), [ ] ( ), { } ( ), ( ) (
), _ ( ), ( ), . (), , (), : (), # (), %
(), ~ ( ), ? ( ), ! ( ), \ (
).

C : ()
() . () ,
. , (short),
(long) (unsigned).
( 1):
1


,

char
1
-128127

int
2
-3276832767

Short
2(1)
-3276832767(-128127)

Long
4
-21474836482147483647

Unsigned int
2
065535
Unsigned long
4
0424967295


Float
4
3,14*10-383,14*1038

Double
8
1,7 *10-308 1,7 *10308

, (struct),
(union), (enum).
.

(, ..), ,
. (
).
:
int
j=10, m=3, n;
float c=-1.3, l=-10.23, n;
,
(0...9), (A...Z) (a...z) ,
(_). .
(a.z) (A .Z), .. PI, Pi pi
.
, .
:
const float PI=3.1415926;
float
pi=3.14;
C
(). - .
:
- ;
- , ;
- ( ).
- , /*
*/ // .

, , ,
, , c (main)
.
:
< >
< typedef>
< >
< >
<>
, , :
<_> <> < > (< >)
{
-
< >
< >
}
-
5.
.

() .
.

:
- #;
- ;
- # ,
.
#include #define.
#include
( ) .
< >
. ,
.
:
#include <stdio.h>
-
-;
#include <conio.h>
- ;
#include <graphics.h> - ;
#include <math.h>
- .
#define ()
.
:
#define PI
3.1415927
PI
3,1415927.
:
#include <stdio.h>
#include < conio.h>
/* */
#define PI 3.1415927
void main()
//
{
//
int num;
// num
num=13 ;
//
clrscr();
//
printf(" \n pi=%7.5f\n %d - \n, PI, num);
}
//
#include,
, -
(stdio.h) printf() (conio.h) clrscr().
PI 3,1415927
. main num.
13. printf :
pi =3.1415927
13
, ,
; ( ).
/* */
//.

:
putchar() .
puts()
.
printf() . :

rintf (< >, < >);



. .
:
% <> < . >
:

);
+ ;
, .. .
;
, . . ;
.
:
2


%d

%c

%s

%e
( )
%f
( )
%u

%o

%x

(long, double) l.
: %ld - , %lf .
% 2 .
: printf(" %d%% .\n",5);
:
5% .
:
\n ;
\t \v ;
\b ;
\r ;
\f ;
\a ;
\ddd 8- ASCII-;
\xhhh 16-- -;
\? .
- (, ),
.
.
:
#include <stdio.h>
#define PI 3.1415926
main()
{
int number=5, cost=11000, s=-777;
float bat=255, x=12.345;

printf ("%d %f .\n", number, bat);


printf (" pi %f.\n", PI);
printf (" .\n");
printf (" %d%s.\n", cost,".");
printf ("x=%-8.4f s=%5d%8.2f ", x, s, x);
}
printf () :
=12.3450 s= -777 12.34


getch () .
gets () ENTER.
scanf .
:
scanf (< >, < >);
, printf (), .
scanf(), printf (), , ..
. &,
. &
. %s .
, .
:
int course;
float grant;
char name[20];
printf ( " , , \n");
scanf ( "%d%f", &course, &grant);
scanf ( "%s", name);
/* & */

<math.h>.
x y double, n int.
(2 = 360).
() double.
3


1
2
sqrt(x)
x
|x|
fabs(x)
x
e
exp(x)
xy
pow(x,y)
ln(x)
log(x)
lg10(x)
log10(x)
sin(x)
sin(x)
cos(x)
cos(x)
tg(x)
tan(x)
arcsin(x)
asin(x)
arccos(x)
acos(x)
arctg(x)
atan(x)
arctg(x/y)
atan2(x,y)
sh(x)=1/2 (ex-e-x)
sinh(x)
x -x
ch(x)=1/2 (e +e )
cosh(x)

tgh(x)
x y
, >=x
, <=x

tanh(x)
fmod(x,y)
ceil(x)
floor(x)


:
1. :
_ =;
, _.
:
y=(x+2)/(3*x)-5;
o ,
:
x=y=z=0;
/* x, y, z=0 */

z=(x=y)*5; - x y,
x*5 , z.
2. :
_ =e;
(+ , -, *, /, %);
: x*=5;
/* x=x*5;
*/
s+=7;
/* s=s+7;
*/
y/=x+3;
/* y=y/(x+3); */
,
.
(--) (++)
1. (++i --i) (i++ i--).
,
( i), .
.
: b=7;
n=1;
1.
c=b*++n;
/* n=n+1; c=b*n; .. c=14 */
2.
c=b*n++;
/* c=b*n; n=n+1; .. c=7 */


goto < >;
:
<>: ;
.
if .
:
if ( ) 1;
else 2;
if(x>y) max=x;
:
else max=y;
1 2 ,
{}, .. . if
. ( 0), 1, ,
(=0), 2.
(else 2;) .
. if
.

1 2 if ,
. else

if.
if:
if (1) 1;
else if(2) 2;
else 3;
: x,y,z.
if (x>y)
if (x>z) max=x;
else max=z;
else if(y>z) max=y;
else max=z;
:
< (), <= ( ), > (), >= ( ), != ( ), = = ().
= =, !=, <=, >= .
:
<_1> <_> <_2>
.
.
, .
: ! ( ), && ( ), ||
( ). && || .
:
(0<x)&&(x<=100)
((!x)&&(y>0)||((z==1)&&(k>0))
, ,
.
( ?). :
_ = ? _1 : _2;
, _ _1,
_2.
max=a>b ? a : b;
: :
switch
:
switch()
{
case consnant1: ;
break;

case consnantN: ;
break;
default: ;
}
consnant1consnantN - ; default - ,
; ; break -o
switch. case
. break , case.
switch , ,
. , .
:
swith(i)
{

case 1: f=pow(x,2);
break;
case 2: f=fabs(x);
break;
case 3: f=sqrt(x);
break;
default: printf(!);
exit(1);
}
f=f+5;

2
3
yx
yx
x y +1 + e y 1

h=
* (1 + y x ) +

,
1 + x * y tgz
2
3
x=2,444, y=0,00869, z=-130, : -0.49871.
:
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define x 2.444
#define y 0.00869
#define z -130.0
void main(void)
{
double rezult,dop,a,b,c;
clrscr( );
/* */
puts(" N1 - ");
puts("=========================================");
dop=fabs(y-x);
a=pow(x,y+1)+exp(y-1);
b=1+x*fabs(y-tan(z));
c=0.5*pow(dop,2)-pow(dop,3)/3;
rezult=a/b*(1+dop)+c;
printf("\a\n : rezult=%lf, Press any key...", rezult);
getch( );
/* */
}
if
F. ,
.

a x + tgy

x > 0, y < 0
5 - 2x ,

3
F = max ( x2 , cosy2 ),
x < 0 , y > 0 ,

y
2
x > 0, y > 0
min (0,5x - 2sin y, e ),

:
#include <conio.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#define A 1
#define C 3
double max(double m,double n)
{
if (m>n) return m;
else return n;
}
double min(double m, double n)
{
if (m<n) return m;
else return n;
}

/* max m n */
/* */
/* */
/* min m n */
/* */
/* */

void main()
{
double x,y,f;
clrscr();
puts(" x y");
scanf("%lf %lf",&x,&y);
if ((x>0)&&(y<0))
{
f=(A*x+tan(C*y))/(5-2*x);
puts("F=(*x+tg(c*y))/(5-2*x)");
}
else if ((x<0)&&(y>0))

/* x,y,f */
/* */

f=max(pow(x,2.0/3.0),cos(y*y));
puts("F=max(pow(x,2/3),cos(y*y))");

/* max */

}
else if ((x>0)&&(y>0))
{
f=min(0.5*x-2*pow(sin(y),2),exp(y));
/* min */
puts("F=min(0.5*x-2*pow(sin(y),2),exp(y))");
}
else
{
puts(" F \n Press any key...");
getch();
exit(1);
/* */
}
printf(": F=%lf,\n Press any key...\n",f);
getch();
}

/* */


1. ?
2. printf() scanf().
3. if ?
4. if switch?

2.
.
Visual C++.
- . (-)

while
while (<>) < >
< > ,
. counter ,
. ,
1:
// 7.2.
2:
// while'
3:
4:
#include <iostream.h>
5:
6:
int main()
7:
{
8:
int counter = 0;
//
9:
10:
while(counter < 5)
//
11:
{
12:
counter++;
//
13:
cout " counter: " counter "\ n";
14:
}
15:
16:
cout " Complete. Counter: " counter ".\ n";
17:
return 0;
18:
}
counter: 1
counter: 2
counter: 3
counter: 4
counter: 5
Complete. Counter: 5.
, . . .
.
, ,
++.
true.
while (true) < >

do...while
do < > while (<>)
< > ,
. do...while ,
.
.
// do...while
#include <iostream.h>
int main()
{
int counter;
cout "How many hellos? ";
cin counter;
do
{

cout "Hello\ n";


counter--;

} while (counter >0 );


cout "Counter is: " counter endl;
return 0;
}

How many hellos? 2


Hello
Hello
Counter is: 0

for.
for (<>;<>;<>) < >
<>
- , . <>
++,
. true, ,
< > , , ,
.
<> , :
<> <> .
1:
// Hello
for(int i=0; 1<10; i++)
cout "Hello!" < endl;
2:
for(int i = 0; i < 10; i++)
{
cout "Hello!" endl:
cout "the value of i is: " i endl;
}
for
. ,
. ,
.
//
// for
#include <iostream.h>
int main()
{
for (int i=0, j=0; i<3; i++, j++)
cout "i: " i " j: " j endl;
return 0;
}
for .
. , , for
(;). for
while.
for
, . ,
, (;).
for.
// for
// ""
for (int i = 0; i<5; cout "i: " i++ endl);
1:
i:
i:
i:

0
1
2
3

i: 4

,
for ; .
,

.
, ,
. .
, for,
. , ANSI, , ,
. , , ,
.
, .
#include <iostream.h>
int main()
{

//
for (int i = 0; i<5; i++)
{
cout "i: " i endl;
}
i=7;( ANSI )
return 0;
}

break u continue

. continue. , ,
. break.

GOTO
, ,
. .
, .
++ , (:).
, .
goto, .
/ goto
#include <iostream.h>
int main()
{
int counter = 0; //
loop: counter ++;//
cout "counter: " counter "\ n";
if (counter < 5) //
goto loop;
//
cout "Complete. Counter: " counter ".\ n"; return 0;
}
counter: 1
counter: 2
counter: 3
counter: 4
counter: 5
Complete.Counter: 5.
goto .

.
: " goto".

goto ,
: for, while do...while. ,
goto . ANSI
. , : "!
!"

1. ?
2. while dowhile?
3. ?

3
, ,

.
:
<><>[< 1 >][< 2 >][< N>]={{ },
{ },};
,
.
, b[2][1]
:
b[0][0], b[0][1], b[1][0], b[1][1], b[2][0], b[2][1].
,
, :
int a[3][4] = {{0,1,2,0},{9,-2,0,0},{-7,1,6,8}};
- {} ,
0. :
int a[3][4] = {{0,1,2},{9,-2},{-7,1,6,8}};

NxM (N M 50), rand
, N,M :
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define rnd (rand()/ 32768.0) // rand - 0
int,
rnd 0 1
void main(void)
{ int i,j,n,m,a[50][50];
puts(\n Input n, m:); scanf(%d %d,&n,&m);
printf(\n Array a \n);
for(i=0; i<n; i++)
for(j=0; j<m; j++) {
a[i][j]=rnd*10-5;
// 5 5
printf(%d%c, a[i][j], (j= =m-1)?\n: );
}
getch();

C
:
- , ;
- ( ).
,
, . ,
,
.
:
*;
: int *a, *d;
float *f;
a, d,
f,
.
: & *. &
(.. ).
. * : ,
:
- .
- ,
.
-
.
1:
int x,
/* int */
*y;
/* int */
y=&x;
/* y - x */
*y=1;
/* x
/* 1, .. x=1; */
2:
int i, j=8, k=5, *y;
y=&i;
*y=2;
/* i=2 */
y=&j;
/* j */
*y+=i;
/* j+=i , .. j=j+1 -> j=j+2=10 */
y=&k;
/* k */
k+=*y;
/* k+=k, k=k+k = 10 */
(*y)++;
/* k++, k=k+1 = 10+1 = 11 */
, ()
.

- .
,
( ),
( C). ,
:
int x[100], *y;
y=x;
//

...
x=y;
// : - -
-
, (
, "void *").
int i, *x;
char *y;
x=&i;
/* x -> int */
y=(char *)x;
/* y -> char */
y=(char *)&i;
/* y -> char */
:
int a=5, *p, *p1, *p2;
p=&a; p2=p1=p;
++p1; p2+=2;
printf(a=%d, p=%d, p=%p, p1=%p, p2=%p.\n,a,p,p,p1,p2);
:
a=5, *p=5, p=FFC8, p1=FFCC, p2=FFD0.
: ,
..
( )
:
p # ie, ##p, p##, p# = ie,
p - , ie - , # - '+' '-'.

ie*sizeof(*p). ,
, .

. , p#ie
, ie*sizeof(*p)
.
.
(">",">=","<","<=","==","!=").
.

( ).

. ,
, .
NULL,
. NULL
. NULL (void *)0.

.
, .
* .
* .
.
:
int a=5;
int *p1=&a;

int **pp1=&p1;
int ***ppp1=&pp1;
, 10.
:
a=10; *p1=10;
**pp1=10;
***ppp1=10;
, .
:
*p1 <-> p1[0] **pp1 <-> pp1[0][0] ***ppp1 <-> ppp1[0][0][0]

,
.

:
float name[][][][];
<-> float ****name;
:
name[i][j][k][l]
*(*(*(*(name+i)+j)+k)+l)
*(*(*(name+i)+j)+k)[l]
*(*(name+i)+j)[k][l]
*(name+i)[j][k][l]


,
. : char *m[5].
m[5] , char.
, ..
.
,
. ,
.
#include <stdio.h>
#include <conio.h>
void main(void)
{
int i,k;
char *m[]={
"Winter",
"Spring",
"Summer",
"Automn"};
k=sizeof(m)/sizeof(*m);
printf("\n size of array=%d",k);
for(i=0; i<k; i++)
printf("\n string - %d; adress - %p; string: %s", i, m[i], m[i]);
getch();
}
:
size of array=4
string - 0; adress - 0042007C; string: Winter

string - 1; adress - 00420074; string: Spring


string - 2; adress - 0042006C; string: Summer
string - 3; adress - 00420064; string: Automn
: ,
..

,
, , sizeof.
:
sizeof();
( ). sizeof
,
( int).
(, , ),
. :
sizeof(int)
->
2 ,
int b[5]; sizeof(b)
->
10 ;
int c[3][4]; sizeof(c) ->
24 .
sizeof :
float *x;
//
int n;
//
x=(float*)calloc(n,sizeof(float));
//
alloc.h,
:
void *calloc(unsigned n, unsigned m);
-
n m ,
NULL;
void *malloc(unsigned n);
- n
, NULL;
void *realloc(void *bf, unsigned n); -
bf n ;
void free(void *bf);
-
bf;
coreleft(void);
- (
unsigned tiny, small, medium; unsigned long ).


#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<alloc.h>
void main(void)
{ int i,n; float *a;
puts(\n Input n:); scanf(%d,&n);
printf(\n -%d,coreleft());
a=(float *)calloc(n,sizeof(float));
//
printf(\n Array a \n);
for(i=0; i<n; i++) {
*(a+i)=(float)random(10); // 0 10
printf( %d, a[i]);

}
printf(\n -%d,coreleft());
free(a);
//
getch(); }

...
void main(void)
{ int i,j,n,m; float **a;
puts(\n Input n,m:); scanf(%d %d,&n,%m);
printf(\n -%d,coreleft());
a=(float **)calloc(n,sizeof(float*));
//
for(i=0; i<n; i++)
a[i]=(float *)calloc(m,sizeof(float));
...
printf(\n -%d,coreleft());
for(i=0; i<n; i++) free(a[i]);
//
free(a);
getch(); }


1. .
2. () .
3. ?

4

PASCAL ,
string. .
char, ..
char, .
, ,
\0 ( -). ,
k , k+1 .
, : char a[7], , ,
.
, .
: .
\0 , .
, :
char S1[10]=123456789, S2[]=12345;
.

, stdio.h.
scanf( ) %S.
, scanf( ) .
gets( ), .
ENTER.
. , ,
, ,
& .
printf( ) puts( ).
. printf( )

,
. puts( )
.
.
string.h.
:
1. strcpy(S1, S2) - S2 S1.
2. strcat(S1, S2) - S2 S1 ,
S1, S2 . ,
S1, S2.
3. strcmp(S1, S2) S1 S2 =0,
, .. ; <0,
S1<S2; >0, S1>S2.
4. strlen(S) ,
.



,
.
#include <stdio.h>
#include <string.h>
#include <conio.h>
void main(void)
{
char s[100];
//
int i, k;
clrscr();
puts(" ");
gets(s);
k=strlen(s);
puts(" \n");
for (i=k; i>=0; i--)
printf("%c",s[i]);
/* */
printf("\n Press any key...");
getch();
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
void main(void)
{
char s1[]="aaa",s2[]="aaaa",s3[]="aaa ";
clrscr();

printf(\n %d,strcmp(s1,s2));
// -97 -
printf(\n %d,strcmp (s1,s3));
// -32
-
printf(\n %d,strcmp (s2,s1));
//
97
printf(\n %d,strcmp (s3,s1));
//
32
printf(\n %d,atoi("a"));
// :
0
printf(\n %d,atoi("12a"));
// 12
printf(\n %d,atoi("5aa")*atoi("2a34")); // 10
getch();
}

1.
2.
3.
4.

?
scanf() gets(), printf() puts()?
strcpy, strncpy?
strcmp, strtok?

5
.
.
:
struct _ {
;
};
:
struct _ _;
.

cin>>
scanf.
:
1) .
(&) .
2) : (.) -
( -> ) - .
, float,int,char
.. :
struct gr
{ char fio[10];
int est[25]:
int nomer;
} gruppa1;

/* */
/* */
/* */
/* */
/* */

struct gr gruppa2; /* */
,
.
( ).
struct date { int day,month,year;};
d[5]={ { 1,3,1980},
{ 5,1,1990},
{ 1,1,2002}

};


#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <iostream.h>
struct Spisok {
char Fio[20];
char Grup[10];
int Ot[3];
float S_Bal;
} *sved;
void Vvod(int nom,struct Spisok *sved)
{
cout << "\n Vvedi svedenia " << (nom+1);
cout << "\n FIO - "; gets(sved->Fio);
cout << " Nomer Gr - "; cin >> sved->Grup;
float s=0;
for(int i=0;i<3;i++) {
cout << "\n Otcenki - "; cin >> sved->Ot[i];
s+=sved->Ot[i];
}
sved->S_Bal=s/3.;
return; }
void main(void)
{ struct Spisok Stud[50]; int i,N; char Bukva;
clrscr();
cout << "\n Vvedi kol-vo < 50 "; cin >> N;
for(i=0;i<N;i++) Vvod(i,&Stud[i]);
cout << "\n Spisok Students";
for(i=0;i<N;i++)
printf("\n %20s %10s %4.2f",Stud[i].Fio,Stud[i].Grup,Stud[i].S_Bal);
cout << "\n Poisk FIO (bukva) "; cin >> Bukva;
cout << "\n Sveden Students";
int kod_p=0;
for(i=0;i<N;i++)
if(Stud[i].Fio[0]==Bukva){ kod_p=1;
printf("\n %20s %10s %4.2f",Stud[i].Fio,Stud[i].Grup,Stud[i].S_Bal); }
if(kod_p==0) cout << " Takix HET!";
cout << "\n Poisk zapisi";
Vvod(-1,sved);
kod_p=0;
for(i=0;i<N;i++)
if(memcmp(sved,&Stud[i],sizeof(sved))==0) { kod_p=1;
printf("\n Poisk \n %20s %10s",Stud[i].Fio,Stud[i].Grup); }
if(kod_p==0) cout << " Takix HET!";
getch();
}

- . () ( ),
.
,
.
:
[]:;
.
.
1
/* sum */
/* avans zarp st
*/
#include <conio.h>
#include <stdio.h>
#define k 2
#define PE printf("\n .. %d ......",k);
#define PE1 printf("\n===================================");
#define PE2 printf("\n");
struct fund{
char *mes_avans;
float avans;
char *mes_zarp;
float zarp;
};
main()
{
static struct fund st={"",
600000,
"",
900000
};
float sum(),res;
res=sum(st.avans,st.zarp);
printf(" \n O %8.2f .",res);
PE2;PE1;getch();
}
float sum(x,y)
float x,y;
{
clrscr();PE;PE1;PE2;
return(x+y);
}
2
/* sum
/*

str
/* str
/* sum - ,

*/
*/
*/
*/

/* spis. sum
*/
/* */
/* str, t
*/
/* spis, : t->vans t->za
*/
#include <stdio.h>
#include <conio.h>
struct spis{
char *s_vans;
float vans;
char *s_za;
float za;
};
main()
{
static struct spis str={"",
600,
"",
1000
};
float sum(),res;
res=sum(&str);
printf(" =%8.0f ",res);
getch();
}
float sum(t)
struct spis *t;
{ clrscr();
return(t->vans+t->za);
}
3.
,
:
) ;
) .

( , )
- :
#include <stdio.h>
#include <conio.h>
struct student
{
char fio[10]; //
int est1; //
} gruppa[25]; //
void main(void)
{
int i,j,k,priznak;
clrscr();
printf("\n 25 ");
/*------ ----------*/

for (i=1;i<=25;i++)
{
printf("\n %d \
\n (0- )\
\n",i);
printf("\n : ");
fflush(stdin); //
gets(gruppa[i].fio);
printf("\n y : ");
fflush(stdin);
scanf("%d",&gruppa[i].est1);
k=i; //
//
printf(" \n ? ");
scanf("%d",&priznak);
k=i;
if(!priznak)break;
}
/*--------- ------------*/
for (i=0; i<25; i++)
{
printf("\n ?\n");
scanf("%d",&j);
if(j>k)
{
printf("\n ! ");
continue; //
}
//
printf(" \n : %s \n",gruppa[j].fio);
printf(" \n , \
: %d",gruppa[j].est1);
printf("\n ? ");
scanf("%d",&priznak);
if(!priznak)break;
}
puts("\n ! Press any key...");
getch();
}

1. ?
2. scanf() gets(), printf() puts()?
3. ?

6


.
. ..
().

:

<_> <_>(<> <>, <> <>);


,
.
fun :
float fun(int, float, int, int);
,
( ).
:
<_> <_>( )
{

}
,
return. ,
int. ,
. ,
.
return
.
. , return,
.
.
, :
int mini(int x, int y)
{ int t;
if (x<y) t=x;
else t=y;
return t;
}
mini :
mini(int x, int y)
{
return (x<y)? x:y;
}
, int.
, ,
, .
, ,
.
,
void ().
,
:
void lin(char a)
{
int k;
for(k=0; k<80; k++)
printf(%c, a);
}
,
void. ,
: void main(void).

,
. , goto
.
:
<_>(_)
, , (
).
,
. ,
( )
.

, ,
. : ,
. ,
. .
.
, .
, .
- .
,
. .

(auto), (extern), (static), (register).
(auto, extern, static, register),
. , register int a;
( )
auto .
, ..
, .

. .
.
, .
,
.
, . -
*.
, x y:
void z1(int *x, int *y)
{ int t;
t=*x;
*x=*y;
*y=t;
}
:
int a=2, b=3;
void z1(int*, int*);

printf(\n a=%d, b=%d, a, b);

z1(&a, &b);
printf(\n a=%d, b=%d, a, b);


, .. :
a=2, b=3
a=3, b=2
.

n!=1*2*3**n:
fac(int n)
{
int b;
if (n= =1) return 1;
b=fac(n-1)*n;
return n;
}
,
.
, .
, , , ,
, type type t, type z
:
type (*p)(type1 t1, type2 t2);
.
:
void main (void)
{
int vec [20];

fun(vec);

}
void fun(vec_pav)
int vec_pav [ ];
{

}
:
void main(void)
{
static int mos [2][3]={{1,2,3}, {4,5,6}};

fun (mos);

}
void fun(mos_per)
{
int_mos_per [ ][3];
..

}

NxN ( 50)
.
#include <stdio.h>
#include <conio.h>
void summa(int, int a1[ ][50]);
void main(void)
{
int a[50][50];
int i,j,N;
clrscr();
puts("\n N (<50)\n");
scanf(%d,&N);
printf("\n \n");
for(i=0; i<N; i++)
for(j=0; j<N; j++)
{
printf("\n a[%d][%d]=", i+1, j+1);
scanf("%d", &a[i][j]);
}
summa(N,a);
}
void summa(int n, int a1[ ][50])
{
int i,j,s;
puts("
summa
");
/* */
for (s=0,i=0; i<n; i++)
{
printf("\n");
for (j=0;j<n;j++)
if (a1[i][j]>0)
s+=a1[i][j];
}
printf("\a = %d, Press any key... ",s);
getch();
}

1. ?
2. ?
3. ?
return ?

7
, .
,
.

, , ..
, : , ..
fopen.
, B:\LR7.CPP, .
, .. , .
. :
FILE * ;
.
FILE *f;
f=fopen ("B:\LR7.PP", "w");
"w" .
LR7.PP B:\ .
,
:

R
. ,
.
W
. ,
, ,
.
A
.
r+
. ,
.
w+
, r+.
a+
, a, .
.
T
. r, w, a, r+, w+, a+.
B
. r, w, a, r+, w+, a+.
,
-, : , : -, .
.
, .
flose. , :
fclose (f);
, :
Void fcloseall(Void);
,
, , .
freopen, stdio.h FILE* freopen (char filename,
chov*mode, FILE *stream). , stream (
fopen), filename mode,
stream.
, ..
,
. tmpfile
:
FILE* tmpfile (void).
tmpfile w+b
FILE.
.
/ :

1. -,
2. -,
3. - .

, .

-
-
.


int fgets(FILE *fp)

int fgetchov(void)
stdin.
int ungetc(int ch, FILE *fp)
ch .
.
int fputs(int ch, FILE *fp)
ch .
-.
- (
) .


int gets (char *S)
stdin S
, ' \n ',
.
int fgets (char *S int m, FILE *fp) , fp,
S ,
' \n ' m .
int fputs (char *S, FILE *fp)
S ,
-,
' \n ' .
int puts (char *S)
, stdout S ,
-,
' \n '.
-
- .


int fread (void *ptv, int n size fp,
size, int n, FILE *fp)
, ptv (
).
int fwrite (void *ptv, n size ,
int size, int n, FILE ptv, fp.
*fp)
. ,
, :
#include <stdio.h>
#include <conio.h>
void main(void)
{
int a=1, b=20, c, d;
FILE *in, *out, *add;
clrscr();

/* ........ ......*/
in=fopen("lr8.dat","wb");
fprintf(in,"%d %d \n",a,b);
fclose(in);
puts(" a, b ");
puts("Press any key...");
getch();
/* ......... ........*/
out=fopen("lr8.dat","rb");
fscanf(out,"%d%d", &c, &d);
printf("\n a=%d b=%d ", c, d);
fclose(out);
puts("\n ");
puts("Press any key...");
getch();
/* ......... ..........*/
add=fopen("lr8.dat","a");
puts(" c d");
scanf("%d%d",&c,&d);
fprintf(add,"%d %d \n",c,d);
printf("\n c=%d d=%d \n ",c,d);
fclose(add);
puts(" c d ");
puts("Press any key...");
getch();
/* ......... ........*/
out=fopen("lr8.dat","rb");
fscanf(out,"%d%d%d%d", &a, &b, &c, &d);
printf("\n a=%d b=%d ", a, b);
printf("\n c=%d d=%d ", c, d);
fclose(out);
puts("\n !");
puts("Press any key...");
getch();
}


.
.
.
, ,
. ,
.
:
class Cat{
public:
double weight;
void SetWeight (double w);
int GetWeight (){return weight; };
};

class , Cat - , public: -


( ), weight - , SetWeight SetWeight .
, Cat(), weight()
, SetWeight( ) GetWeight( )
.
( ) - GetWeight ()
. ,
inline- C++, ,
. , .
.h , .cpp .
.cpp #include. ,
MyClass.h,
:
#include MyClass.h
void Cat::SetWeight (double w){ if (w>=0) weight=w; };

, .
#include,
MyClass.h.
. , ,
( ).
:
Cat Murka;//
Cat* pBarsik;// Cat
pBarsik = new Cat;//
, , C++.
. Murka. pBarsik - Cat. new
, Cat
, pBarsik.
, , .
Murka.SetWeight(4.2);
Cout<< Murka.weight;
pBarsik-> SetWeight(7.0);
cout<<pBarsik-> GetWeight();
(
, ).
,
. ,
.
,

. , ,
.
.
, . .
X .
- X, ,
,

X.
, X , - SetX(),
- ,
- .
ANSI C++
.
private () - -,
( ), - (
- -, ..).
public () - -,
( ), , .
protected () - -,
( ) - , ( - -, .).
(private: , public: protected:)
, .
, ,
private. , (. List.h)
CList( ). FirstNode count
private, . public,
.
ANSI C++ -.
- .
const, ,
. (. 1.1), CList GetCount()
.
, ,
, .
.
, , -
, .

,
( - ). ,
. , ,
, , .
, .
- .
-,
,
, . - .
, new
( , ).
- . , ,
(
). 100
, ,
. -.
ANSI : ,
, .

-,
, , ,
. , , .
, .
-,
~.
,
CList (. 1.1).
, : CNode M(3.5); :
CNode *pM;
pM= new CNode(2.1);

, ,
. , ,
. - ,
( -
). ,
, -
. (. 1.1), Dog - pAge,
,
. pAge
pAge ,
.


Dog

pAge


Dog
pAge

1.1
, .
, ,
, (. 1.2). , pAge
() , .



5
Dog
Dog
pAge

pAge

1.2
,
( , ,
, ).



5
Dog
Dog
5
pAge

pAge
1.3

,
. :
Dog(const Dog & rhs);
Dog- , rhs- Dog
( , , rhs ,
). rhs (right-hand side ).
( - ,
), . -
List.h(. 1.1).
.
( , , , ..).
, ( ), -
().
(. 1.1) CList() CNode()
, . C++
C(class). CList . FirstNode
. -, .
1.1
//
List.h
#include <iostream.h>
class CNode ;
//
class CList
/* (-)*/
{
CNode *FirstNode;
//
unsigned int count;
//
public:
CList(){count=0;FirstNode=NULL;}; //
~CList(){ Clear(); };
//
CList(const CList& rhs);
//
void AddNode(double value); // .
void AddNode();
//
bool DeleteNode(unsigned int index);/* index*/
void Clear(); //
CNode* GetNode(unsigned int index); );/* index*/
unsigned int GetCount()const {return count;};/* */
};
class CNode
/* */
{
double value;
//
CNode * Next;
//
public:
CNode() {value=0;Next=NULL;}; //
~CNode(){};
//
CNode(double val) { value=val; Next=NULL;}; /* */
void SetValue(double val){value=val;}; //
double GetValue(){return value;};
//
CNode* GetNext(){return Next;};// .
void SetNext(CNode*Nex){Next=Nex;}; /* */
};


1. .
/?

2.