University Of Pune Question Paper
M. C. M. (Semester - II) Examination - 2012
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 Question Nos. 2 to 6.
Q.1) Find the output : (Any Five) [3x5=15]
(a) [‘cat’, ‘dog’, ‘horse’]. each {|name| print name, “ ”}
5.times {print “ * ”}
3.upto (6) {|i| print i}
(‘a’ .. ‘e’). each {|char| print char}
puts.
(b) a = [‘ant’, ‘bee’, ‘cat’, ‘dog’, ‘elk’]
puts a[0]
puts a[3]
a[5] = ‘ram’
puts a
[4277]-205 1 P.T.O.
Seat
No.
(c) def call-block
puts “Start of Method”
yield
yield
puts “End of Method”
end
call_back {puts “In the Block”}
(d) 3.times {print “x”}
1.upto(5) . {|i| print i, “ ”}
99.downto(95) {|i| print i, “ ”}
50.step (80, 5) {|i| print i, “ ”}
puts
(e) x = [ ]
x << “good morning”
x = << “good afternoon”
x = << “good evening”
puts x.pop
puts x.pop
puts x.length
(f) Class Allvowels
include Enumerable
@@ vowels = %w {a, e, i, o, u}
def each
@@ vowels. each {|v|. yield v}
end
end
x = Allvowels.new
x. collect {|i| print i + “x”}
[4277]-205 2 Contd.
(g) def routine (n)
puts n
throw : done if n < = 0
routine (n – 1)
end
catch (:done) {routine (4)}
Q.2) Write a ruby program to swap the content of 2 text files. [10]
Q.3) Write a ruby program to display balance, use class account with two
methods deposit and with draw accept acocunt_no, account_balance,
cust_name. [10]
(a) When customer deposit amount that account_balance must be
updated.
(b) When customer withdraw some amount the account_balance must
be updated.
Q.4) Write a Ruby Program to find the size of file, words, characters with
space, characters without spaces.
# assumptions : the file exist in the same folder as the program. [10]
Q.5) Accept a sentence and replace all capital with lower and lower with
capital and special character with ‘&’.
Input : My email id IS xyz @ gmail.com.
Output : MY EMAIL ID is xyz@GMAIL.COM
Q.6) Write a Ruby Program to display where driver is insured as not, input
following variables (name, gender, age, status). Consider following
assumption drivers are inscured in following condition : [10]
(a) Married
(b) Male and age greater than 35
(c) Female and age greater than 25
[4277]-205 3 P.T.O.
Q.7) Write short notes : (Any Three) [5x3=15]
(a) Explain different types of Array in Ruby with example.
(b) Exception handling with example
(c) Scope of variables, local, global, class, instance
(d) Ruby Modules
(e) Duck Typing
M. C. M. (Semester - II) Examination - 2012
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 Question Nos. 2 to 6.
Q.1) Find the output : (Any Five) [3x5=15]
(a) [‘cat’, ‘dog’, ‘horse’]. each {|name| print name, “ ”}
5.times {print “ * ”}
3.upto (6) {|i| print i}
(‘a’ .. ‘e’). each {|char| print char}
puts.
(b) a = [‘ant’, ‘bee’, ‘cat’, ‘dog’, ‘elk’]
puts a[0]
puts a[3]
a[5] = ‘ram’
puts a
[4277]-205 1 P.T.O.
Seat
No.
(c) def call-block
puts “Start of Method”
yield
yield
puts “End of Method”
end
call_back {puts “In the Block”}
(d) 3.times {print “x”}
1.upto(5) . {|i| print i, “ ”}
99.downto(95) {|i| print i, “ ”}
50.step (80, 5) {|i| print i, “ ”}
puts
(e) x = [ ]
x << “good morning”
x = << “good afternoon”
x = << “good evening”
puts x.pop
puts x.pop
puts x.length
(f) Class Allvowels
include Enumerable
@@ vowels = %w {a, e, i, o, u}
def each
@@ vowels. each {|v|. yield v}
end
end
x = Allvowels.new
x. collect {|i| print i + “x”}
[4277]-205 2 Contd.
(g) def routine (n)
puts n
throw : done if n < = 0
routine (n – 1)
end
catch (:done) {routine (4)}
Q.2) Write a ruby program to swap the content of 2 text files. [10]
Q.3) Write a ruby program to display balance, use class account with two
methods deposit and with draw accept acocunt_no, account_balance,
cust_name. [10]
(a) When customer deposit amount that account_balance must be
updated.
(b) When customer withdraw some amount the account_balance must
be updated.
Q.4) Write a Ruby Program to find the size of file, words, characters with
space, characters without spaces.
# assumptions : the file exist in the same folder as the program. [10]
Q.5) Accept a sentence and replace all capital with lower and lower with
capital and special character with ‘&’.
Input : My email id IS xyz @ gmail.com.
Output : MY EMAIL ID is xyz@GMAIL.COM
Q.6) Write a Ruby Program to display where driver is insured as not, input
following variables (name, gender, age, status). Consider following
assumption drivers are inscured in following condition : [10]
(a) Married
(b) Male and age greater than 35
(c) Female and age greater than 25
[4277]-205 3 P.T.O.
Q.7) Write short notes : (Any Three) [5x3=15]
(a) Explain different types of Array in Ruby with example.
(b) Exception handling with example
(c) Scope of variables, local, global, class, instance
(d) Ruby Modules
(e) Duck Typing
0 comments:
Pen down your valuable important comments below