Solution to Write a program to read from a file containing the details of a restaurant order. … - Sikademy
Author Image

Archangel Macsika

Write a program to read from a file containing the details of a restaurant order. The details in the file include the item number, quantity and price. Store the details of at least five items in the file. Calculate the subtotal by adding the total price for each item which can be obtained by multiplying the quantity and price for each item. Calculate the tax, the tax rate can be assumed as 7%. Find the total price after adding the tax to the subtotal.

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 restaurant_orders(file_path, total_holder)
	if (File.exist?(file_path))
		File.open(file_path, "r") do |read_all_data|
				while line = read_all_data.gets
					res_order = line.split(" ")
					calc_total = res_order[1].to_i + res_order[2].to_i
					total_holder << calc_total
				end		
				total = total_holder.inject {|x, y| x + y}
				tax = total * (7.0/100)
				puts "Total Price without Tax = %d" % [(total)]
				puts "Total Price with Tax = %d" % [(total + tax.to_f)]
		end
	else
			puts "Sorry, the requested file does not exist."
	end
end
restaurant_orders("restaurant_orders.txt", [])

If you would like to see a different solution or an implementation in a different programming language Kindly let us know



Related Answers

Was this answer helpful?

Join our Community to stay in the know

Get updates for similar and other helpful Answers

Question ID: mtid-3-stid-9-sqid-2-qpid-2