


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The concept of c-style enumerations in c++ programming language. It covers the syntax and purpose of enumeration declarations, the object-to-integer mapping, valid enumerator declarations, and the use of enumerations as array indices. Examples are provided to illustrate the concepts.
Typology: Study notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!
12.2 C-Style Enumerations 745
enum Gender {FEMALE, MALE};
enum HandTool {HAMMER, PLIERS, SAW, SCREWDRIVER};
enum Zipcodes { 12531 , 14405 , 21724 , 30081 }; // ERROR! enum LetterGrades {A, A-, B+, B, B-, C+, C, // ERROR! C-, D+, D, D-, "FAIL" };
enum NumberBase {BINARY = 2 , OCTAL = 8 , DECIMAL = 10 , RED ORANGE YELLOW GREEN BLUE INDIGO VIOLET 0 1 2 3 4 5 6
enum Gender {FEMALE, MALE};
enum HandTool {HAMMER, PLIERS, SAW, SCREWDRIVER};
enum Zipcodes {12531, 14405, 21724, 30081}; // ERROR! enum LetterGrades {A, A-, B+, B, B-, C+, C, // ERROR! C-, D+, D, D-, "FAIL" };
enum NumberBase {BINARY = 2, OCTAL = 8, DECIMAL = 10, HEX = 16, HEXADECIMAL = 16};
enum Color {RED = 1, ORANGE = 2, YELLOW = 3, GREEN = 4, BLUE = 5, INDIGO = 6, VIOLET = 7};
enum Color {RED = 1, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET};
enum Flag {GOOD_BIT = 1, BAD_BIT, FAIL_BIT = 4, EOF_BIT = 8};
Enumeration Declaration Statement
enum TypeName { List };
IDENTIFIER = integer_constant
vector
vector
748 Chapter 12 • Classes and Enumerations
Figure 12-2 Computing Color Wavelength. // - ------ Wavelength of a Color - --------------------------------- double wavelength(Color aColor) { switch(aColor) { case RED: return 6. 5 E- 7 ; case ORANGE: return 6. 0 E- 7 ; case YELLOW: return 5. 8 E- 7 ; case GREEN: return 5. 2 E- 7 ; case BLUE: return 4. 7 E- 7 ; case INDIGO: return 4. 4 E- 7 ; case VIOLET: return 4. 1 E- 7 ; default: cerr << "\n*** wavelength: invalid color " "received!\n"; return 0. 0 ; }