Solved

need code help in program "class declaration"

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c++ how to tell if the progra is ctl or mfc atl ect 6 107
sorting efficency of sorting algorithm 30 147
Copy output image from TWindowsMediaPlayer 6 67
C++ help/ Toy problem 19 69
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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

738 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