Question
I need the code to define the Turtle class following the instructions above. The code for vanish.cpp is below #include turtle.h #include draw.h int main()
I need the code to define the Turtle class following the instructions above. The code for vanish.cpp is below
#include "turtle.h" #include "draw.h"
int main() { draw::setpenwidth(10); // thick lines draw::setrange(-100, 100);
// start at A Turtle raphael(50, 50, 240); raphael.setColor(draw::RED); raphael.move(100); // go to B raphael.turn(-105); raphael.move(50); // go to C raphael.off(); // ninja vanish raphael.turn(180); // turn around raphael.move(90); // go to D raphael.turn(-135); raphael.setColor(draw::GREEN); raphael.on(); // ninja unvanish raphael.move(60); // go to E
return 0; }
Procedure: setColor(), on(), off() [4 pts.] setColor(), on(), off() This week we have extended the draw library. The new feature is to define a new kind of struct called Color . Look inside of draw.h to see how it is defined. You can pass a Color object to draw: : setcolor() to change the current color. For this part of the lab, extend the functionality of your |Turtle class by defining 3 more member functions that affect the look of the turtle's path. E void setColor(Color c); // change line color that this Turtle draws from now on void off(); // make this Turtle stop drawing Lines when it moves E void on(); // make this Turtle resume drawing Lines when it moves E.g., here is a program vanish.cpp that uses these features, with the expected generated image file "vanish.png" shown below. (The labels A, B, C,.. should not actually be shown on-screen, they're just to match the explanations in the comments.) A C B E D. What additional data members do you need to add to the Turtle class to support this functionality? . You will need to add #include "draw.h" to turtle.h in order to use a Color object therein. At the same time, you may choose to remove #include "draw.h" from turtle. cpp since it's transitively included through turtle. h . Make sure that the constructor initializes all of the new data members. Make each Turtle's default color be draw: : BLACK . How does the new functionality change move? . You should not change the prototypes of the constructor or of the move function. Just the definitions (the parts between {brackets}) need to change. . Finally, add the new functions (declare them in turtle.h and define them in turtle.cpp)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