Question: require './input_functions' module Genre POP, CLASSIC, JAZZ, ROCK = *1..4 end $genre_names = ['Null', 'Pop', 'Classic', 'Jazz', 'Rock'] # Look at Task 5.1 T Music

require './input_functions'

module Genre

POP, CLASSIC, JAZZ, ROCK = *1..4

end

$genre_names = ['Null', 'Pop', 'Classic', 'Jazz', 'Rock']

# Look at Task 5.1 T Music Records for an example of how to create the following

class Track

attr_accessor :title, :location

def initialize (title, location)

@title = title

@location = location

end

end

# Returns an array of tracks read from the given file

def read_tracks music_file

count = music_file.gets().to_i

tracks = Array.new

# Put a while loop here which increments an index to read the tracks

track = read_track(music_file)

tracks << track

tracks

end

# reads in a single track from the given file.

def read_track aFile

# complete this function

# you need to create a Track here - see 5.1 T, Music Record for this too.

end

# Takes an array of tracks and prints them to the terminal

def print_tracks tracks

# Use a while loop with a control variable index

# to print each track. Use tracks.length to determine how

# many times to loop.

# Print each track use: tracks[index] to get each track record

end

# Takes a single track and prints it to the terminal

def print_track track

puts('Track title is: ' + track.title)

puts('Track file location is: ' + track.file_location)

end

# Open the file and read in the tracks then print them

def main

aFile = File.new("input.txt", "r") # open for reading

if aFile # if nil this test will be false

tracks = read_tracks(aFile)

aFile.close

else

puts "Unable to open file to read!"

end

# Print all the tracks

print_tracks(tracks)

end

main

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!