.


:




:

































 

 

 

 


Device. put (char_var);, 1




 

++; - , ; ; .

 

 

1.2

 

, , , ++ , ++ . 䳿, ' , . .

++ :

- ;

- ;

- .

- . , , , , , . - . , . , , #include <iostream.h>.

, ( )

 

.

1.2.1

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

cin :

cin [ >> values ];.

, x y :

cin >> x >> y;.

>> . :

¾ , , ( hr ' ) ENTER;

¾ ( ), , , , ( hr) ;

¾ ;

¾ ( ENTER);

¾ , . , :

2.345 789

2.345

, , , , . : getline(), read(), get() . ( ). ++ - , - .

1.2.2 ++

. <<, ' cout. , ,

cout << x;

x ( ). .

cout ++

cout << data << [ data ];,

data ¾ , , .

cout , , :

out << "y=" << x + a - sin(x) << "\n";.

++ \n endl, :

out << "y=" << x + a - sin(x) << endl;

, .

out << "p =" << (a && b || c) << "\n";.

++ . "\n" , , 10 ( ). , :

#define sp " "

#define ht "\t"

#define hl "\n"

:

out << " y = " << x + a - sin(x) << hl;.

', cout . , cout, :

cout << " \n";

cout << " << endl;.

 

1.1 , , :

//P1_1.CPP (

//

#include <iostream>

Using namespace std;

Int main ()

{

char first = 'W';

char middle = 'P';

char last = 'S';

int wozrast = 20;

int doplata = 2;

float zarplata = 309.75;

float prozent = 8.5;

//

cout << " \n";

cout << first << middle << last << "\n\n";

cout << " ³ : \n";

cout << wozrast << ' ' << doplata << ' ' << zarplata << ' ' << prozent;

Return 0;

}

. , \t ' ( ), :

cout << " ³ \t \t \t \t \n";

cout << wozrast<<"\t" << doplata<<"\t"<< zarplata<<"\t"<< prozent<<"\n ";

: setw(n) setprecision(k). setw(n) , ( n - ). Setprecision(k) .

' cout, . ֳ . ' , , , , , :

cout << 456 << 789 << 123;

: 456789123, .

 

1.2 setw.

// P1_2.CPP (

//

#include <iomanip>

#include <iostream>

Using namespace std;

Int main ()

{

cout << 456 << 789 << 123 << endl;

cout << setw(5) << 456 << setw(5) << 789

<< setw(5) << 123 << endl;

cout << setw(7) << 456 << setw(7) << 789

<< setw(7) << 123 << endl;

Return 0;

}

:

456 789 123

456 789 123

' iomanip, , setw. setw, ++ . , ++ .

setprecision(2) ++ , , , , ,

out << setw(7) << setprecision (2) << 123.456789;

: 123.46.

1.3 .

// P1_3.CPP ¾ :

//

#include <iostream>

#include <iomanip>

Using namespace std;

Int main ()

{

float prod_sum; //

Float nalog;

//

cout << " ";

cin >> prod_sum;

nalog = prod_sum* 0.7; //

cout << " " << setprecision(2) << prod_sum;

cout << " " << setprecision(2) << nalog<< "\n";

Return 0;

}

, cout , ' .

++ . scanf, ¾ printf. ' , ,

#include <stdio.h>

 

1.3 ++

++ ";", . ++.

- ¾ , :

++i; //

swap (&a, &y); //

:

p =a;

p =a = b = c;

p ¾ ' ; , b, ¾ ,

.

:

If (L)

1;

Else

2;,

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

, :

if (i < j)

i++;

Else

{ j = i - 3; i +=2; }

 

;

Switch (L)

{

case ..1: 1; [break;]

case ..2: 2; [break;]

.........................

case ..n: n; [break;]

[default: n+1;]

},

switch, case, default ¾ ;

break ¾ (') switch;

L ¾ - ;

..1,,..n ¾ , . ;

1;... ¾ - ++.

: L, ( ) ..1,.. L .. , break. break, , .. , switch. L .., default switch. , default ( '), L .., switch.

switch:

int a=2;

Switch (a)

{

case 1: func1();

case 2: func2();

case 0:

case 4: func3();

default: printf ("gd bay \n");

}

 

: func2, func3 default: printf ("good bay \n");.

:

int a=2;

Switch (a)

{

case 1: func1(); break;

case 2: func2(); break;

case 0:

case 4: func3(); break;

default: printf ("good bay \n");

}.

case 2: func2(); break; switch.

++ : while, do, for.

while L

L ¾ - , (- ).

: L (), , ( ), while .

while.

 

1.3: :

Y= A*X*X-SIN(X), A=10.3; X[-1; +1]; hx=0.2.

 

// P1_6.CPP ( y = a* x* x sin (x)

// while

#include <stdio.h>

#include <math.h>

Void main ()

{

Float a, x, y;

a = 10. 3;

x = - 1;

while (x <= 1)

{

y = a * x * x - sin(x)

printf ("x = % 4 f, y = % 6 f \n", x, y);

x = x + 0.2;

}

}

 

for :

 

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

1 ¾ , ; (' );

2 ¾ , (' );

3 ¾ , , (' ).

:

¾ ( for);

¾ ( ( ), ;

¾ ;

¾ ;

¾ , , for.

, , .

for 1.3:

// P1_7.CPP ( y = a * x * x - sin(x)

// for

#include <stdio.h>

#include <math.h>

Void main ()

{

Float a, x, y;

a = 10.3;

for (x = -1; x <= 1; x = x + 0.2)

{

y = a * x * x - sin(x);

printf ("x = % 4 f, y = % 6 f \n", x, y);

}

}

 

for , , - , :

 

Int i;

for (; i < 4; i++)

Int k, n, y;

for (k = 0, n = 20; k <= n; k++, n--)

y = k * n;

. k = 0 n = 20. k <= n. , , k++ n--, , .

do , , :

Do

{

}while (L);,

L ¾ .

do : ( ), L , ( ), , ¾ . do 1.3 :

 

// P1_8.CPP ( y = a * x * x - sin(x)

// do

#include <stdio.h>

#include <math.h>

Void main ()

{

Float a, x, y;

a = 10.3;

x = -1;

Do

{

y = a * x * x - sin (x);

printf (" x = % 4 f, y = % 6 f \n ", x, y);

x = x + 0.2;

}

while (x <= 1);

}

 

1.5

 

1. ++?

2. ++?

3. ++?

4. ++, ?

5. ++?

6. - ?

7. ?

8. ?

9. switch?

10. , for?

11. do while?

 

 

1.6

 

, .

1.

2.

 

3.

=5; b=3;

4.

 

5.

 

6.

 

7.

8.

 

9.

 

10.

 

11.

 

12.

 

13.

 

 

14.

 

15.

x a .

 

16.

- 0.1 x .

 

17.

 

 

18.

 

.

 

19. ϳ , .





:


: 2015-11-05; !; : 442 |


:

:

, .
==> ...

1758 - | 1624 -


© 2015-2024 lektsii.org - -

: 0.15 .