.


:




:

































 

 

 

 





, , , , . , .

, , ++.

enum, ( ), .

enum chess {king, queen, rook, bishop, knight, p};   enum month {Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};   enum operator_CPP{plus='+', minus='-', mult='*', div='/', rem='%'};

unsigned char int, . int.

, chess mouth, 0, - 1, .. , , 1 , .

operator_CPP , ASCII - '+', '-', '*', '/', '%'.

, . , :

const TWO = 2; enum {first, second=first, next=first+TWO, last =next*next+1}dummy;

, , dummy, : first, second, next, last.

  , dummy = first; dummy = last;  

- , .

,

  month m1, m2; operator_CPP op1, op2, op3; enum colour { red, green} c[10];  

op1, op2, op3 plus, minus,...; m1, m2 - Jan, Feb . ., c[0]... c[9] red green.

, int. .

int i = dummy; // i = = 5 month current_month = Jan; current_month =0; // ! . current_month = (month)0; // ! Feb = 1; // : Feb - !

5.2 ++.

1. .

 

  # include iostream using namespace std; void main() { enum Days {Monday, Tuesday, Wednesday, Thursday, Friday} day; day = Monday; cout<<This is the << day + 1<< day of a week!<< endl; day = Friday; cout<<This is the << day + 1<< day of a week!<< endl; }   : This is the 1 day of a week! This is the 5 day of a week!  

2. .

# include iostream using namespace std; enum Months {January = 1; February, March, April, May, June, July, August, September, October, November, December} months; /* 1 12, .. January 1*/ void main() {int present_month; int diff;   // 1 12 cout<<Input the present month number (1 - 12):; cin>> present_month;   months = December; diff = (int)months - present_month;   // cout<<There are months till the end of the year:<<diff; }   : Input the present month number (1 - 12): 5 There are months till the end of the year: 7  

3. , , .

# include iostream using namespace std; const NUMDAYS = 7; enum DAYS { mon, tue, wen, thur, fri, sat, sun } day1, day2, day3; DAYS day_before (DAYS), day_after (DAYS); void print_day (DAYS); void main () { day1 = sun; day2 = day_after (day1); day3 = day_before (day1); cout << " "; print_day (day1); cout << ", "; print_day (day2); cout <<",\n "; print_day (day3); cout <<".\n"; } DAYS day_after (DAYS day) { return ((DAYS) ((day +1)% NUMDAYS)); } DAYS day_before (DAYS day) { int prev = (day-1)%NUMDAYS; return (prev <0)? (NUMDAYS - 1): prev; } void print_day (DAYS day) { int day_i = day; static char * days [ ] ={ "", "", "", "", "", "", "" }; if (day_i <0 || day_i > NUMDAYS) cout << " !"; else cout << days[ day_i ];} }
:
, , .

 





:


: 2015-05-07; !; : 549 |


:

:

- , .
==> ...

1958 - | 1750 -


© 2015-2024 lektsii.org - -

: 0.008 .