SlideShare a Scribd company logo
The provided code:
*track_file_handling.rb
class Track
attr_accessor :name, :location
def initialize (name, location)
@name = name
@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
return tracks
end
# reads in a single track from the given file.
def read_track(a_file)
# complete this function
# you need to create a Track here.
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.name)
puts(track.location)
end
# Open the file and read in the tracks then print them
def main()
a_file = File.new("input.txt", "r") # open for reading
# Print all the tracks
print_tracks(tracks)
end
main()
*input.txt
3
Crackling Rose
sounds/01-Cracklin-rose.wav
Soolaimon
sounds/06-Soolaimon.wav
Sweet Caroline
sounds/20-Sweet_Caroline.wav
Can anyone pls help me with this Ruby task, it's urgent. Thx! Use the code provided to get
started. You must enhance the code provided as follows: - Complete the provided code so that it
reads in an array of tracks then prints them out. The program output (using the file input.txt)
should look as follows: MacBook-Pro-6:TuteTasks mmitchel1s ruby music_tracks_only.rb
Crackling Rose sounds/01-Cracklin-rose.wav Soolaimon sounds/06-Soolaimon.wav Sweet
Caroline sounds/20-Sweet_Caroline.wav MacBook-Pro-6:TuteTasks mmitchel1s Once your
program is running upload a screenshot to the workspace. Below is a structure chart for this task:

More Related Content

Similar to The provided codetrack_file_handling.rb class Track att.pdf

390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.ppt
mugeshmsd5
 
List command linux fidora
List command linux fidoraList command linux fidora
List command linux fidoraJinyuan Loh
 
Shell programming
Shell programmingShell programming
Shell programming
Moayad Moawiah
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 
Linux basics
Linux basicsLinux basics
Linux basics
BhaskarNeeluru
 
QSpiders - Unix Operating Systems and Commands
QSpiders - Unix Operating Systems  and CommandsQSpiders - Unix Operating Systems  and Commands
QSpiders - Unix Operating Systems and Commands
Qspiders - Software Testing Training Institute
 
File
FileFile
File
Acad
 
Linux And perl
Linux And perlLinux And perl
Linux And perl
Sagar Kumar
 
I need help writing the methods for the song and playList class in J.pdf
I need help writing the methods for the song and playList class in J.pdfI need help writing the methods for the song and playList class in J.pdf
I need help writing the methods for the song and playList class in J.pdf
arihanthtextiles
 
Termux commands-list
Termux commands-listTermux commands-list
Termux commands-list
DhanushR24
 
Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013
Wave Digitech
 
File_Management_in_C
File_Management_in_CFile_Management_in_C
File_Management_in_C
NabeelaNousheen
 
Linux
LinuxLinux
Write a program in C++ language that implements a music play.pdf
Write a program in C++ language that implements a music play.pdfWrite a program in C++ language that implements a music play.pdf
Write a program in C++ language that implements a music play.pdf
iconsystemsslm
 
Chapter 4 Linux Basic Commands
Chapter 4 Linux Basic CommandsChapter 4 Linux Basic Commands
Chapter 4 Linux Basic Commands
Shankar Mahure
 
awkbash quick ref for Red hat Linux admin
awkbash quick ref for Red hat Linux adminawkbash quick ref for Red hat Linux admin
awkbash quick ref for Red hat Linux admin
ZoumanaDiomande1
 
Lecture1 2 intro-unix
Lecture1 2 intro-unixLecture1 2 intro-unix
Lecture1 2 intro-unixnghoanganh
 
Need help with this java project, as the methods are proving to be p.pdf
Need help with this java project, as the methods are proving to be p.pdfNeed help with this java project, as the methods are proving to be p.pdf
Need help with this java project, as the methods are proving to be p.pdf
prajeetjain
 
Group13
Group13Group13

Similar to The provided codetrack_file_handling.rb class Track att.pdf (20)

390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.ppt
 
List command linux fidora
List command linux fidoraList command linux fidora
List command linux fidora
 
Shell programming
Shell programmingShell programming
Shell programming
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 
Linux basics
Linux basicsLinux basics
Linux basics
 
QSpiders - Unix Operating Systems and Commands
QSpiders - Unix Operating Systems  and CommandsQSpiders - Unix Operating Systems  and Commands
QSpiders - Unix Operating Systems and Commands
 
