Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7751519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:34:09+00:00 2026-06-01T11:34:09+00:00

This question is driving me crazy. I need to get it right so I

  • 0

This question is driving me crazy. I need to get it right so I can pass my class. Thank you to all that try it.

Write a simple program in C++ to investigate the safety of its enumeration types. Include at least 10 different operations on enumeration types to determine what incorrect or just silly things are legal.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:34:10+00:00Added an answer on June 1, 2026 at 11:34 am

    Here is a fully operational program that shows ten different types of operations with enums. Details will be in the code, references will be at the bottom of the post.

    First, it is very important you understand what enums are. For a reference on this, take a look at Enumerated Types – enums. In the code below I use mathematical operations, bitwise operators and use an enum value to initialize an array to a default size.

    #include <iostream>
    using namespace std;
    
    enum EnumBits
    {
        ONE = 1,
        TWO = 2,
        FOUR = 4,
        EIGHT = 8
    };
    
    enum Randoms
    {
        BIG_COUNT = 20,
        INTCOUNT = 3
    };
    
    int main(void)
    {
        // Basic Mathimatical operations
        cout << (ONE + TWO) << endl;    // Value will be 3.
        cout << (FOUR - TWO) << endl;   // Value will be 2.
        cout << (TWO * EIGHT) << endl;  // Value will be 16.
        cout << (EIGHT / TWO) << endl;  // Value will be 4.
    
        // Some bitwise operations
        cout << (ONE | TWO) << endl;    // Value will be 3.
        cout << (TWO & FOUR) << endl;   // Value will be 0.
        cout << (TWO ^ EIGHT) << endl;  // Value will be 10.
        cout << (EIGHT << 1) << endl;   // Value will be 16.
        cout << (EIGHT >> 1) << endl;   // Value will be 4.
    
        // Initialize an array based upon an enum value
        int intArray[INTCOUNT];
    
        // Have a value initialized be initialized to a static value plus
        // a value to be determined by an enum value.
        int someVal = 5 + BIG_COUNT;
    
        return 0;
    }
    

    The code sample done above can be done in another way, which is where you overload the operator|, etc for EnumBits. This is a commonly used technique, for additional references please see How to use enums as flags in C++?.

    For a reference on bitwise operations, take a look at Bitwise Operators in C and C++: A Tutorial

    Using C++ 11 you can use enums in additional ways, such as strongly typed enums.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question that is driving me crazy. It is all about updating,
This is a newbie question that is driving me crazy. According to jQuery mobile
I have this question that is driving me crazy: could I save a PDF
This issue has been driving me crazy all morning. I've been trying to get
This is driving me crazy. Hopefully my question makes sense... I'm using MVC 2
This is NOT a duplicate question, and the problem is driving me crazy. I
This problem is driving me crazy, I'm sure I'm missing something. I need to
This is probably a simple question, but it's driving me crazy! I have a
Sorry for the stupid question, but this is driving me crazy... I have test_framework.php
Please apologize for the basicness of my question, but this is driving me crazy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.