118k views
4 votes
2. 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. Now, write a C program that does the same things and run it to determine how many of the incorrect or silly things are legal. Compare your results.

User Stot
by
6.1k points

1 Answer

3 votes

Answer:

Check the explanation

Step-by-step explanation:

To solve the question above, we will be doing some arithmetic and bit wise operations on enum values. in addition to that, we are asserting the array with INTCOUNT and also printing the size of array i.e 12 and we are adding BIG_COUNT enum value to 5 and the result is 25.

#include<stdio.h>

enum EnumBits

{

ONE = 1,

TWO = 2,

FOUR = 4,

EIGHT = 8

};

enum Randoms

{

BIG_COUNT = 20,

INTCOUNT = 3

};

int main()

// Basic Mathimatical operations

printf("%d\\",(ONE + TWO)); //addition

printf("%d\\",(FOUR - TWO)); //subtraction

printf("%d\\",(TWO * EIGHT)); //multiplication

printf("%d\\",(EIGHT / TWO)); //division

// Some bitwise operations

printf("%d\\",(ONE

Kindly check the attached image below for the Code and Output Screenshots:

2. Write a simple program in C++ to investigate the safety of its enumeration types-example-1
User HoGo
by
7.1k points