File
FileFile
File
 
Linux And perl
Linux And perlLinux And perl
Linux And perl
 
I need help writing the methods for the song and playList class in J.pdf
I need help writing the methods for the song and playList class in J.pdfI need help writing the methods for the song and playList class in J.pdf
I need help writing the methods for the song and playList class in J.pdf
 
Termux commands-list
Termux commands-listTermux commands-list
Termux commands-list
 
Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013
 
File_Management_in_C
File_Management_in_CFile_Management_in_C
File_Management_in_C
 
Linux
LinuxLinux
Linux
 
Linux ppt
Linux pptLinux ppt
Linux ppt
 
Write a program in C++ language that implements a music play.pdf
Write a program in C++ language that implements a music play.pdfWrite a program in C++ language that implements a music play.pdf
Write a program in C++ language that implements a music play.pdf
 
Chapter 4 Linux Basic Commands
Chapter 4 Linux Basic CommandsChapter 4 Linux Basic Commands
Chapter 4 Linux Basic Commands
 
awkbash quick ref for Red hat Linux admin
awkbash quick ref for Red hat Linux adminawkbash quick ref for Red hat Linux admin
awkbash quick ref for Red hat Linux admin
 
Lecture1 2 intro-unix
Lecture1 2 intro-unixLecture1 2 intro-unix
Lecture1 2 intro-unix
 
Need help with this java project, as the methods are proving to be p.pdf
Need help with this java project, as the methods are proving to be p.pdfNeed help with this java project, as the methods are proving to be p.pdf
Need help with this java project, as the methods are proving to be p.pdf
 
Group13
Group13Group13
Group13
 

More from fashination

The OSI reference model Select all of the following statements that.pdf
The OSI reference model Select all of the following statements that.pdfThe OSI reference model Select all of the following statements that.pdf
The OSI reference model Select all of the following statements that.pdf
fashination
 
This is business law but it is not an available option for subjects..pdf
This is business law but it is not an available option for subjects..pdfThis is business law but it is not an available option for subjects..pdf
This is business law but it is not an available option for subjects..pdf
fashination
 
the header file code for double link list#include iostream#.pdf
the header file code for double link list#include iostream#.pdfthe header file code for double link list#include iostream#.pdf
the header file code for double link list#include iostream#.pdf
fashination
 
There are two views regarding the social responsibility of business.pdf
There are two views regarding the social responsibility of business.pdfThere are two views regarding the social responsibility of business.pdf
There are two views regarding the social responsibility of business.pdf
fashination
 
There are several different methods of data gathering in research. Her.pdf
There are several different methods of data gathering in research. Her.pdfThere are several different methods of data gathering in research. Her.pdf
There are several different methods of data gathering in research. Her.pdf
fashination
 
There are several different methods of data gathering in research. H.pdf
There are several different methods of data gathering in research. H.pdfThere are several different methods of data gathering in research. H.pdf
There are several different methods of data gathering in research. H.pdf
fashination
 
The Windows CreateProcess() system call creates a new process. What .pdf
The Windows CreateProcess() system call creates a new process. What .pdfThe Windows CreateProcess() system call creates a new process. What .pdf
The Windows CreateProcess() system call creates a new process. What .pdf
fashination
 
The Seven Major Sources of Economic Progress are a framework that .pdf
The Seven Major Sources of Economic Progress are a framework that .pdfThe Seven Major Sources of Economic Progress are a framework that .pdf
The Seven Major Sources of Economic Progress are a framework that .pdf
fashination
 
The following MATLAB code generates the plot of the unit-sample resp.pdf
The following MATLAB code generates the plot of the unit-sample resp.pdfThe following MATLAB code generates the plot of the unit-sample resp.pdf
The following MATLAB code generates the plot of the unit-sample resp.pdf
fashination
 
The financial statements and industry norms are shown below for Ever.pdf
The financial statements and industry norms are shown below for Ever.pdfThe financial statements and industry norms are shown below for Ever.pdf
The financial statements and industry norms are shown below for Ever.pdf
fashination
 
