Other Master Degree-Master of Computer Management (M.C.M) 2nd Sem CORE RUBY(University of Pune, Pune-2013)
[4377]-205
M. C. M. (Semester - II) Examination - 2013
CORE RUBY
(New 2008 Pattern)
Time : 3 Hours] [Max. Marks : 70
Instructions :
(1) Question Nos. 1 and 7 are compulsory.
(2) Solve any four from the remaining.
(3) Figure to the right indicate full marks.
Q.1) Find the output for following program segments : (Any Five) [15]
(a) def say_goodnight(name)
result = “Good night, #{name}”
return result
end
puts say_goodnight(‘Pa’)
(b) def fib_up_to(max)
i1, i2, = 1, 1
while i1 < = max
yield i1
i1, i2 = i2, i1 + i2
end
end
fib_up_to(10) {|f| printf, “ ”}
puts
[4377]-205 1 P.T.O.
(c) square = 2
while square < 1000
puts square = square*square
end
(d) inst_section = {
‘cello’ =>‘string’,
‘clarinet’ => ‘woodwind’,
‘durm’ = > ‘percussion’,
‘oboe’ => ‘woodwind’,
‘trumpet’ => ‘brass’,
‘violin’ => ‘string’
}
puts inst_section[‘oboe’]
puts inst_section[‘cello’]
(e) def say_goodnight(name)
result = “Good night, #{name.capitalise}”
return result
end
puts say_goodnight(‘uncle’)
(f) class Array
def find
for i in 0.. size
value = self[i]
return value if yield(value)
end
return nil
end
end
puts[1, 3, 5, 7, 9]. find {|v| v*v > 30}
[4377]-205 2 Contd.Q.2) (A) Write a ruby function that accepts a year and returns “leap” if it is a leap year and “not a leap year” if it is not. [05]
(B) Write a ruby program that accepts a number from user and find whether it is a single digit, 2 digit or 3 digit no. [05]
Q.3) (A) Write a ruby program that accepts 15 numbers in an array and print maximum and minimum of the numbers. [05]
(B) Write a ruby program that accepts a string of words and reverse contents of every word in the string. [05]
Q.4) Design a class Student with instance variables(rollno, name, total_present_day). Write a calculate_fine method to calculate fine of the student (assume total number of lectures = 40 and fine for each day is Rs. 15. Fine should be calculated if percentage of lecturers attended is less than 70%). [10]
Q.5) Write a ruby program to create a file, store text in it. Also read the file character by character and display the contents in uppercase letters. [10]
Q.6) Design a class Stack with instance variables (array of 10 numbers, top of stack) and methods push(add element in array at top) and pop(remove element from top of array). Create an object and invoke the methods. [10]
Q.7) Write short notes : (Any Three) [15]
(a) Block and Procs
(b) Ruby Modules
(c) Hashes
(d) Regular Expressions with suitable example
(e) Exception Handling with example
Earning: ₹ 7.05/- |