.


:




:

































 

 

 

 





 

++; , ++; ; .

 

 

1.2

 

, , ++ [17, ].

 

1.2.1 VISUAL C ++

 

Visual C++ Windows. . . Visual C++ . , , . ( ) ++. .

 

:

1. Visual C++.

2. File/New, New.

3. Projects Win32 Console Application.

4. Project Pro1, Location .

5. New. Pro1 Pro1.dsw, Pro1.dsp.

6. , , File/Open Workspaces .dsw.

7. Pro1.cpp File/New, Files.

8. C++ Source File, Pro1.cpp Filename , Add to project ! . Pro1.cpp Visual C++.

9. . pp , .cpp . cpp, . Far.

10. ++ Build/Build Pro1.exe F7.

11. Build/Execute Pro1.exe Ctrl+W.

12. . , . .

³ Build/ Start Debug /Configurations.

 

, , . ++ #include< .h>, main() , , , . ++ :

#include< .h>

Int main()

{ ;}

int , . Գ , .

 

. , , . ++ :

/* */ ,

// .

 

. , , . , . , . . , .

. .

ᒺ , , . , . - , , ++ . ' , , . , , ' ().

.

1.1

Intel

,
bool   true (1) false(0)
unsigned short int   0 65 535
short int   32 768 32 767
unsigned long int   0 4 294 967 295
long int   2 147 483 648 2 147 483 647
int (16 )   32 768 32 767
int(32 )   2 147 483 648 2 147 483 647
unsigned int (16 )   0 65 535
unsigned int (32 )   0 4 294 967 295
char   0 256
float   1.2-38 3.438
double   2.2-308 1.8308
long double   3.4-4932 3.4 4932
void 2 4 -

 

,

bool dd = true; dd=1;

bool dd1 = 1; dd1=true;

int a = 1, b = 0; a = 1, b = 0;

har sim =A; sim =A;

float Age = 18.5; Age = 18.5 , ;

void MyFunction(); , .

 

, , , 񳺿 . :

onst [] = ;

:

const double Pi = 3.1415; // Pi 3.1415;

const a=1; // int.

 

. - . - : . , . , :

#include <iostream>.

, ( ). , , , , , .

++ , istream iostream. std::cin , . , >> . , char.

cin :

std::cin [ >> values ];

, :

std::cin >> x >> y;

. <<, ' std::cout. , :

std::cout << x;

x ( ). .

cout ++:

std::cout << data [ << data << "\n"];

data ¾ , , "\n" . std:: , cin cout std. , using:

using namespace std;

: setw(n) setprecision(k). setw(n) , ( n - ), s etprecision(k) . <iomanip.h>.

scanf < stdio.h >. scanf , , . & . , &x " x ", , . scanf , . %, , , . scanf .

:

scanf (" ", );.

< stdio.h >. , . printf . ( ), , , '.

, , %: . , , , :

printf (" , b, : %d %d %d \n", a, b, c);

d , .

, :

% - ;

% s - ;

% x - ;

% 0 - ;

% f - , .

 

++ #include <math.h>

1.2

<math. h>

 

'
double acos (double _x); acos (x)
double asin (double _x); asin (x)
double atan (double _x); atan (x)
double atan2 (double _y, double _x); atan2 (y, x) y/x
double ceil (double _x); ceil (x)
double cos (double _x); cos (x) x,
double cosh (double _x); cosh (x) ,
double exp (double _x); exp (x) e, e x
double fabs (double _x); fabs (x) |x| double
double floor (double _x); floor (x) , x
double fmod (double _x, double_y); fmod (x) x y
double log (double _x); log (x)
double log10 (double _x); log10 (x)
double pow (double _x, double_y); pow (x, y) x, x y
double sin (double _x); sin (x) x,
double sinh (double _x); sinh (x) ,
double sqrt (double _x); sqrt (x) x, x>0
double tan (double _x); tan (x) x, x
double tanh (double _x); tanh (x) ,
int abs (int _x); abs (x) x int
double atof (const char*_s); atof (s)
double hypot (double_x, double_y); hypot (x, y) (x2+y2)
long labs (long _x); labs (x) long |x|
double pow10 (int _p) pow10 (p) 10

 

1.1 , .

#include <iostream>

int main()

{

const double Pi = 3.1415;

float Rad; double Square;

std::cout<<"Input radius, radius =";

std::cin>>Rad;

Square = Pi*Rad*Rad; // Square = Pi*pow(Rad,2);

std::cout<<"Square = "<<Square<< std::endl;

std::cin.get();//

std::cin.get();

return 0;

}

 

:

If () 1;

lse 2;

. ( ), 1, , 2; , else .

++ : while, do, for.

while () ¾ - , , .

: (), , (), while .

for :

for ([1;] [2;] [3]) ;

