.


:




:

































 

 

 

 





++ .

 

2. Ͳ ²Ҳ

 

, , , .

. . , - -. ³ () , . , , .

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

- , - . , :

Ø ( );

Ø (- );

Ø - ( );

Ø ( ).

, , . , , , . , , .

. , . , . ++. , , ++.

-. - . . - , . 璺 , . , , , , ( ). - , . - ʳ. - , 璺 (). - , . , , , , , ( ). , , , . . , , , . , - .1.

1.

/

. , - , , . . - - , , , . 璺 . . .

ϳ , - . , . , . , .

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

++ : if , if/else switch . ++ : while, do/while for. . ++ : , . ++ , .

2.2. ++

if , , 䳿, . :

if (<>) <>;

<>, , (, ), 0 (, ). ++ , TRUE FALSE ( ). TRUE ++ - , FALSE 0. , if : <> , <>, <> , , if .

if , ++ , , , , . ֳ , , 1, , , 0 . , , (, 䒺, ) n. , . , .

 

#include <iostream>

#include <conio.h>

 

void main()

{

using namespace std;

 

int n;

cout<<"Enter n:";

cin>>n;

if (n) cout<<"TRUE"<<endl; // ++ !

if (n>0) cout<<"n is positive"<<endl;

if (n<0) cout<<"n is negative"<<endl;

if (n==0) cout<<"n is zero"<<endl;

cout<<"Value of operation > is "<<(n>0)<<endl;

cout<<"Value of operation < is "<<(n<0)<<endl;

cout<<"Value of operation == is "<<(n==0)<<endl;

_getch();

}

 

, , if/else, :

if (<>) <1>; else <2>;

, <>, ( ), <1>, ( ), <2>. - .1 .

.1. if ++

<1> <2> - ++, . if/else, . , else if. , , x=1; y=-1,

if (x>0) if (y>0) z=1; else z=2;

z 2. , else z=2; if (y>0), if (x>0), :

if (x>0) {if (y>0) z=1;} else z=2;

++ <1> <2> . , { }, . , ++ , . :

{ <1>; <2>;... <N> }

if/else, .

#include <iostream>

#include <conio.h>

#include <math.h>

void main()

{

using namespace std;

 

double x,y;

cout<<" x:"<<endl;

cin>>x;

if (x<0)

cout<<" <0 !"<<endl;

else {

y=0.75*sqrt(x)-0.5*pow(4, 1.0/3);

cout<<"y="<<y<<endl;

}

_getch();

}

2.3. ?:

++, / . ++ : && ( ), || ( ) ! ( ). , .2.

2.

&&     ||  
             
         

:!0=1 !1=0.

if/else. , x b :

(x>=a && x<=b)

++ ?:, if/else. , , . ֳ , :

<>? <1>: <2>.

, , , , , . ,

cout<< (grade>=50? ”: ”);

, ”, grade>=50 , ”, . , 䳿, i f/else:

if(grade>=50)cout<<”; else cout<< ”;

, .

䳿. ,

grade>=50? cout<<”: cout<< ”;

: grade 50, ’, ’.

switch

. if/lse. - switch, :

switch (switch_expression)

{ case constant1: statement1; [ break;]

case constanti: statementi; [ break;]

......

case constantN: statementN; [ break; ]

[ default: statementN+1; ] }

switch . switch__expression. - char, int, unsigned int, long int long unsigned. constant1,..., constantN. . switch_expression constanti statementi. switch, i- break ( break switch). i+1, i+2 , break statement n+1.

switch_expression constanti,..., constantN, , default. switch .

, .

#include <iostream>

#include <conio.h>

 

void main()

{

using namespace std;

 

char ch;

cout<<"Enter letter:";

cin>>ch;

switch (ch) {

case 'r': cout<<"Stop! RED"<<endl; break;

case 'y': cout<<"Attention! YELLOW"<<endl; break;

case 'g': cout<<"Go! GREEN"<<endl; break;

default: cout<<"Wrong letter!"<<endl;

}

 

_getch();

}

goto. goto:

goto <>;

M

<>: <>;

̳ . , goto, ++. , . ֳ .





:


: 2017-02-11; !; : 702 |


:

:

, .
==> ...

1714 - | 1496 -


© 2015-2024 lektsii.org - -

: 0.058 .