++



         

if - 5


min() main(), :

#include <iostream>

#include <vector>

int min( const vector< int > &ivec, int &occurs )

{

int minVal = ivec[ 0 ];

occurs = 1;

int size = ivec.size();

for ( int ix = 1; ix < size; ++ix )

{

if ( minVal == ivec[ ix ] )

++occurs;

else

if ( minVal > ivec[ ix ] ){

minVal = ivec[ ix ];

occurs = 1;

}

}

return minVal;

}

int main()

{

int ia[] = { 9,1,7,1,4,8,1,3,7,2,6,1,5,1 };

vector<int> ivec( ia, ia+14 );

int occurs = 0;

int minVal = min( ivec, occurs );

cout << " : " << minVal

<< " : " << occurs << " .\n";

return 0;

}

:

: 1 : 5 .

if-else . , min():

template <class valueType>

inline const valueType&

min( valueType &vall, valueType &va12 )

{

if ( vall < va12 )

return vall;

return va12;

}

:

template <class valueType>

inline const valueType&

min( valueType &vall, valueType &va12 )

{

return ( vall < va12 ) ? vall : va12;

}

if-else, , , , .

if ( ch == 'a' ||

ch == 'A' )

++aCnt;

else

if ( ch == 'e' ||

ch == 'E' )

++eCnt;

else

if ( ch == 'i' ||

ch == 'I' )

++iCnt;

else

if ( ch == 'o' ||

ch == '0' )

++oCnt;

else

if ( ch == 'u' ||

ch == 'U' )

++uCnt;

++ switch. .

5.3

:

(a) if ( ivall != iva12 )

ivall = iva12

else

ivall = iva12 = 0;

(b) if ( ivat < minval )

minvat = ival;

occurs = 1;

(c) if ( int ival = get_value())

cout << "ival = "

<< ival << endl;

if ( ! ival )

cout << "ival = 0\n";

(d) if ( ival = 0 )

ival = get_value();

(e) if ( iva1 == 0 )

else ival = 0;

5.4

occurs min(), , . . ?