The plaintiff, Smith, is a United States Marine Corps veteran. He su.pdf
The plaintiff, Smith, is a United States Marine Corps veteran. He su.pdfThe plaintiff, Smith, is a United States Marine Corps veteran. He su.pdf
The plaintiff, Smith, is a United States Marine Corps veteran. He su.pdf
fashination
 

More from fashination (11)

The OSI reference model Select all of the following statements that.pdf
The OSI reference model Select all of the following statements that.pdfThe OSI reference model Select all of the following statements that.pdf
The OSI reference model Select all of the following statements that.pdf
 
This is business law but it is not an available option for subjects..pdf
This is business law but it is not an available option for subjects..pdfThis is business law but it is not an available option for subjects..pdf
This is business law but it is not an available option for subjects..pdf
 
the header file code for double link list#include iostream#.pdf
the header file code for double link list#include iostream#.pdfthe header file code for double link list#include iostream#.pdf
the header file code for double link list#include iostream#.pdf
 
There are two views regarding the social responsibility of business.pdf
There are two views regarding the social responsibility of business.pdfThere are two views regarding the social responsibility of business.pdf
There are two views regarding the social responsibility of business.pdf
 
There are several different methods of data gathering in research. Her.pdf
There are several different methods of data gathering in research. Her.pdfThere are several different methods of data gathering in research. Her.pdf
There are several different methods of data gathering in research. Her.pdf
 
There are several different methods of data gathering in research. H.pdf
There are several different methods of data gathering in research. H.pdfThere are several different methods of data gathering in research. H.pdf
There are several different methods of data gathering in research. H.pdf
 
The Windows CreateProcess() system call creates a new process. What .pdf
The Windows CreateProcess() system call creates a new process. What .pdfThe Windows CreateProcess() system call creates a new process. What .pdf
The Windows CreateProcess() system call creates a new process. What .pdf
 
The Seven Major Sources of Economic Progress are a framework that .pdf
The Seven Major Sources of Economic Progress are a framework that .pdfThe Seven Major Sources of Economic Progress are a framework that .pdf
The Seven Major Sources of Economic Progress are a framework that .pdf
 
The following MATLAB code generates the plot of the unit-sample resp.pdf
The following MATLAB code generates the plot of the unit-sample resp.pdfThe following MATLAB code generates the plot of the unit-sample resp.pdf
The following MATLAB code generates the plot of the unit-sample resp.pdf
 
The financial statements and industry norms are shown below for Ever.pdf
The financial statements and industry norms are shown below for Ever.pdfThe financial statements and industry norms are shown below for Ever.pdf
The financial statements and industry norms are shown below for Ever.pdf
 
The plaintiff, Smith, is a United States Marine Corps veteran. He su.pdf
The plaintiff, Smith, is a United States Marine Corps veteran. He su.pdfThe plaintiff, Smith, is a United States Marine Corps veteran. He su.pdf
The plaintiff, Smith, is a United States Marine Corps veteran. He su.pdf
 

Recently uploaded

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 

Recently uploaded (20)

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 

The provided codetrack_file_handling.rb class Track att.pdf

  • 1. The provided code: *track_file_handling.rb class Track attr_accessor :name, :location def initialize (name, location) @name = name @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 return tracks end # reads in a single track from the given file. def read_track(a_file) # complete this function # you need to create a Track here. 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.name)
  • 2. puts(track.location) end # Open the file and read in the tracks then print them def main() a_file = File.new("input.txt", "r") # open for reading # Print all the tracks print_tracks(tracks) end main() *input.txt 3 Crackling Rose sounds/01-Cracklin-rose.wav Soolaimon sounds/06-Soolaimon.wav Sweet Caroline sounds/20-Sweet_Caroline.wav Can anyone pls help me with this Ruby task, it's urgent. Thx! Use the code provided to get started. You must enhance the code provided as follows: - Complete the provided code so that it reads in an array of tracks then prints them out. The program output (using the file input.txt) should look as follows: MacBook-Pro-6:TuteTasks mmitchel1s ruby music_tracks_only.rb Crackling Rose sounds/01-Cracklin-rose.wav Soolaimon sounds/06-Soolaimon.wav Sweet Caroline sounds/20-Sweet_Caroline.wav MacBook-Pro-6:TuteTasks mmitchel1s Once your program is running upload a screenshot to the workspace. Below is a structure chart for this task: