`CS 170: Introduction to Computer Science I `

homework代写 | aws | 代写unity | assignment – 这道题目是利用aws进行的编程代写任务, 包括了aws/unity等方面, 这是值得参考的assignment代写的题目

```
CS 170: Introduction to Computer Science I Fall 2018
homework assignment #
Due by Wednesday, April 10, 2019 at 4:00 pm
```

**Submission instructions**

Submit your assignment through the QTest system, using class ID **CS170** and exam ID **hw4**. If you submit with a teammate, select team size 2 and login with the IDs of both members of the team. No email submissions are accepted. No late submissions are accepted.

**General instructions and hints**

In those problems asking you to write a method, always call the method several times to test that it works properly with a variety of different values for the parameters. Test it on more examples than the ones shown in this handout. Even if the problem asks you for just one method, you can always write additional helper methods to simplify and organize your code. Make sure you write comments to explain your code.

**Comment requirements: Always comment the top of each method (what the method does, the meaning of the input parameters, the meaning of the output value). Write comments within the methods to explain the strategy you are using to solve the problem, and to clarify blocks of code that may be difficult to understand.**

**Problem 1: Is reverse (6 points)**

Write a recursive method isReverse(String s1, String s2) that takes two strings and returns true if s1 is the reverse of s2, false otherwise. Then, draw the sequence of recursive calls for the following cases. Submit your diagrams in a PDF file called isReverseTrace.pdf.

```
isReverse("happy", "yppah") will return true
isReverse("cool", "loac") will return false
isReverse("", "") will return true
```

**Rubric: programs that do not compile get zero points +3 correct implementation (1 point for a partially correct solution. Zero if the solution is far from correct) -1 incorrect method signature (method name, number of parameters, and types of parameters) -1 if there are no test cases -1 if there are no comments, insufficient comments, or bad usage of comments Traces: +3 points (1 point each). If the file is not a PDF, zero points.**

**Problem 2: Turtle spiral (6 points)**

Using turtle graphics and recursion, Write a method turtleSpiral(Turtle t, double size, double minSize) that dr aws squared spirals like the one in the figure. The spiral starts from the outside (the longest side) and ends with the shortest side. The longest side has length equal to size, and each following side is 10% shorter than the previous one. The length of the shortest side is no shorter than minSize.

Then write the same method again, but using iteration instead of recursion. Call this method turtleSpiralIter(Turtle t, double size, double minSize). Make sure the two methods draw exactly the same spirals in all the cases. Take this opport unity to reflect about similarities and differences between iteration and recursion.

**Rubric: programs that do not compile get zero points For each method: +3 correct implementation (1 point for a partially correct solution. Zero points if the solution is far from correct) -1 incorrect method signature (method name, number of parameters, and types of parameters) -1 if there are no test cases -1 if there are no comments, insufficient comments, or bad usage of comments**

**Problem 3: Fractal flowers (2 points for simpleFlower; 5 points for fractalFlower)**

Using turtle graphics, you will create beautiful fractal flowers.

**3.A.** Write a method simpleFlower(Turtle t, double size) that takes a Turtle and a number representing the size of the flower. Your method will draw the following figure:

The position and orientation of the flower will depend on the initial position and orientation of the turtle. The origin of the flower is the bottom part of the stem, and its length develops straight ahead on the current direction of the turtle. When your method terminates, the turtle should be back to the same position and the same orientation it started from.

```
si
```

```
ze
```

```
size * 2.0/3.
```

**3.B.** Write a method fractalFlower(Turtle t, double size, int level) that takes a Turtle, a double representing the size of the flower, and an integer representing the maximum level (depth) of recursion. Your method will paint a recursive fractal flower with the same basic shape outlined above, but with each petal recursively replaced by a scaled down version of the flower itself. For example, a fractal flower with a maximum recursion level of 4 will result in a picture like this one:

Your program should include some test code that draws three flowers, all of them facing up, on three different positions of the screen: (a) a simple flower of size 200; (b) a fractal flower of depth 3 and size 250; and (c) a fractal flower of depth 4 and size 300. Your three test flowers should not overlap.

Notice that the method simpleFlower that you implemented before was only for understanding and practicing the structure: you don’t need to call that method in fractalFlower.

