170 likes | 189 Views
Enumerations. Your First Enums. // syntax enum enum_name {enumerator1, enumerator2, ... enumeratorN }; // example 1 enum color {green, blue, yellow}; // example 2 enum number {one, two, three, four, five}; //example 3 enum {Ace, King, Queen, Jack};. Your First Enums. // syntax
E N D
Your First Enums // syntax enumenum_name {enumerator1, enumerator2, ... enumeratorN}; // example 1 enum color {green, blue, yellow}; // example 2 enum number {one, two, three, four, five}; //example 3 enum {Ace, King, Queen, Jack};
Your First Enums // syntax enumenum_name {enumerator1, enumerator2, ... enumeratorN}; // example 1 enum color {green, blue, yellow}; // example 2 enum number {one, two, three, four, five}; //example 3 enum {Ace, King, Queen, Jack};
Your First Enums // syntax enumenum_name {enumerator1, enumerator2, ... enumeratorN}; // example 1 enum color {green, blue, yellow}; // example 2 enum number {one, two, three, four, five}; //example 3 enum {Ace, King, Queen, Jack};
Your First Enums // syntax enumenum_name {enumerator1, enumerator2, ... enumeratorN}; // example 1 enum color {green, blue, yellow}; // example 2 enum number {one, two, three, four, five}; //example 3 enum {Ace, King, Queen, Jack};
Your First Enums // syntax enumenum_name {enumerator1, enumerator2, ... enumeratorN}; // example 1 enum color {green, blue, yellow}; // example 2 enum number {one, two, three, four, five}; //example 3 enum {Ace, King, Queen, Jack};
Your First Enums // syntax enumenum_name {enumerator1, enumerator2, ... enumeratorN}; // example 1 enum color {green, blue, yellow}; // example 2 enum number {one, two, three, four, five}; //example 3 enum {Ace, King, Queen, Jack};
Your First Enums // example 1 enum color {green, blue, yellow}; color hue; color hue = green; color hue = 2; color hue = color(2); intx = hue; // example 2 enumexit {door = 7, window = 3, chimney, drain = 1};
Your First Enums // example 1 enum color {green, blue, yellow}; color hue; color hue = green; color hue = 2; color hue = color(2); intx = hue; // example 2 enumexit {door = 7, window = 3, chimney, drain = 1};
Your First Enums // example 1 enum color {green, blue, yellow}; color hue; color hue = green; color hue = 2; color hue = color(2); intx = hue; // example 2 enumexit {door = 7, window = 3, chimney, drain = 1};
Your First Enums // example 1 enum color {green, blue, yellow}; color hue; color hue = green; color hue = 2; color hue = color(2); intx = hue; // example 2 enumexit {door = 7, window = 3, chimney, drain = 1};
Your First Enums // example 1 enum color {green, blue, yellow}; color hue; color hue = green; color hue = 2; color hue = color(2); intx = hue; // example 2 enumexit {door = 7, window = 3, chimney, drain = 1};
Your First Enums // example 1 enum color {green, blue, yellow}; color hue; color hue = green; color hue = 2; color hue = color(2); intx = hue; // example 2 enumexit {door = 7, window = 3, chimney, drain = 1};
Your First Enums // example 1 enum color {green, blue, yellow}; color hue; color hue = green; color hue = 2; color hue = color(2); intx = hue; // example 2 enumexit {door = 7, window = 3, chimney, drain = 1};
Readable int main() { srand(time(NULL)); short count_heads = 0; short count_tails = 0; enumcoin_toss {head, tail}; coin_toss flip; string tosses[2] = {“head”,”tail”}; for (inti=1; i<=200; i++) { flip = coin_toss(rand()%2); cout<<”we flipped a “<<tosses[flip]<<endl; flip ? count_tails++ : count_heads++ ; // tally the flips } cout<<endl<<"We tossed: "<<count_heads<<" heads"<<endl<<" "<<count_tails<<" tails"<<endl; return 0; }
Readable output we flipped a headwe flipped a head we flipped a tail we flipped a head we flipped a tail we flipped a tail ...We tossed:110 heads 90 tails int main() { srand(time(NULL)); short count_heads = 0; short count_tails = 0; enumcoin_toss {head, tail}; coin_toss flip; string tosses[2] = {“head”,”tail”}; for (inti=1; i<=200; i++) { flip = coin_toss(rand()%2); cout<<”we flipped a “<<tosses[flip]<<endl; flip ? count_tails++ : count_heads++ ; // tally the flips } cout<<endl<<"We tossed: "<<count_heads<<" heads"<<endl<<" "<<count_tails<<" tails"<<endl; return 0; }