473,748 Members | 8,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

enum

13 New Member
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....h ow 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 1940
gpraghuram
1,275 Recognized Expert Top Contributor
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 Recognized Expert Moderator Expert
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 New Member
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 New Member
thank you!!
Apr 11 '07 #5

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

Similar topics

20
4849
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 your calling statement? EXAMPLE: public enum EnumName FirstValue = 1 SecondValue = 2 ThirdValue = 3
21
4600
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 the missing Flags attribute enum Color {
31
3616
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 explicit conversion, eg Form1 f = new Form1(); Control c = f; An enum value inherits from int but it doesn't get implicitly converted: HorizontalAlignment h = HorizontalAlignment.Center;
18
11368
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
3399
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 their value, i.e., I want to input 6 into a function and return the name "FirstData"
13
12392
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 = ???(enumName)
10
3904
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 errors just trying to compile the header enum.h. --Randy Yates
1
2460
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 (see following). I have also downloaded and installed the boost library. This is using gcc under FC3.
2
2120
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 (see following). I have also downloaded and installed the boost library. This is using gcc under FC3.
34
11197
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 standard enums? There's now a nice little code snippet that I wrote today that gives me an instant implementation of the pattern. I could easily just always use such an implementation instead of a standard enum, so I wanted to know what you experts all thought. Is there a case for standard enums?
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8242
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.