Solved

need code help in program "class declaration"

Posted on 2000-03-22
2
208 Views
Last Modified: 2010-08-05
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???
0
Comment
Question by:schmitty22
2 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 2646234
>> 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
 
LVL 1

Author Comment

by:schmitty22
ID: 2646247
right.. well said.. this helped greatly and quick too.. thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now