//today i wrote the sample code of shopping details in ruby
sum=0
for i in 1..2
puts "enter the item name"
name=gets
puts "enter the no.of quantity"
qty=gets.to_i
puts "enter the price details $"
price=gets.to_i
total=qty*price
x=puts "the total price for the #{name} is #{price} and total billed today is #{total} thanks for nice day"
end
puts x
///sample code for railway reservation counter
class RailwayReservation
def enquiry
puts "Welcome to the chennai railway station"
puts "enter ur pnr number"
@x=gets.chomp
end
def reservation
puts "enter the source and destination"
@y=gets.chomp
puts "enter the number of persons to travel"
@z=gets.chomp.to_i
end
def calculation
puts "your Pnr number is #{@x}"
@total= @z * 250
puts "the total fare for #{@z} persons is #{@total}"
end
obj =RailwayReservation.new()
obj.enquiry
obj.reservation
obj.calculation
end
No comments:
Post a Comment