1 , ; (' ); 2 , , (' ); 3 , , (' ).

:

( for);

;

( ), ;

;

;

(), , for.

, , .

do , , :

Do

While ();

¾ .

do : ( ), , , ( ), , ¾ .

1.2

a b (a < b).

#include <iostream>

int main()

{

int sum=0, a, b, i;

std::cout<<"Vvedi a, a=";

std::cin>>a;

std::cout<<"\nVvedi b, b=";

std::cin>>b;

for (i=a; i<b; i+=2)

sum +=i;

std::cout<<"Summa dorivnue Sum= "<<sum;

std::cout<<"\n";

std::cin.get();

std::cin.get();

return 0;

}

 

1.3

1. ++.

2. ?

3. ?

4. ?

5. ?

6. ?

7. .

 

 

1.4

1. .

:

1. ha hb,hc

p=(a+b+c)/2.

i i.

2. =1,45; y=-1,22; z=3,5.

3. z=(sin x3 +cos2y); =1.2, =-0.8.

4. ᒺ : ; R,r,h i.

5. a =-0,5; b =1,7; t =0,44.

6. a=1,5; b=15,5; x=-2,9.

7. ; a =16,5; b =3,4; x =0,61.

8. ; x =1,82; y =18,5; z =-3,4 9. R=x2(x+1)/b-sin2(x-a); a =0,7; b =0,05; x=0,43.

10. b=x(arctg z +e(x+3)); x,y,z i.

11. x =1,25; y =0,93.

12. x =0,25; y =1,31; a =3,5; b =0,9.

13. R=x3(x+1)/b2 sin2(x(x+a)); S = a =0,7; b =0,05; x =0,5.

14. y=sin3(x2+a)2 - z=x2/a+cos2(x+b)3; a =1,1; b =0,004; x =0,2.

15. m =2; c =-1; x =1,2; b =0,7.

16. x =0,25; y =0,79; z =0,81.

17. =3,2; b =17,5; x =-4,8.

18. K=ln(a+x3)+sin2(x/b); M=e -cx. a =10,2; b =9,3; x =2,4; c =0,5.

19.
a =0,3; b=0,9; x=0,53.

20. a =0,5; b =2,9; x =0,3.

21. a =0,5; b =3,1; x =1,4.

22. a =0,5; b =2,9; x =0,3.

23. m =0,7; x =1,77; a =0,5; b =1,08.

24. m =2,1; t =1,02; c =-1.

25. b=(1+tg2 (x/2))ln x; x =1,23; y =0,79; z =0,9.

26. x =10,3; y =4,93; z =0,4.

27. x =1,2; y =0,9; z =3,5.

28. x =-5,3; y =2,8; z =0,39.

29.

c =0,5; b = -0,5; x =0,61; y =1,2.

 

30. x=0,92; y =5,3; a =0,25.

 

 

2. , .

:

1.

2.

 

3. =5; =3;

 

 

4.

 

5.

 

6.

 

7.

8.

 

9.

 

10.

 

11.

 

12.

 

 

13.

 

 

14.

 

15.

x a .

 

16.

0.1 x . ϳ: .

 

17.

 

 

18. :

?

 

19. ϳ , .

 

20. 10 , .

 

21. ' , b, c .

ϳ:

 

22. ' , R (, b).

ϳ: :

 

23.

, ‌ x ‌ £ 5,

y =

x4 + 2x2 sin x, ‌ x ‌ > 5,

 

x Î [ -10; 10], hx =2

 

24. ϳ , .

 

25. .

26.

x2 + y2, x2 + y2 £ 1,

y = x2 + y, x2 + y2 > 1 y ³ x,

lg(x2 + y2), x2 + y2 > 1 y < x,

x Î [ 0,1; 1,3], hx =0,2; y Î [ 0,1; 1,3], hy =0,3.

 

27.

1 + a x < 0,

y = 0, x = 0,

1 - a x > 0,

 

x Î [ -10; 10], hx = 2; a Î [ 2; 12], ha = 0,95

 

 

28.

lg(), > 0, > 0, > 0,

y = 2, < 0, < 0, < 0,

1, ;

 

 

Î [ -3; 3], h = 0,5; Î [ -4; 5], h = 0,5; Î [ -2; 4], h = 0,5.

 

 

29.

x £ 3,5,

y =

x > 3,5,

 

x Î [ 2; 4,5], hx = 0,5; a = 1,42; d = 5,4; c = 3,15.

 

30.

 
 


x £ 0,

y =

, x > 0;

 

a = 1, b = 2, x Î [ -2; 2], hx = 0,5.

 


2

 

 

 

Visual C++ .

 

2.2

 

. ' . , '.

. mas, , 3, (!) . .

ҳ ' C++ , . , ', . [ ]. 0. :

int mas1[21]; char mas2[67];

mas1, 21 int mas2, 67 char.

C++ : .

, ' , - (mas1==&mas1[0]). , * . , i- mas1[i] *(mas1+i), (mas1+i)==& mas1[i].

++ - .

,j,k- :

b[][j][k]= = *(b[][j]+k)= =*(*(b[]+j)+k)= =*(*(*(b+)+j)+k).

, , ' - , - . ' , .

2.1 mas .

#include <iostream>

#include <conio.h>

int main()

{

const int n=5;

int mas[n];

std::cout<<"Vvedit "<<n<<" elemetiv massivu "<<std::endl;

int i;

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

{

std::cin>>mas[i];

}

int imin=0;

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

{

if (mas[imin]>mas[i])

imin=i;

}

std::cout<<"min="<<mas[imin]<<"\tindex="<<imin<<std::endl;

getch();//

return 0;

}

 

2.2 ³ mas 10 .

 

#include <iostream>

#include <conio.h>

int main()

{

int i, j;

const int n = 10;

float mas [n], rab;

std::cout<<"Vvd 10 elem \n";

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

std::cin>>mas[i]; // cin>>*(mas+i);

std::cout<< " Isxodnik\n";

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

std::cout<<mas[i]<<" "; // cout<<*(mas+i)<<" ";

std::cout<<"\n"; // cout<<endl;

//

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

for (j=0;j<n-1-i;j++)

if(mas[j]<mas[j+1]) // if(*(mas+j) <*(mas+j+1))

{

rab= mas[j]; // rab=*(mas+j);

mas[j] =mas[j+1];// *(mas+j)=*(mas+j+1);

mas[j+1]=rab;

} // *(mas+j+1)=rab;

//

std::cout<< " Otsort massiv\n"<<"\n";

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

std::cout<< mas[i]<<" "; // cout<<*(mas+i)<<" ";

getch();//

return 0;

}

 

2.3 matr 5*6 . .

#include <iostream>

#include <conio.h>

int main()

{

int i,j,sum,stk;

const int n =5, m=6;

int matr[n][m], mas[n];

std::cout<<"Input matr\n";

//

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

for(j=0; j<m; j++)

std::cin>> *(*(matr+i)+j);

//

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

{

sum=0;

for(j=0; j<m; j++)

{

sum+=*(*(matr+i)+j);

}

*(mas+i)=sum;

}

std::cout<< "Result mas\n";

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

std::cout<< *(mas+i)<<" ";

// mas

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

for(j=0; j < n-1-i; j ++)

if (*(mas+j)> *(mas+j+1))

{

stk=*(mas+j);

*(mas+j)= *(mas+j+1);

*(mas+j+1)=stk;

}

//

std::cout<< "\nResult otsortirov mas\n";

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

std::cout<< *(mas+i)<<" ";

getch();//

return 0;

}

 

2.4 n ( n ). 䒺 .

#include <iostream>

#include <conio.h>

int main()

{

int n,i;

int *mas;

std::cout<<"Vvedit kilkist' strok (n)\n";

std::cin>>n;

mas=new int[n];//

//

std::cout<<"Vvedit "<<n<<" elementiv massivu\n";

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

std::cin>>mas[i];

int kil(0);

//ϳ 䒺

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

if(mas[i]<0)

kil++;

std::cout<<"kil="<<kil<<"\n";

delete [] mas;//

getch();//

return 0;

}

2.5 n m ( n m ). .

 

#include <iostream>

#include <conio.h>

int main()

{

int n,m,i;

int **mas;

std::cout<<"Vvedit kilkist' strok (n) i stolbcov (m)"<<std::endl;

std::cin>>n>>m;

//

mas=new int*[n]; //

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

mas[i]=new int[m]; //

std::cout<<"Vvedit "<<n<<"x"<<m <<" elementi massiva"<<std::endl;

//

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

for(int j=0;j<m;j++)

std::cin>>mas[i][j];

//

for(i=0;i<n;i++,std::cout<<std::endl)

for(int j=0;j<m;j++)

std::cout<<mas[i][j]<<"\t";

int sum(0);

//ϳ

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

for(int j=0;j<m;j++)

if(mas[i][j]%2==0)

sum+=mas[i][j];

std::cout<<"sum=="<<sum<<std::endl;

//

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

delete[]mas[i];//

delete []mas; //

getch();//

return 0;

}

 

2.3

 

1. *(c+i), c ?

2. ++?

3. 䳿 ?

4. .

5. ?

 

3.4

 

1. .

2. ³ .

3. .

4. .

5. , , .

6. , .

7. , ?

8. ³ 䒺 .

9. ³ .

10. , . 3, .

11. .

12. .

13. , .

14. .

15. , 3, .

16. 䒺 .

17. 䒺 . .

18. , x. , 0.

19. D, .

20. . , .

21. , .

22. , , .

23. .

24. , .

25. , .

26. .

27. .

28. . ³ .

29. 3*3. " ".

30. .

 


++ , .

 

 

3.2

 

++ . . , ++ , #include <string.h>. .

char*strcat (char*_dest, const char*_src); dest src. (dest). \0 dest .

char*strncat (char*_dest, const char*_src, size_t_maxlen); maxlen , src, , dest. dest maxlen . maxlen src, .

char*strchr (const char*_, int_c); c , s. s \0.

int strcmp (const char*_s1, const char*_s2); , s1 s2. : , s1<s2; , s1==s2; , s1>s2.

int strnmp (const char*_s1, const char*_s2, size_t_maxlen); , strcmp () , maxlen .

int stricmp (const char *_s1, const char *_s2); , s1 s2. . : , s1>s2; , s1==s2; , s1<s2.

int strlen (const char*_s); , s. - .

char*stpcpy (char *_dest, const char *_src); , src, ', est. , dest.

char*strncpy (char*_dest, const char*_src, size_t_maxlen); maxlen , src, ', dest. - . maxlen src, src \0. , src , , , \0. dest.

char *strlwr (char *_s); , s, . .

char *strups (char *_s); , s, . .

char *strset (char *_s, int_ch); , s, ch. .

char *strtok (char *_s1, char *_s2); s1, s2.

 

 

3.1

ϳ , , , .

1-

#include <iostream>

#include <conio.h>

#include <string.h>

int main()

{

char s[]=" Repetitio est, mater studiorum!";

int i=0, col=0;

char spes[]=";!,.?\t";

int strLen = strlen(s);

while (i<strLen)

{

if (!strchr(spes, s[i]))

{

col++;

while (!strchr(spes, s[i]) && i<strLen)

i++;

}

else

{

while (strchr(spes, s[i]) && i<strLen)

i++;

}

}

std::cout<<"\nKilkist sliv="<<col<<'\n';

getch();//

return 0;

}

2- strtok

#include <iostream>

#include <conio.h>

#include <string.h>

int main()

{

int col=0;

char str[] = "Repetitio est mater studiorum. Help.";

char seps[] = ";,\t\n";//

std::cout<<str<<std::endl;

char *token = strtok(str, seps);//

while(token!= NULL)

{

col++;

token = strtok(NULL, seps);//

}

std::cout<<"\nKilkist sliv="<<col<<std::endl;

getch();//

return 0;

}

3.2

, a, . ϳ , .

. : , .

#include <iostream>

#include <conio.h>

#include <string.h>

int main()

{

char str[] = "test word 1: asdda. Test word 2: asdfg, word 3: Awea";

char strCopy[sizeof(str)];

strcpy(strCopy,str);//

char seps[] = ":?!;,.\t\n";//

std::cout<<str<<std::endl;

char *token = strtok(str, seps);//

int lenResult=0;

int countWord=0; //

//ϳ ' -

while(token!= NULL)

{

int last = strlen(token)-1;

if (

(token[0] == 'a' || token[0] == 'A')

&& (token[last] == 'a' || token[last] == 'A')

)

{

lenResult+= strlen(token)+1;

++countWord;

}

token = strtok(NULL, seps);//

}

char* resString = new char [lenResult];

resString[0]='\0'; //

strcpy(str,strCopy);//

token = strtok(str, seps);//

int curentNumberWord=0;

while(token!= NULL)

{

int last = strlen(token)-1;

if (

(token[0] == 'a' || token[0] == 'A')

&& (token[last] == 'a' || token[last] == 'A')

)

{

strcat(resString,token);

++curentNumberWord;

if (countWord!=curentNumberWord)//

{

strcat(resString," ");

}

}

token = strtok(NULL, seps);//

}

std::cout<<"\nResult:\n"<<resString<<std::endl;

delete[]resString;

getch();//

return 0;

}

 

3.3

 

1. ++?

2. - Visual C++.

3. ?

4. ++.

 

3 .4

 

1. " " "".

2. "" ""?

3. , .

4. , .

5. "" "".

6. , "".

7. , "".

8. , .

9. , ?

10. ?

11. , , .

12. , .

13. , ( ) .

14. , .

15. .

16. . , "*".

17. ϳ , .

18. .

19. , .

20. , .

21. .

22. , .

23. , .

24. , .

25. ( ) .

26. , ?

27. , .

28. , .

29. , .

30. 10 .

 


 

4

 

 

 

++ , .

 

4.2

 

, ' '. :

struct [_] {_1 __1;

_2 __2;...;

_n __n;};

_ ' , C++; _1, _2,..., _n ,; __1,..., __n - , .

_ ', . '





:


: 2017-02-25; !; : 2473 |


:

:

, , .
==> ...

1353 - | 1271 -


© 2015-2024 lektsii.org - -

: 0.766 .