Introduction To Programming: Pass Task 2.1T: Debug
Introduction To Programming: Pass Task 2.1T: Debug
Introduction to Programming
Pass Task 2.1T: Debug
Overview
This program will allow you to demonstrate simple debugging of Ruby code.
Purpose: Learn to correct programming errors.
Task: Correct the provided code so it works according to the specification.
Time: This task should be started in your second lab class and submitted for
feedback before the end of week 3.
Resources: Pine, C 2013 Learn to Program, The Pragmatic Programmer. (available in the library).
Submission Details
You must submit the following files to Doubtfire:
■ Corrected debug.rb source code
Make sure that your task has the following in your submission:
■ The program must read the required details from the user, and respond correctly
■ Code must follow the Ruby coding convention used in the unit (layout, and use of case).
■ Your program must have the indicated local variables, and use them appropriately.
Introduction to Programming Pass Task 2.1 Debug
Instructions
To explore this topic, we will correct a Terminal program that:
■ asks the user to enter their name and their age.
■ calculates and outputs the year the user was born
Note: these are tasks you have already done by now in other programs.
Look at the debug.rb program shown below and available in the Resources for the task:
# Asks the user to enter their age and returns an integer age
def get_age()
puts "Enter your age in years: "
age = gets
return age_in_years
end
# Calculate the year born based on the parameter age and print
# that out along with the user’s name.
def print_year_born(age)
year_born = Date.today.year - age
puts "You were born in: " + year_born
end
def main()
age = get_age()
name = get_string()
print_year_born(age)
end
main()
Introduction to Programming Pass Task 2.1 Debug
1. You may need to add the following code elements to correct the program:
Now that the Task is complete you can submit it for assessment, which will help prepare it for
your portfolio.
1. Use Skitch (or your preferred screenshot program) to take a screenshot of the
Terminal, as this is one of the things you will need to submit.
2. Save the document and backup your work to multiple locations!
• Once you get things working you do not want to lose them.
• Work on your computer’s storage device most of the time... but backup your
work when you finish each task.
• Use Dropbox or a similar online storage provider, as well as other locations.
• Doubtfire is not a Backup of your work, so make sure you keep a copy!
• A USB key and portable hard drives are good secondary backups... but can be lost/
damaged (do not rely upon them).
3. Login to Doubtfire, and locate Tutorial Task 2.1
4. Change the status of the task to Ready To Mark
5. Upload your completed code and the screenshot.
6. If you check back later Doubtfire will have prepared these as PDFs for your tutor to
assess.
You now have another of your first portfolio pieces. This will help demonstrate your learning
from the unit.
Note: This is one of the tasks you need to submit to Doubtfire. Check the assessment
criteria for the important aspect your tutor will check.