-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mahfuz_assignment_1.rb
62 lines (43 loc) · 1000 Bytes
/
Mahfuz_assignment_1.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#Question 1
class Circle
@@pi=3.14;
def initialize(radius)
@radius=radius
end
def get_area()
puts "Area is #{@@pi*@radius*@radius}"
end
def get_circumference()
puts "Circumference is #{2*@@pi*@radius}"
end
end
c1=Circle.new(5)
c1.get_area()
c1.get_circumference
#Question 2
class ConvertToString
def convert()
puts "Enter a number"
num=gets.chomp
num=num.to_f
puts "$#{num.round(2).to_s}"
end
end
n=ConvertToString.new()
n.convert()
Question 3
class Temperature
def convert_to_Fahrenheit()
puts "Enter degree celcius to convert to fahreinheit"
degree=gets.chomp.to_i
puts "#{degree*(9/5.0)+32} degree fahrenheit"
end
def convert_to_celcius()
puts "Enter degree in fahrenheit to convert to celcius"
fah=gets.chomp.to_i
puts "#{(fah-32)*(5/9.0)} celcius"
end
end
obj=Temperature.new
obj.convert_to_Fahrenheit
obj.convert_to_celcius