User Tools

Site Tools


cs330_f2016:lab5

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

cs330_f2016:lab5 [2016/09/16 20:20]
dcostello
cs330_f2016:lab5 [2021/06/30 23:42]
Line 1: Line 1:
- 
-====Objective:​==== 
- 
-Learn the basics of the Julia Language. 
- 
----- 
- 
-====Preparation:​==== 
- 
-For this lab, you should use Julia v.0.4. ​ You may use the binary hosted in Dr. Wingate'​s home directory, at 
- 
-''/​users/​faculty/​wingated/​cs330/​languages/​julia-2e358ce975/​bin''​ 
- 
-or you may install Julia yourself. 
- 
----- 
- 
-====Deliverables:​==== 
- 
-For this lab, you will need to implement the following functions and data structures in Julia: 
-  * ''​area''​ 
-  * ''​in_shape''​ 
-  * ''​greyscale''​ 
-  * ''​invert''​ 
-  * ''​tree_map''​ 
-  * ''​add_last_name''​ 
-  * ''​eye_colors''​ 
- 
- 
-=== Shapes === 
-Define the following data structures. 
-<code Julia> 
-abstract shape 
- 
-type position 
-  x::Real 
-  y::Real 
-end 
- 
-type circ <: shape 
-  center::​position 
-  radius::​Real 
-end 
- 
-type square <: shape 
-  upper_left::​position 
-  length::​Real 
-end 
- 
-type rect <: shape 
-  upper_left::​position 
-  width::Real 
-  height::​Real 
-end 
-</​code>​ 
- 
- 
-=== Area === 
-<code Julia> 
-function area(Shape) ... 
-</​code>​ 
-Returns the area of the given shape. 
-where ''​Shape''​ is some concrete instance of the abstract shape type class. For this a few of the following instead of testing for class member ship it is easier to write three different functions, one for each concrete instance of shape. ie: ''​function area(shape::​rect)...''​ 
- 
-=== In_Shape=== 
-<code Julia> 
-function inside(Shape::​shape,​ Position::​position) ... 
-</​code>​ 
-Returns if the position is inside the shape. Assume standard math coordinates where y is positive going up. The bounds are inclusive. 
- 
-=== Pixel === 
-Define the Following type in your code 
-<code Julia> 
-type pixel 
-  r::Real 
-  b::Real 
-  g::Real 
-end 
-</​code>​ 
- 
-=== Greyscale == 
-<code Julia> 
-function greyscale(picture::​Array{pixel,​2}) ... 
-</​code>​ 
-Takes a 2d array of pixels and greys out each pixel. This is done by averaging together the r g b values and then setting r g b to the average. 
- 
-Hint: Julias map works over  multi-dimensional arrays 
- 
-=== invert === 
-<code Julia> 
-function invert(picture::​Array{pixel,​2}) ... 
-</​code>​ 
-Takes a 2d array and pixels and inverts each one. Inverting is done by setting r to `255 - r` and the other two in the same manner. 
- 
-=== Trees == 
-Define the folowing types in your code 
-<code Julia> 
-abstract treeItem 
- 
-type person <: treeItem 
-  name::​AbstractString 
-  birthyear::​Integer 
-  eyecolor::​symbol 
-  father::​treeItem 
-  mother::​treeItem 
-end 
-  
-type unknown <: treeItem 
-end 
-</​code>​ 
- 
-=== Count Persons === 
-<code Julia> 
-function count_persons(tree::​treeItem) 
-</​code>​ 
-Counts the number of people in the tree. Unknowns do not count as people. 
- 
-=== Average Age === 
-<code Julia> ​ 
-function average_age(tree::​treeItem) 
-</​code>​ 
-Calculates the average age of the people in the tree. Use this years date 2016. Unknowns do not count as people. 
- 
-=== tree map === 
-<code Julia> 
-function tree_map(f, tree::​treeItem) 
-</​code>​ 
-Takes a function f and applies it to each known member of the tree. The function f takes one parameter and returns a treeItem, that  
- 
-=== add last name=== 
-<code Julia> 
-function add_last_name(name::​AbstractString,​ tree::​treeItem) 
-</​code>​ 
-Appends name to the end of the name of each member of the tree.  
- 
-Hint: Julia uses ''​*''​ for string concatenation. 
- 
-=== eye_colors === 
-<code Julia> 
-function eye_colors(tree::​treeItem) 
-</​code>​ 
-Returns a list of all eye colors in the tree. A color can appear more than once. 
  
cs330_f2016/lab5.txt ยท Last modified: 2021/06/30 23:42 (external edit)