In: Computer Science
In this program, you'll create a program that utilizes an enumerated data type to manipulate the array.
Here are the requirements:
Write a program that contains an enumerated data type named Letters. In the declaration, include the following three enumerators: ALPHA, BETA, DELTA.
Then, create an array of integers three elements long. The array should be initialized to 0 using a 1-element initialization list.
Instead of using integers as subscripts, use the enumerators from your enumerated data type to assign the values 100, 40, and 75 to the first three elements, respectively.
Finally, print the contents of the array using a for loop that initializes the counter with an enumerator and uses an enumerator in the test expression.
Again, this will be structured as a guided multiple choice quiz where you will choose the appropriate code for a program. After you have gotten a perfect score, write out the program and compile and run it to see it in action.
Instructions:
Choose the correct C++ code for each requirement presented.
Sample Run:
100
40
75
//include headers
#include<iostream>
using namespace std;
//defining a enum data type
enum Letters{
ALPHA, BETA, DELTA
};
//driver function
int main(){
//array of integers 3 element long initialized to 0 using a
1-element list
int arr[3]={0};
//using enumerators as subscript, assigning value to the
array
arr[ALPHA]=100;
arr[BETA]=40;
arr[DELTA]=75;
//printing the contents of the array using enumerators as
counters
for(int i=ALPHA;i<=DELTA;i++){
cout<<arr[i]<<endl;
}
return 0;
}
100
40
75
CODE
OUTPUT
So if you still have any doubt regarding this solution please feel free to ask it in the comment section below and if it is helpful then please upvote this solution, THANK YOU.