Programming Project

I need a little assistance on how to do this. This whole project must emulate the idea of encapsulation, inheritance and polymorphism. If anyone has an idea on how to do this, please don't hesitate on posting a reply. Thank you.

Legend: + is public
- is private


Specification:

1. Create a class named “Light”, as specified below:

Light

- color (data type: int) /* red=1, yellow=2, green=3, default = 0*/
- status (data type: bool) /*off=0, on=1 */

+ Light(int color_in, bool status_in) /*overloaded constructor, set the color based on the parameter input color_in.If a number other than specified is given, set the color to default ‘0’
The status is set to the value of status_in */

+ print_light ( ) /* return type: void, print the color and status of the object*/

+ change_status( ) /*return type: void, change the status from on to off, or off to on, according to the current status */

+ set_status(bool in_status) /* return type: void, set the status according to the parameter in_status */


2.Applying the composition mechanism to implement the class named “TrafficLight”, specified below:

A data members called “total_count” needs to be declared. A member function named get_total_count( ) needs to be declared and defined.

TrafficLight

- redLight (data type: Light) /* a data member which is an object of class Light, with color set to red */

- yellowLight(data type: Light) /* a data member which is an object of class Light, with color set to yellow* /

- greenLight(data type: Light) /* a data member which is an object of class Light, with color set to green */

- total_count(date type: int) /* a static member, maintain the total number of TrafficLight objects in the system */

+TrafficLight( ) /* construct three lights, default the status to “off” for all three lights, maintain the total_count static member appropriately*/

+TrafficLight(bool red_status, bool yellow_status, bool green_status) /* construct three lights, set the status of the three lights based on the parameter inputs, maintain the total_count static member appropriately */

+ set_Traffic_Lights(bool red_status, bool yellow_status, bool green_status) /* return type: void. Set the status of the three lights to the parameter inputs accordingly*/


+ print_Traffic_Lights /* return type: void. Print the statuses of the three lights*/

+ get_total_count( ) /*return type: int. A static member function. Print and return the value of total_count*/


3. Write a complete program that instantiates two TrafficLight objects named northsouth, and eastwest. The outputs of the program is specified below:

Total number of traffic lights: 0
Traffic light northsouth:
red light on
yellow light off
green light off

Total number of traffic lights: 1
Traffic light eastwest:
red light off
yellow light off
green light on

Total number of traffic lights: 2
Traffic light northsouth:
red light on
yellow light off
green light off

Traffic light eastwest:
red light off
yellow light on
green light off



I would recommend doing this using encapsulation, inheritance and polymorphism.
Any more specific questions? What do you have so far?
Well, here is what I have so far. I know that there are blanks and what not, but I think it goes like this. Somehow I am still confused...if you can provide an example that is quite related to this project, please post a link just like mcleano. I almost understand it, I really am just confused. Thank you.

/*My Code*/

#include <iostream>

using namespace std;

class TrafficLight
{
public:
TrafficLight();//construct three lights, default the status to "off" for all three lights, maintain the total_count static member appropriately
TrafficLight(bool, bool, bool);//construct three lights, set the status of the three lights based on the parameter inputs, maintain the total_count static member appropriately
void setTrafficLights(bool, bool, bool);//set the status of the tree lights to the parameter inputs accordingly
void printTrafficLights();//print the statuses of the three lights
int gettotalCount();//A static member function. print and return the value of the total_count
private:
Light redLight;
Light yellowLight;
Light greenLight;
int totalCount;
}

void Light::setStatus()
{
}

void Light::changeStatus()
{
}

void Light::printLight()
{
}

Light::Light()
{
}

TrafficLight::TrafficLight(bool red_status, bool yellow_status, bool green_status)
{
red_status = 0;
yellow_status = 0;
green_status = 0;
}

TrafficLight::TrafficLight()
{
Light : redLight;
Light : yellowLight;
Light : greenLight;
}

void TrafficLight::setTrafficLights(bool red_status, bool yellow_status, bool green_status)
{

}

int TrafficLight::gettotalCount()
{
}

void TrafficLight::printTrafficLights()
{
}
Topic archived. No new replies allowed.