need code help in program "class declaration"

Is it possible to create a class declaration for a traffic light using enum and class???? If the light can be green, yellow or red...  should be able to check this state and change it right?

how???
LVL 1
schmitty22Asked:
Who is Participating?
 
nietodConnect With a Mentor Commented:
>> Is it possible to create a class declaration for a
>> traffic light using enum and class
Yes.

>> how???
Well, we can't GIVE you answers to school assignments, but we can provide assistance, like you might get from a teacher.  I'll give you a cpouple of hints to get you started.  Do the best you can, then if you get stuck post what you get done.

First you need to declare an enum that lists the 3 colors.  An example of an enum might be

enum Fruit
{
   Apple,
   Orange,
   Banana
};

can you declare the color enum?

Then you need to declare a class that contains a data member that records this enum.  like

class Snack
{
   Fruit SnackType;
};

You need to add member functions to this class to get the ligh'ts current color or set it to a new color, in the snack case that might be like

class Snack
{
   Fruit SnackType;
public:
   Fruit GetSnackType() const
   {
       return SnackType;
   }
   SetSnackType(Fruit NewType)
   {
      SnackType = NewType;
   }
};
0
 
schmitty22Author Commented:
right.. well said.. this helped greatly and quick too.. thanks
0
All Courses

From novice to tech pro — start learning today.