Solved

need code help in program "class declaration"

Posted on 2000-03-22
2
199 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

759 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

20 Experts available now in Live!

Get 1:1 Help Now