University Of Pune Question Paper
M. C. M. (Semester - II) Examination - 2010
CORE RUBY
(New 2008 Pattern)
Time : 3 Hours] [Max. Marks : 70
Instruction :
Question Nos. 1 and 7 are compulsory. Solve any four from the
rest.
Q.1) Find output of the following : (Any Five) [15]
(a) arr = [1, 2, 3, 4, 5]
sum = 0
arr.each {|i| sum + = i}
puts sum
(b) s = ‘Ruby=Gems’
i = s.index(‘=’)
puts s[0...i]
puts s[i + 1, s.length]
(c) i = 0
while (i < 15)
i + = 1
next if i % 2 == 0
puts i
end
[3877]-205 1 P.T.O.
(d) class Square
def initialize (side_length)
@side_length = side_length
end
def area
@side_length * @side_length
end
end
a = Square.new(25)
puts a.area
(e) x = {“a” = > 5, “b” = > 7, “c” = > 9}
x.each {|key, value| puts “#{key} equals#{value}”}
puts x.keys.inspect
(f) def basic_method
x = 75
puts x
end
x = 10
basic_method
puts x
(g) a = [2, 4, 6, 8 10, 12]
puts a[1..4].inspect
a[1..3] = [“a”, “b”, “c”]
puts a.inspect
[3877]-205 2 Contd.
Q.2) Write a program to print prime numbers between 200 to 300. [10]
Q.3) Write a program that reads a file and prints total number of words
in the file. [10]
Q.4) Design a class for Book_Master with instance variables (Bookid,
Bookname, AuthorName, and Price)
Write a routine to accept 10 records and store it in array.
Write a method MaxBooks that prints author’s name who had
written maximum books and also prints book details of that author. [10]
Q.5) Accept an array of 10 integers and count total number of odd
and even numbers. [10]
Q.6) Write a Ruby program to print the following pattern : [10]
12 3 4 3 2 1
1 2321
121
1
Q.7) Write short notes : (Any Three) [15]
(a) Nested Classes
(b) Blocks and Iterators
(c) Collections
(d) Procs and Lamdas
(e) Exception Handling
M. C. M. (Semester - II) Examination - 2010
CORE RUBY
(New 2008 Pattern)
Time : 3 Hours] [Max. Marks : 70
Instruction :
Question Nos. 1 and 7 are compulsory. Solve any four from the
rest.
Q.1) Find output of the following : (Any Five) [15]
(a) arr = [1, 2, 3, 4, 5]
sum = 0
arr.each {|i| sum + = i}
puts sum
(b) s = ‘Ruby=Gems’
i = s.index(‘=’)
puts s[0...i]
puts s[i + 1, s.length]
(c) i = 0
while (i < 15)
i + = 1
next if i % 2 == 0
puts i
end
[3877]-205 1 P.T.O.
(d) class Square
def initialize (side_length)
@side_length = side_length
end
def area
@side_length * @side_length
end
end
a = Square.new(25)
puts a.area
(e) x = {“a” = > 5, “b” = > 7, “c” = > 9}
x.each {|key, value| puts “#{key} equals#{value}”}
puts x.keys.inspect
(f) def basic_method
x = 75
puts x
end
x = 10
basic_method
puts x
(g) a = [2, 4, 6, 8 10, 12]
puts a[1..4].inspect
a[1..3] = [“a”, “b”, “c”]
puts a.inspect
[3877]-205 2 Contd.
Q.2) Write a program to print prime numbers between 200 to 300. [10]
Q.3) Write a program that reads a file and prints total number of words
in the file. [10]
Q.4) Design a class for Book_Master with instance variables (Bookid,
Bookname, AuthorName, and Price)
Write a routine to accept 10 records and store it in array.
Write a method MaxBooks that prints author’s name who had
written maximum books and also prints book details of that author. [10]
Q.5) Accept an array of 10 integers and count total number of odd
and even numbers. [10]
Q.6) Write a Ruby program to print the following pattern : [10]
12 3 4 3 2 1
1 2321
121
1
Q.7) Write short notes : (Any Three) [15]
(a) Nested Classes
(b) Blocks and Iterators
(c) Collections
(d) Procs and Lamdas
(e) Exception Handling
0 comments:
Pen down your valuable important comments below