Enum Types Assignment Help

Assignment Help: >> Data Types, Variables and Operators in C++ - Enum Types

Enum types

Enumerated categories work when you know in advance a finite (commonly short) list of values in which a data type can take on.  It is another user defined type that gives a way for attaching names to numbers, thus increasing comprehensibility of the code. An enum keyword automatically enumerates a list of words through assigning them values 0,1,2,3,4, and many more.

The general form of enum is:

enum variable name { list of constants separated by commas };

where enum is a keyword

variable name is the user defined variable name

list denotes the fixed constant values

Eg.

enum days_of_week {sun, mon, tue, wed, thu, fri, sat};

At one we have specified the days of the week as displays we can describes variable of this category.

Example:

// demonstration of enum data types

# include<iostream.h>

enum days_of_week {sun, mon, tue, wed, thu, fri, sat };

void main( )

{

days_of_week day1, day2,day3;

day1 = mon;

day 2 = fri;

int diff = day2 - day1;

cout<<"days between = "<<diff<<endl;

if (day1<day2)

cout<< "day1 comes before day2\n";

}

the values which are listed inside braces of enum keyword are known as members.  An Enumerated means which all the values are listed.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd