Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

need code help in program "class declaration"

Posted on 2000-03-22
2
Medium Priority
?
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

604 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