Question

In: Computer Science

In this program, you'll create a program that utilizes an enumerated data type to manipulate the...

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

Solutions

Expert Solution

  • Below is the detailed implementation of the above problem in C++ with code and output shown.
  • For better understanding please read the comments mentioned in the code.
  • Using enums to define a user data type in which some values are defined while declaring the enum data-type, for example in the below program enum data type is used for iterating on array elements.
  • CODE:

//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;
}

  • OUTPUT:

100
40
75

  • Below are the screenshot attached for the code and output for better clarity and understanding.

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.


Related Solutions

Description: In this program, you'll reuse the Monster data type you wrote in LA11A. Then, you'll...
Description: In this program, you'll reuse the Monster data type you wrote in LA11A. Then, you'll write a function that accepts a Monster as an argument by reference, then print the Monster to the screen. 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...
Exercise 2: Write a program in Java to manipulate a Double Linked List: 1. Create Double...
Exercise 2: Write a program in Java to manipulate a Double Linked List: 1. Create Double Linked List 2. Display the list 3. Count the number of nodes 4. Insert a new node at the beginning of a Double Linked List. 5. Insert a new node at the end of a DoubleLinked List 6. Insert a new node after the value 5 of Double Linked List 7. Delete the node with value 6. 8. Search an existing element in a...
Exercise 3: Stack Write a program in Java to manipulate a Stack List: 1. Create Stack...
Exercise 3: Stack Write a program in Java to manipulate a Stack List: 1. Create Stack List 2. Display the list 3. Create the function isEmply 4. Count the number of nodes 5. Insert a new node in the Stack List. 6. Delete the node in the Stack List. 7. Call all methods above in main method with the following data: Test Data : Input the number of nodes : 4 Input data for node 1 : 5 Input data...
Exercise 1: Write a program in Java to manipulate a Singly Linked List: 1. Create Singly...
Exercise 1: Write a program in Java to manipulate a Singly Linked List: 1. Create Singly Linked List 2. Display the list 3. Count the number of nodes 4. Insert a new node at the beginning of a Singly Linked List. 5. Insert a new node at the end of a Singly Linked List 6. Insert a new node after the value 5 of Singly Linked List 7. Delete the node with value 6. 8. Search an existing element in...
Create a program (or set of programs) which accomplish the following for each complex data type...
Create a program (or set of programs) which accomplish the following for each complex data type (list,tuple,set,frozenset, dictionary): create the item with at least 4 elements Append an element Remove an element Insert an element in the middle somewhere Append another array of the same data type Append another array of a different data type (for example, if you have a dictionary, append a set or tuples And do the following: Output the results after each step. Report and explain...
Create a program (or set of programs) which accomplish the following for each complex data type...
Create a program (or set of programs) which accomplish the following for each complex data type (list,tuple,set,frozenset, dictionary): create the item with at least 4 elements Append an element Remove an element Insert an element in the middle somewhere Append another array of the same data type Append another array of a different data type (for example, if you have a dictionary, append a set or tuples And do the following: Output the results after each step. Report and explain...
HW 8-1a   1.)   Referring to the UML class diagram, create a program that utilizes the Student...
HW 8-1a   1.)   Referring to the UML class diagram, create a program that utilizes the Student class. - id : Integer - units : Integer - name : String + Student ( ) : + Student (id : Int, name : String, units : Int) : + ~Student( ) : + setID(id : Integer) : void + setName(name: String) : void + setUnits(units : Integer ) : void + displayRecord() : void 2.)   Include 3 files: -   Source.cpp -   Student.h...
This program is supposed to identify whether I inputted a number or a letter through enumerated...
This program is supposed to identify whether I inputted a number or a letter through enumerated types and an array of messages. I'm aware that you can't compare strings and enums but I'm out of ideas. What method do you suggest. #include <iostream> #include <iomanip> using namespace std; int main() {    enum letters { A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y,...
Write a program that utilizes a function called paymentCalc. In the main body of the program,...
Write a program that utilizes a function called paymentCalc. In the main body of the program, ask the user what is their principal and how many months they want the loan. If it is easier, ask the user for number of years, but don’t forget to change it to months for the calculation. Use a function to calculate their monthly mortgage payment. In the main body of the program, print out what their monthly mortgage payment will be. For simplicity,...
An organism is classified as a heterotroph or autotroph based on the type of _______ it utilizes.
An organism is classified as a heterotroph or autotroph based on the type of _______ it utilizes.A respiration source (e.g., oxygen or other) B. nitrogen source . C. carbon source D.none of the above
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT