Solution to Three employees in a company are up for a special pay increase. You are given … - Sikademy
Author Image

Archangel Macsika

Three employees in a company are up for a special pay increase. You are given a file, say Data.txt, with the following data: Miller Andrew 65789.87 5 Green Sheila 75892.56 6 Sethi Amit 74900.50 6.1 Each input line consists of an employee's last name, first name, current salary, and percent pay increase. For example, in the first input line, the last name of the employee is Miller, the first name is Andrew, the current salary is 65789.87, and pay increase is 5%. Write a program that reads data from the specified file and stores the output in the file Output.dat. For each employee, the data must be output in the following form: firstName lastName updatedSalary. Format the output of decimal numbers to 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 data_transfer(from_path, to_path)
	if (File.exist?(from_path))
			File.open(from_path, "r") do |read_all_data|
				to_file = File.open(to_path, "w+")
				to_file.puts "First Name | Last Name | Updated Salary"
					while each_line = read_all_data.gets
						file_contents = (each_line[/\w+\s\w+\s(\d+[.]\d+)\s+(\d+[.]\d+|\d+)\Z/]).split(" ")
						to_file.puts "#{file_contents[0]}     |  #{file_contents[1]}   |   #{(file_contents[2].to_f * (file_contents[3].to_f/100)).round(2)}"
					end
				puts "Operation successful!"
			end
	else
		puts "Sorry, the requested file does not exist."
	end
end
data_transfer("Data.txt",  "output.dat")

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-1-qpid-1