Explanation of Solution
Von Koch snowflake using Recursive method:
- A method calls itself is a recursive method.
- In recursive function base case will stop recursion and return value instead of calling function.
- In each recursive call each side is divided into three sides. Each side has length of one by third of previous one.
- Three new sides are drawn by turn line to left by “600”, turn right by “1200” and turn left by “600”.
Refer program in Figure 5.6 of textbook and include the following code in the given program to draw the cross.
Function to draw cross:
//Recursive function to draw side of cross
void drawSideofCross(double sidde, int levell)
{
//If level is 0
if (levell == 0)
{
//Calculate value of x cordinate
pt.x = int(cos(angle*PI/180)*sidde) + currPt.x;
//Calculate value of y cordinate
pt.y = int(sin(angle*PI/180)*sidde) + currPt.y;
pen->LineTo(pt);
//Set x cordinate of of current point
currPt.x = pt.x;
//Set y cordinate of of current point
currPt.y = pt.y;
}
//If level is not 0
else
{
/*Call recursive function drawSideofCross() with prameters (sidde/3) and (levell-1)*/
drawSideofCross(sidde/3,levell-1);
//Rotate 90 degree to left
left (90);
/*Call recursive function drawSideofCross() with parameters (sidde/3) and (levell-1)*/
drawSideofCross(sidde/3,levell-1);
//Rotate 90 degree to right
right(90);
/*Call recursive function drawSideofCross() with parameters (sidde/3) and (levell-1)*/
drawSideofCross(sidde/3,levell-1);
//Rotate 90 degree to right
right(90);
/*Call recursive function drawSideofCross() with parameters (sidde/3) and (levell-1)*/
drawSideofCross(sidde/3,levell-1);
//Rotate 90 degree to left
left (90);
/*Call recursive function drawSideofCross() with parameters (sidde/3) and (levell-1)*/
drawSideofCross(sidde/3,levell-1);
}
}
//Function to draw cross
void drawCross()
{
/*Call recursive function drawSideofCross() with parameters (side) and (level)�...
Trending nowThis is a popular solution!
Chapter 5 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
- Just what does it imply when people talk about a "Regular Expression"? We have to ask ourselves why we did it. Specifically, what are the main dissimilarities between a descriptive method and a regular expression? Could you be more detailed, please?arrow_forwardThe question in the images program using java in the loop \ whilearrow_forwardCan you please help me with part e because i am really struggling with this problem that I don't understand, Can you please do something visual so I can understand it better, this problem has to be done in state diagram. Again I only need help with part Earrow_forward
- can you solve this please? Adopt appropriate Java animation code to implement the video in the file “test4.wmv” and given that the parametric equation for a circle. x=r*cos(t) y=r*sin(t) with t in range [0, 2p] and r is the radius of the circle. (the circle goes in a loop like in the images, i did my best to try to explain it , please try to do it ) and here is a sample of what they want me to use : package javaapplication1;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.awt.geom.*;import java.util.Random;import javax.imageio.*;import java.io.File;import java.io.IOException;import java.awt.image.BufferedImage;import java.awt.event.*;import java.util.Calendar; public class JavaApplication1 extends JApplet { public static void main(String[] args) { JFrame frame=new JFrame(); frame.setTitle("hello"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JApplet applete =new JavaApplication1(); applete.init();…arrow_forwardI need to know how exactly I can implement all of the other features within the program and where please. Specifically giving users the option of using their own list of numbers or a random list, being able to play the game continously until they quit, keeping a score of wins and losses, and using turtle graphics for a grid and/or score.arrow_forwardHow to write a java program will read in the strings from the text file, keep count of the number of each grade, and output a graph similar to the screenshot below?arrow_forward
- Implement the "paint fill"feature seen in several picture editing products.To put it another way, if you have a screen (represented by a two-dimensional array of colours), a point, and a new colour, Fill in the surrounding area until the colour shifts away from the original.arrow_forwardOne last implementation, can you have the user implement their own names and employee info (like first and last name, # of hours worked, hourly rate, and their major) and it computes it for them and prints it out?arrow_forwardQuestion is in the photo attached Need a simple python code that does not involve the map() functionarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education