Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Wa . Write a default constructor that sets state to 1 . b . Write an overloaded constructor to set the value of state from
Wa Write a default constructor that sets state to b Write an overloaded constructor to set the value of state from a parameterc. Write a getter function that returns a description of the state see comment aboved Write a member function called string change This function willi. take the current value and change it to its next value following the normal pattern of redgreen yellowred and back again.ii Return the new state's text description if the light is red, it returns "red" Remember the getter function in c Example, if state was red, calling the change function will set state to green and then return the word "green"e In main,i create a TrafficLight object with an initial state of redii. Write a loop that will simply repeat times. The loop body will call the object's change function. This loop will simply be used to see that the change sequence is correct.iii. The output of the loop above should be something like GREEN YELLOW RED GREEN YELLOW RED GREEN YELLOW RED GREEN YELLOW RED
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started