Skip to main content
BSC Moodle
Log in
  • Moodle Home
  • MyBSC Links
    Academic Alerts (formerly Starfish) Apogee BSC Email BSC Intranet BSC Website Change Password Colleague Events Records IT Helpdesk IT Help for Online Course Students Library MobilePrint OrgSync TheSIS Time & Attendance Trakstar
  • Moodle FAQs
  1. Home
  2. Courses
  3. Miscellaneous
  4. 22FA_CAC180A
  5. Week Six: 9/26-9/30
  6. Lab #6: Functions

22FA_CAC180A-Programming

Lab #6: Functions

Completion requirements
Make a submission
Opened: Tuesday, 27 September 2022, 12:00 AM
Due: Friday, 30 September 2022, 11:59 PM

Please complete the following two problems. The first problem will help you with the second problem. 

1. Words like first, second and third are referred to as ordinal numbers. In this exercise, you will write a function that takes an integer as its only parameter and returns a string containing the appropriate English ordinal number as its only result. Your function must handle the integers between 1 and 12 (inclusive). It should return an empty string if a value outside of this range is provided as a parameter. Include a main program that demonstrates your function by displaying each integer from 1 to 12 and its ordinal number. 

2. The Twelve Days of Christmas is a repetitive song that describes an increasingly long list of gifts sent to one’s true love on each of 12 days. A single gift is sent on the first day. A new gift is added to the collection on each additional day, and then the complete collection is sent. The first three verses of the song are shown below.

The complete lyrics are available on the internet.

On the first day of Christmas
my true love sent to me:
A partridge in a pear tree.

On the second day of Christmas
my true love sent to me:
Two turtle doves,
And a partridge in a pear tree.

On the third day of Christmas
my true love sent to me:
Three French hens,
Two turtle doves,
And a partridge in a pear tree.

Your task is to write a program that displays the complete lyrics for The Twelve Days of Christmas. Write a function that takes the verse number as its only parameter and displays the specified verse of the song. Then call that function 12 times with integers that increase from 1 to 12.

Each item that is sent to the recipient in the song should only appear once in your program, with the possible exception of the partridge. It may appear twice if that helps you handle the difference between “A partridge in a pear tree” in the first verse and “And a partridge in a pear tree” in the subsequent verses. Use your solution to Problem #1 to help you complete this exercise.

◄ Slides: Functions
12 Days of Christmas Code ►

Moodle Help

BSC Students - Please contact the BSC Helpdesk at helpdesk@bsc.edu or 205-226-3033, option 2. If you're an online course student, please consult the IT Website for Online Course Students. 

BSC Faculty and Staff - Please visit the Instructional Technology Moodle Course or contact Angela Brooks at adbrooks@bsc.edu, 205-226-3039.

facebooklinkedininstagram

  • Moodle Home
  • MyBSC Links
    Academic Alerts (formerly Starfish) Apogee BSC Email BSC Intranet BSC Website Change Password Colleague Events Records IT Helpdesk IT Help for Online Course Students Library MobilePrint OrgSync TheSIS Time & Attendance Trakstar
  • Moodle FAQs
Built with Open LMS, a Moodle-based product.
Copyright © 2024 Open LMS, All Rights Reserved.

Data retention summary
Get the mobile app
Switch to the standard theme