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
- In c++ code. Correct code and output screenshot.else you get downvote. grouping of round and square sections is given. You can change the arrangement by playing out the accompanying activities: shift the bearing of a section from opening to shutting as well as the other way around without changing the type of the section: for example you can change '(' to ')' and ')' to '('; you can change '[' to ']' and ']' to '['. The activity costs 0 burles. change any square section to adjust section having a similar course: for example you can change '[' to '(' yet not from '(' to '['; comparably, you can change ']' to ')' however not from ')' to ']'. The activity costs 1 burle. The activities can be acted in any request quite a few times. You are given a string s of the length n and q inquiries of the kind "l r" where 1≤l<r≤n. For each substring s[l… r], track down the base expense to pay to make it a right section grouping. It is ensured that the substring s[l… r] has an even length.…arrow_forwardI need help with my assignment in my Java programing class. I have already created the "Monkey" class (#5) but need help in creating a loop (#6) as I struggle with loops since they are not clicking. Please see the picture for the criteria on the loop. Attached is also a picture of the first page of the driver class.arrow_forwardImagine if the survey contained two sheets in the same book. Perhaps sheet 1 isshoes and sheet 2 is dresses.The work now doubles.What about more than two sheets?You get the picture. This needs some sort of automation.Write ALGORITHM FOR MERGING SHEETSarrow_forward
- Write a program that draws 10 circles with centers (0, 0), as shown in Figure 5.3b.arrow_forwardCreate a program that provides visualization for three-dimensional plane: Animate your solution using any animation programming language like matlab please. (so the output should show graph of the exponential function inputted by the user)the system should be user-input, and the output should show graph of the exponential function inputted by the user) The topic is all about Inverse Laplace Transform on Exponential function.arrow_forwardWrite a graphical program to trace a random walk (see previous two prob-lems) in two dimensions. In this simulation you should allow the step to be taken in any direction. You can generate a random direction as an angleoff of the x axis. angle = random() * 2 * math.piarrow_forward
- I'm developing a card game that requires one deck of 52 cards using Java. The 52 card has 4 suits from top to bottom: diamonds (d), clubs (c), hearts (h), and spades (s). Each card has a point. The rest of the instructions are in the images. Based on the code below, it outputs the maximum points of all 5 sorted cards. Instead, I need the total point chosen from the suit that gives the highest point. The images shown are for reference purposes. import java.util.HashMap; import java.io.*; public class CardPointsList { static HashMap<String,Integer> Code = new HashMap<>(); static HashMap<Character,Integer> Order = new HashMap<>(); static String[][] hand= {{ "c5","s6","sK","dK","dA"},{"s7","s4","dJ","sA","h5"},{"sQ","d3","c9","hK","d5"}}; static int[] scores={0,0,0}; public static void sortHand() { String temp; for (int h=0;h<3;h++) {for (int i=0;i<5;i++) { for (int j=i+1;j<5;j++) { if (hand[h][j].charAt(0)…arrow_forwardRewrite Exercise 3.4 using the following func tion to return the area of a pentagon: def area(s):arrow_forwardWrite up Java source codes for compiling and execution of program below. Draw UML diagram for codes. There is a very simple solution to keeping Tic-tac-toe fresh and interesting, though, and it has been thought up by a group of mathematicians. It’s being called Ultimate Tic-tac-toe and simply embeds a Tic-tac-toe board in each of the nine squares of the original game. Now instead of just winning the main board, you also need to win each of the smaller boards first until you have a line of three. New Rule: You can only place a mark on the board determined by the position of your opponent’s last placed mark. So, if they put an X or O in the top right corner of a square, your next move must occur in the top right board. By adding that rule the game is no longer about winning a single board, it’s about tactically managing up to 9 games at once and plotting ahead. You still win by marking three squares in a row, but that now involves winning three games. The effects of the New Rule: 1:…arrow_forward
- You are learning how to repeat a set of actions, by using loops. There are several different kinds of loops, but the simplest are those that use a counter to control the number of repetitions. We call these counter-controlled loops, (or counted loops). The easiest way to write a counter-controlled loop is by using Java's for statement. The mechanics of using a for loop are the same as using a while loop, including: loop initialization loop condition loop update. The Java for statement provides a convenient syntax which includes all three of these elements in one statement.arrow_forwardWrite a program (in MATLAB) to read how many pixels are in "cameraman.tif", and add a white vertical line in the center of the ?(image (cameraman.tifarrow_forwardImplement the problem below in Python using mpi4py. Submit the code of your program and a brief report. The report should describe the design of your program, and demonstrate the results of running your program. n-body solver. Implement a parallel n-body solver with n = 10 particles. You may randomly generate the masses, initial velocities, and initial positions of all particles at the beginning. Compute the positions of all particles after 1 second. Compare the results by using 0.1s, 0.01s, and 0.001s as the time in each timestep, respectively.arrow_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