.


:




:

































 

 

 

 


int *p; // int

abs
acos
asin
atan
atan2
ceil
cos
random 0 .
exp
fabs ( )
floor
fmod
frexp .
ldexp
log
log10 10
modf(x, p) ( )
pow(x, y) x y, xy
sin
sinh
sqrt
tan
tanh

 

 

6. 123456 int. * . .

 

 

#include <iostream>

using namespace std;

int main(){

setlocale (LC_ALL, "RUS");

int a = 123456;

cout<<a<<endl;

cout<<(a/100000);

cout<<(a/10000)%10;

cout<<(a/1000)%10;

cout<<"*";

cout<<(a/10)%10;

cout<<a%10;

cout<<endl;

return 0;

}

 

7. 541069 int. . .

 

#include <iostream>

using namespace std;

int main() {

setlocale (LC_ALL, "RUS");

int a = 541069;

int max = -99999;

int min = 99999;

cout << a << endl;

int d = a % 10;

if(max < d)

max = d;

cout << max << endl;

int b = (a / 100) % 10;

if(min > b)

min = b;

cout << min << endl;

return 0;

}

 

8. . 650123 int. : 1- 3; 2- 2; 3- 1; 4- 0; 5- 5; 6- 6. .

#include <iostream>

using namespace std;

int main(){

setlocale (LC_ALL, "RUS");

int a = 650123;

cout<<a<<endl;

cout<<"1 "<<a%10<<endl;

cout<<"2 "<<(a/10)%10<<endl;

cout<<"3 "<<(a/100)%10<<endl;

cout<<"4 "<<(a/1000)%10<<endl;

cout<<"5 "<<(a/10000)%10<<endl;

cout<<"6 "<<a/100000<<endl;

return 0;

}

 

9. . .

 

, .

int *p; // int

.

.

- , , , , . , C++. , .

 

:

int a;

a = 7;

int *mas = new int[a];

 

 

10. . , N , - . INPUT.TXT N . , N . :̻ - , :̻ - . , .

#include<iostream>

#include<fstream>

using namespace std;

int main(){

setlocale(LC_ALL,"Russian");

ifstream in("pks.txt");

char q;

int kol;

in>>kol;

int **mass, h, m;

mass = new int *[kol];

for(int i=0;i<kol;i++)

mass[i]=new int [2];

 

for (int i =0; i < kol; i++){

in>>h>>q>>m;

mass[i][0] = h*60+m;

 

in>>h>>q>>m;

mass[i][1] = h*60+m;

cout<<mass[i][0] << " " << mass[i][1]<<endl;

}

for (int i = 0; i < kol-1; i++)

if (mass[i][0] > mass[i+1][0]){

h = mass[i][0];

mass[i][0] = mass[i+1][0];

mass[i+1][0] = h;

h = mass[i][1];

mass[i][1] = mass[i+1][1];

mass[i+1][1] = h;

}

for (int i =0; i < kol; i++){

cout<<mass[i][0] << " " << mass[i][1]<<endl;

}

h = 0;

m = 0;

int max=0;

for (int i = 0; i < 1439; i++){

if (i == mass[m][0]) {

h++;

m++;

if (m == kol) break;

}

if (h > max) max = h;

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

if (i == mass[j][1]) h--;

}

cout<<max<<endl;

for (int i = 0; i < kol; i++) delete [] mass[i];

delete [] mass;

return 0;

}

 

 

11. . N

. , y . ( , . , .) , , , N .

 

#include<iostream>

#include<math.h>

using namespace std;

 

int main() {

int x1, x2, n, k;

int t1, t2;

int tmin=9999, tmax;

cin>>x1>>x2>>n;

if(x1<x2){

k=x1;

n--;

}

 

else {

k=x2;

n--;

}

 

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

t1=x1*i;

t2=x2*(n-i);

if (t1 < t2) tmax=t2;

else tmax=t1;

 

if(tmin > tmax) tmin=tmax;

}

cout<<tmin+k<<endl;

return 0;

}

 

12. ++. include, define.

 

++ , , , - . ++ ,

++ .

 

, #include. . , .

 

#define , . , . :

#define _ _

, . . .

, TRUE 1, a FALSE 0 :

#define TRUE 1
#define FALSE 0

, TRUE FALSE, 1 0 .

 

13. .

 

  • C++ , , .
  • , .
  int A[10]; // int struct MyStruct { int A; char C[10]; }; MyStruct obj1[10]; // MyStruct //

 

14. .

 

#include<iostream>

using namespace std;

int main(){

int n;

cin>>n;

int a[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};

char r[][3] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};

for(int i=0; i < 13; i++){

while(n>=a[i]){

cout<<r[i];

n-=a[i];

}

}

return 0;

}

 

15. .

 

#include<iostream>

using namespace std;

