HMWK3
Due: 5 April 2018, by end of class
Take some time to examine some of the Ruby resources I've provided on the web page!
Also, please just email your code to the grader to hand it in. Easier for all.
1) Write a Ruby function which takes a list of integers, ignores the first three and then returns the sum of rest of the numbers.
2) Write a Ruby function which takes a single string and returns a string with only the odd (position) characters.
func("abcdef") => "ace"
func("hhiijjkk") => "hijk"
3) The following class definition is provided:
class Student
def initialize
@name = String.new()
@age = Integer
@id = Integer
@grade = Integer
end
def this?(id)
@id == id
end
def name()
@name
end
def name=(name)
@name=name
end
def age=(age)
@age=age
end
def id=(id)
@id = id
end
def grade()
@grade
end
def grade=(grade)
@grade=grade
end
end
Write a class which stores a collection of students.
It should implement the following four functions:
add(string,int,int,int) puts a new student record in the structure
find(int) returns the name (or error string) of the student with them matching id
top() returns the name of the student with the highest grade
median() returns the median age of the students