Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a . Write a default constructor that sets state to 1 . b . Write an overloaded constructor to set the value of state from

a. Write a default constructor that sets state to 1.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 above)d. 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 red->green> yellow->red 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 12 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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions