Question: Implement a class that simulates a traffic light. The next function advances the color in the usual way, from green to yellow to red, then

Implement a class that simulates a traffic light. The next function advances the color in the usual way, from green to yellow to red, then again to green. Provide two constructors, as described in the documentation of the public interface. Also supply a member function that yields the number of times that this traffic light has been red.

Complete the following file:

Implement a class that simulates a traffic light. The next function advances

the color in the usual way, from green to yellow to red,

then again to green. Provide two constructors, as described in the documentation

Tester.cpp 1 2 3 4 5 #include #include using namespace std; 6 /** A simulated traffic light. */ class Traffic light { public: /** Constructs a green traffic light. TrafficLight(); /** Constructs a traffic light. @param initial_color the initial color "green", "yello */ TrafficLight(string initial_color); /** Moves this traffic light to the next color. */ void next(); 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 /** Returns the current color of this traffic light. @return the current color string get_color() const; /** Counts how often this traffic light has been red. @return the number of times this traffic light has bee int get_reds() const; private: string color; int reds; }; TrafficLight :: TrafficLight() { } TrafficLight :: TrafficLight(string initial_color) } void TrafficLight:: next() { } string TrafficLight::get_color() const { 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 } int TrafficLight::get_reds() const { } int main() TrafficLight tll; cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!