The manager of a football stadium wants you to write a program that calculates the total ticket sales after each game. There are four types of tickets: box, sideline, premium, and general admission. After each game, data is stored in a file in the following form: ticketPrice numberOfTicketsSold ... Sample data are shown below: 250 5750 100 28000 50 35750 25 18750 The first line indicates that the ticket price is $250 and that 5750 tickets were sold at that price. Output the number of tickets sold and the total sale amount. Format your output with two decimal places.
The Answer to the Question
is below this banner.
Can't find a solution anywhere?
NEED A FAST ANSWER TO ANY QUESTION OR ASSIGNMENT?
Get the Answers Now!You will get a detailed answer to your question or assignment in the shortest time possible.
Here's the Solution to this Question
Solution in Ruby Programming Language
def ticket_calculator(file_path, tickets, prices)
if (File.exist?(file_path))
File.open(file_path, "r") do |read_all_data|
while line = read_all_data.gets
data_collector = line.split( )
tickets.push data_collector[0]
prices.push data_collector[1]
end
puts "Total Tickets = " + (tickets.map {|a| a.to_i}.inject {|a, b| a + b}).to_s
puts "Total Price = " + (prices.map {|a| a.to_i}.inject {|a, b| a + b}).to_s
end
else
puts "Sorry, the requested file does not exist."
end
end
ticket_calculator("ticket_data.txt", Array.new, Array.new)
If you would like to see a different solution or an implementation in a different programming language Kindly let us know