C++.


switch - 6


5.7

:

(a)

switch ( ival ) {

case 'a': aCnt++;

case 'e': eCnt++;

default: iouCnt++;

}

(b)

switch ( ival ) {

case 1:

int ix = get_value();

ivec[ ix ] = ival;

break;

default:

ix = ivec.sizeQ-1;

ivec[ ix ] = ival;

}

(c)

switch ( ival ) {

case 1, 3, 5, 7, 9:

oddcnt++;

break;

case 2, 4, 6, 8, 10:

evencnt++;

break;

}

(d)

int iva1=512 jva1=1024, kva1=4096;

int bufsize;

// ...

switch( swt ) {

case ival:

bufsize = ival * sizeof( int );

break;

case jval:

bufsize = jval * sizeof( int );

break;

case kval:

bufsize = kval * sizeof( int );

break;

}

(e)

enum { illustrator = 1, photoshop, photostyler = 2 };

switch ( ival ) {

case illustrator:

--i11us_1icense;

break;

case photoshop:

--pshop_1icense;

break;

case photostyler:

--psty1er_license;

break;

}