2. You have an array that stores your grades like:
int Grade[5];
Now, you need to assign the grades of your subjects like:
(Math, English, Biology, Chemistry, History)
to your array.
So, in Math you have a grade 1
Grade[0] = 1; // Math --> 1
for English you have a grade 3
Grade[1] = 3; // English --> 3
Later in your code, you want to retrieve the grade of English. For that you will
have to remember that in your Grade[ ] array the second entry [1] would be
English.
WITH ENUMERATION WE CAN DO IT IN AN EASY WAY.
3. First we are gonna know the meaning of the
the word enumeration, generally.
“It is the action of mentioning a number of things
one by one”
In C++, enumeration means,
“An Enumeration is user-defined data type that
consists of Integral constants”
‘enum’ keyword is used to define and
enumeration.
4. enum season { spring, summer, autumn, winter };
Here, the name of the enumeration is season.
And, spring, summer and winter are values
of type season.
By default, spring is 0, summer is 1 and so on.
You can change the default value of an enum
element during declaration
6. The expression Grade[0] is the same as
Grade[math]
Grade[0] = 1; // Math --> 1
You do not need to know which subject
has which index any more, you simply call
them by their name.
7. SOURCE CODE:
#include <iostream>
using namespace std;
enum week {
Monday,
Tuesday, FOR INSTANCE:
Wednesday, If I initialize only Monday as to (Monday=1)
Thursday , then?
Friday,
Saturday,
Sunday };
int main()
{
week today;
today = Monday;
cout << "Day: " << today +1;
return 0;
}