Chapter - 1
Download Book
solution:
page(30)
Exercise - 1
In all the problems related to drawing, you are expected to identify the patterns/repetitions
in what is asked, and use repeat statements to write a concise program as possible. You
should also avoid excessive movement of the turtle and tracing over what has already been
drawn.
1. Modify the program given in the text so that it asks for the side length of the polygon
to be drawn in addition to asking for the number of sides.
#include<simplecpp>
main_program{
int length , sides;
cout<<"Enter length and number of sides"<<endl;
cin>>length>>sides;
turtleSim();
repeat(sides){
forward(length);
right(360/sides);
wait(1);
}
wait(4); //it is use for pause the turtle for certain time interval
}
2. Draw a sequence of 10 squares, one to the left of another.
solution:
#include<simplecpp>
main_program{
turtleSim();
repeat(10){
repeat(4){
forward(25);
right(360/4);
wait(0.3);
}
right(180);
penUp();
forward(25);
right(180);
penDown();
}
wait(5);
}
Comments
Post a Comment