int main(){

char n[20];

cin>>n;

int a[] = {1000, 500, 100, 50, 10, 5, 1};

char r[] = {'M', 'D', 'C', 'L', 'X', 'V', 'I'};

int res[20];

for (int i = 0; i < 20; i++) res[i] = 0;

for (int i = 0; n[i]!= '\0'; i++) {

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

if(r[j] == n[i]) res[i] = a[j];

}

int summ=0;

for (int i = 0; i < 19; i++){

if (res[i] < res[i+1])

summ-=res[i];

else

summ+=res[i];

}

cout<<summ<<endl;

for (int i = 0; i < 20; i++)

cout<<res[i]<< " ";

return 0;

}

 

16. ( 1755).

 

#include<iostream>

#include<math.h>

using namespace std;

int main() {

setlocale(LC_ALL, "Russian");

int a=1755;

long double res=1;

int m[5000];

for (int i=0; i<5000; i++){

m[i]=0;

m[0]=1;

}

for (int i=1;i<=a; i++){

for (int j=0; j<5000; j++){

m[j]*=i;

}

for (int j=0; j<5000;j++){

if (m[j]>10){

m[j+1]+=m[j]/10;

m[j]=m[j]%10;

}

}

}

bool b=true;

for (int i=4999;i>=0;i--){

if (m[i]==0 && b==true)

continue;

else

b=false;

cout<<m[i];

}

return 0;

}

 

17. , .

#include <iostream>

using namespace std;

int main() {

double a[3] = { 1, 2, 3 };

double b[3] = { 4, 5, 6 };

double c[3] = { 0 };

c[0] = a[1] * b[2] - a[2] * b[1];

c[1] = a[2] * b[0] - a[0] * b[2];

c[2] = a[0] * b[1] - a[1] * b[0];

cout << c[0] << " " << c[1] << " " << c[2] << " ";

return 0;

}

 

18. new.

New C++, . , new, new , , .

 

19. . .

++ , . , .

++ , : =.

  1. += -;
  2. -= -;
  3. *= -;
  4. /= -;
  5. %= - ;

20. for.

. , - . , , .

++ :

  • for
  • while
  • do while

, (. . true).

  // for: for (1; ; 3){ /* */; }   21. while. while while, , while .
  // while while (/* while*/) { /* */; /* */; }

true, ,

.

 

22. .

a == b

a!= b

a > b

a < b

a >= b

a <= b

 

23. .

, ( ) , . , , . , , , .

 

24. . .

, ( ) 2 :
,
.

3 C++:
,
,
.

void func1 (int arg);

void func2 (int * arg);

void func3 (int & arg);

 

25. .

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

#include <stdio.h>
void display(int num[10]);
int main (void) /* */
{
int t [10], i;
for (i=0; i<10; ++i) t[i]=i;
display(t);
return 0;
}

 

26. .

 

, , char int. float, double, long double, void .

4.3.

~ ~expr
<< expr1<<expr2
>> expr1>>expr2
& expr1 & expr2
^ expr1 ^ expr2
| expr1 | expr2
&= expr1 &= expr2
^= expr1 ^= expr2
|= expr1 |= expr2
<<= expr1 <<= expr2
>>= expr1 >>= expr2

 

 

27. . , , .

#include <iostream>

using namespace std;

void main() {

setlocale(LC_ALL, "Russian");

char str[2000];

cin.getline(str, 2000);

out << endl;

int a[256];

for (int i = 0; str[i]; i++) {

a[str[i]]++;

}

for (int i = 0; i < 256; i++) {

if (a[i])

cout << " " << char(i) << " " << a[i] << " " << endl;

}

system("pause");

}

 

28. ++

 

++ , .
.

. , , .

  2 struct TPoint // TPoint. { int x; // int y; // }; // void main() { TPoint O; // O TPoint }  
   
         

29. .

C - C++, C++. - , C++- . C- , , , int). , , , . . . -:

(type) val

, type val

 

30. . INPUT.TXT . , . :MM, , . . . 120, 59. , (, )

 

#include <iostream>

#include <fstream>

using namespace std;

int main() {

setlocale(LC_ALL, "RUSSIAN");

ifstream in("input.txt");

int h, m, h1, h2, m1, m2, h3, m3;

int d = 0;

char q;

in h q m;

in h1 m1;

h2 = h + h1;

m2 = m + m1;

if (m2 >= 60) {

m2 = m2 - 60;

h2++;

}

if (h2 >= 24) {

h2 = h2 - 24;

d++;

}

cout << " : " << d<< ": "<< " | " << h2 << q << m2;

return 0;

}

 

 

31. .

ifstream , ofstream fstream . / /, , / , . / cin cout, / , cin cout.

, ++. :

  1. ofstream;
  2. , ;
  3. ;
  4. .

ofstream, ifstream? , , , ifstream.

