472,328 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

enum

13
Hi there,

I'm fairly new at this, and I am having a bit of trouble wrapping my head around some concepts of enum for a project. So any help would be greatly appreciated.

Essentially I'm writing a program where i will have an enum in one of my classes. When the program is used, the user will define what actually goes inside the enum.
So for example what I mean is if the class is WorkDay....and the user defines what days of the weeks he or she works. One user would say monday, tuesday and thursday...and the class would look like:

class WorkDay{
enum days { monday, tuesday, thursday };
}

Another user might say monday, wednesday, thursday and friday....and the class would look like:

class WorkDay{
enum days { monday, wednesday, thursday, friday};
}


My question is....well....how do I actually code that?
How do I define what goes inside the enum each time the program is run through the user's input??

Another question is....how do I assign the enum constants to variables when it's inside a class?
Do I use something like:

WorkDay enum today = sunday; //???

And one final question....how do I actually output the enum constant?
If I want to output the above variable 'today'...it has already been enumerated...so it would output an number. But what if I want to output the word 'sunday' instead?


Sorry to bombard everyone with all of these questions. I'm just really confused with the basic concepts right now.

Thanks a lot for your help.
Apr 10 '07 #1
4 1830
gpraghuram
1,275 Expert 1GB
Hi,
To clarify ur first question
1)enums have to be specified at compile time and cant be specified on the go during run time
2)You can maintain a map to do this.


Thanks
Raghuram
Apr 10 '07 #2
Banfa
9,065 Expert Mod 8TB
And one final question....how do I actually output the enum constant?
If I want to output the above variable 'today'...it has already been enumerated...so it would output an number. But what if I want to output the word 'sunday' instead?
Almost everytime I create an enum I also create a function that takes the enum as an input and returns a const char * with the textual name of the enum entries to facilitate output and debugging.
Apr 10 '07 #3
cpp
5
Hi,

Answer to your second question."how do I assign the enum constants to variables when it's inside a class?"

you can do it inside the constructor of that class..just like assigning any normal variable a value

answer to your last Q:
You can use a switch statement, where cases include your enumerated consts and for each const you can print corresponding name
Apr 10 '07 #4
ice8595
13
thank you!!
Apr 11 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

20
by: Glenn Venzke | last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an enum. Is it possible to pass the item name without the enum name in...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note...
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an...
18
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I have created an enum list like this: enum myEnum : int { This = 2, That, NewVal = 10, LastItm
2
by: Dennis | last post by:
I have an enum as follows: Public Enum myData FirstData = 6 SecondData = 7 end enum Is there anyway that I can return the Enum names by...
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType =...
10
by: Randy | last post by:
Hi, Can anyone point me to a complete, compilable example of Besser's ENUM++ mechanism? I downloaded it from CUJ and gave it a try but got...
1
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile...
2
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.