**Rubric: programs that do not compile get zero points Implementation: +2 points for simpleFlower; +5 points for fractalFlower (1-3 points for a partially correct solution. Zero points if the solution is far from correct) -1 incorrect method signature (method name, number of parameters, and types of parameters) -1 if there are no test cases -1 if there are no comments, insufficient comments, or bad usage of comments**

**Problem 4: Fractal Mickey Mouse (2 points for mickeyFace; 5 points for fractalMickeyMouse)**

Using turtle graphics, you will create a funny fractal cartoon character inspired by Disney’s Mickey Mouse.

**4.A.** Write a method mickeyFace(Turtle t, double r) that draws a circular-shaped face of a Mickey-like character, without ears. This method takes a Turtle and the radius r of the face. The turtle starts and

ends drawing in the center of the face. The exact details of the face are up to your creativity (they dont necessarily have to be identical to the picture); just make sure it has at least two eyes, a nose, and a mouth.

**4.B.** Using your previous method mickeyFace, write a method fractalMickeyMouse(Turtle t, double r, int level) that recursively draws a character with the face you previously defined, and a recursively downsized version of that same face as ears. Your method will take as parameter a Turtle, the radius r

of the face, and an integer level representing the maximum depth of recursion. The radius of each ear is exactly

half the radius of the face. Hint: if you do not manage to complete mickeyFace on time, you can replace it with a plain circle of the correct size. The following figure shows an example of a Fractal Mickey Mouse with maximum recursion level (depth) of 6.

Your program should include some test code that draws a Fractal Mickey Mouse of depth 6. Coloring the background is optional.

**Hint:** If you want to fill areas with colors you can use the method fill() from the Turtle library. This method flood-fills an area with the turtle’s current color. Just move the turtle inside the area you want to color (it won’t work if it is on the border) and call t.fill(), where t is a Turtle object.

**Rubric: programs that do not compile get zero points Implementation: +2 points for mickeyFace; +5 points for fractalMickeyMouse (1-3 points for a partially correct solution. Zero points if the solution is far from correct) -1 incorrect method signature (method name, number of parameters, and types of parameters) -1 if there are no test cases -1 if there are no comments, insufficient comments, or bad usage of comments No penalty for imperfections in filling (unless the result is very messy)**

**Problem 5: Fractal sun (7 points)**

Using turtle graphics, you will paint a majestic fractal sun. The fractal sun is composed of a circle of radius r, and 8 rays of length 2*r originating from the center of the circle and radially equally spaced. The external tip of each ray is also the origin of a recursively downsized fractal sun with radius equal to 1/4 of the radius of the sun at the previous level. Also, the suns originating at the tip of the rays will have different colors, i.e., the color of a sun is a method of the recursion level of the fractal sun itself. You can invent the coloring method you prefer, just make sure that your sun will look good no matter what the maximum level of recursion is going to be. Coloring the background is optional.

Your fractal sun will be generated by a method fractalSun(Turtle t, double r, int level) which you will write. Your method will take as parameter a Turtle, the radius r of the sun’s circle, and an integer

level representing the maximum depth of recursion of your fractal sun.

The following picture shows a fractal sun with a maximum recursion depth of 5, with colors fading from yellow to red.

Your program should include some test code that draws a fractal sun of depth 5.

**Rubric: programs that do not compile get zero points Implementation: +7 points (1-5 points for partially correct solution. Zero if the solution is far from correct) -1 incorrect method signature (method name, number of parameters, and types of parameters) -1 if there are no test cases -1 if there are no comments, insufficient comments, or bad usage of comments No penalty for imperfections in filling (unless the result is very messy)**

**Problem 6: Your own fractal (7 points)**

Using turtle graphics, design and implement your own fractal. Be creative! Your program should include:

- A comment section at the top of the code explaining the structure of the fractal.
- A creative usage of colors that change as a function of the level of recursion.
- Some controlled randomness to vary the structure of your fractal and make it more interesting.
- In the main method, you should draw several versions of your fractal with different depth of recursion.

**Rubric: programs that do not compile get zero points +3 points for basic fractal +1 point for comment explaining the structure of fractal +1 point for changing colors as a function of the level +1 point for usage of randomness +1 point for main method -1 if there are no comments, insufficient comments, or bad usage of comments**

**Bonus points: Early submission**

If you submit the entire homework no later than 48 hours before the deadline, and the total score on the rest of this homework assignment is at least 20 points, you will receive 2 bonus points. The bonus point will be added to the total score of this homework assignment.

**Good luck and have fun!**