// ofstream /* */; // ofstream

fout, :

ofstream fout("cppstudio.txt");

? , . , , .

open(), . . , . , , . :

fout << " ++"; //

fout ++ . , , .

fout.close(); //

++.

 

32. . .

, , . , , . . Web- , , . , , , - . .

, . , () , , , ( ) ( ). : n!, .

 

33. , , -.

++ char, - \0 .

char str[] = "- "; // '\0'

 

cout << str << endl;

 

. . , 11 , 12, \0 . . , , : cout << str << endl; cout , \0 . ( \0) . , - \0.

 

34. .

 

35. .

 

, , . , , .

#include "stdafx.h"

#include <iostream>

using namespace std;

 

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

{

int value = 15;

int &reference = value; // value

cout << "value = " << value << endl;

cout << "reference = " << reference << endl;

reference+=15; // value

cout << "value = " << value << endl; // , , ,

cout << "reference = " << reference << endl; //

system("pause");

return 0;

}

 

 

36. . .

 

37. .

 

, ( ) . .

#include "stdafx.h"

//

int main() { // main

//

}

 

 

38. .

++ , if else. ?: ( ( ), C++).

C++
""? " 1": " 2";
, 1, ( ) 2.
:

a > b? cout << a: cout << b; // > b, cout << a, cout << b

, , > b , b. , . , if else .

 

39. . . .

 

40. .

, . , . . . , ++ &. , , . , ( , ), , , , . , , . , , . , .

int var = 123; // var 123

int *ptrvar = &var;

 

41. if.

if , - , , .. ++ if.

. , , .

 

42. switch.

:

default switch() case. , case. , , . .

switch(), default case, break . . , break !

default . switch() . , case , switch(), , switch()

case , . case b:, case G:, case + ..

 

43. . . .

, :

1. .

2. .

3. .

, .

main. .

, , .

, , , , , ( , , ).

.

:

_ _ (_1, _2,...);

_ (, ) void, .

_ .

_N (, ) N-oro .

:

int max (int, int);

double cube (double)

float massa();

void printarr(*int, int);

, , .

, . . void, (, - ).

44. . , . , . . . ( ), ; . , , , .

 

 

#include <math.h>

using namespace std;

int main() {

double xc, yc; //

double xd, yd; //

double xn, yn; //

double kol, nora = 0; //kol -

int n = 0;

cin>>xc>>yc>>xd>>yd>>kol;

for (int i = 0; i<kol; i++) {

cin>>xn>>yn;

double s = sqrt((pow((xn - xc), 2) + pow((yn - yd), 2)));

double d = sqrt(((pow((xn - xd), 2) + pow((yn - yd), 2) / 2)));

if (s<d) {

nora = i;

break;

}

}

if (n>0)

cout<<"Suslik spassya v"<<n<<" nore"<<endl;

else

cout<<"-"<<endl;

return 0;

}

 

 

45. 437 . N . , . INPUT.TXT N. N - , . , , . , .

 

#include <iostream>

#include <fstream>

using namespace std;

int main(){

int avtobus=437;

int mosti;

int mostiVis[100];

int sloman, nomerMosta;

 

ifstream in("input.txt");

 

in>>mosti;

 

for (int i=0; i<mosti; i++){

 

in>>mostiVis[i];

 

if (mostiVis[i]<avtobus){

sloman=mostiVis[i];

nomerMosta=i+1;

break;

}else{

sloman=0;

nomerMosta=0;

}

 

}

if (sloman == 0){

cout << " " <<endl;

}else{

cout<<" "<<endl;

cout<<nomerMosta<<" "<<endl;

}

return 0;

}

 

46. NxM. 1 N*M , ( ).

 

 

#include<iostream>

#include<math.h>

 

using namespace std;

 

void main() {

 

setlocale(LC_ALL, "Russian");

 

const int m = 8, n = 6;

int arr[m][n];

int num1 = 0, num2 = n - 1, num3 = 0, num4 = m - 1;

int param = 0;

 

while (param < m*n) {

for (int i = num1; i <= num2; i++) {

param++;

arr[num3][i] = param;

}

num3++;

 

for (int i = num3; i <= num4; i++) {

param++;

arr[i][num2] = param;

}

num2--;

 

for (int i = num2; i >= num1; i--) {

param++;

arr[num4][i] = param;

}

num4--;

 

for (int i = num4; i >= num3; i--) {

param++;

arr[i][num1] = param;

}

num1++;

 

}

 

for (int i = 0; i < m; i++) {

for (int j = 0; j < n; j++) {

cout << arr[i][j] << " ";

}

cout << endl;

 

}

system("pause");

}

 

 



<== | ==>
қ ғ ә қ ғ ғ | 
:


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


:

:

, .
==> ...

1593 - | 1386 -


© 2015-2024 lektsii.org - -

: 0.344 .