FOR RUBY:
-----------------------------------
Create a program named Gifts. This program will describe the gifts for the 12 Days of Christmas.
Ans:-
Below is the required code.Here, instead of using nested loops to traverse the gifts backwards from second day onwards, I have used inbuilt array functions for slicing ,reversing and joining.
#the gifts array
Gifts=["twelve drummers drumming","eleven pipers piping","ten lords a leaping","nine ladies dancing","eight maids a milking","seven swans a swimming","six geese a laying","five golden rings","four calling birds","three french hens","two turtle doves","a partidge in a pear tree"].reverse
app=""
#traversing for each day
for i in 0..11
#checking for st,nd,rd or th
if (i+1)==1
p="st"
elsif (i+1)==2
p="nd"
elsif (i+1)==3
p="rd"
else
p="th"
end
gift=Gifts[i]
#forming string of gifts backwards, second day onwards
if i>0
gift=Gifts.slice(1,i).reverse.join(", ")+",and "+Gifts[0]
end
#outputting song line
puts "On the #{i+1}#{p} day of Christmas, my true love gave to me : #{gift}\n"
end
Note:- If you have any doubts
please comment below,i am happily help to u brother, please
thumbs-up bro and don't give any negative reviews please
bro????
FOR RUBY: ----------------------------------- Create a program named Gifts. This program will describe the gifts for the...
import java.util.Scanner;
public class TwelveDays
{
public static void main(String[] args)
{
final int MAX = 12;
int lastDay = 0; //last day for the
song, user will update
Scanner scan = new
Scanner(System.in);
//Get the last day and use input
validation
//Begin 1st while
{
}
int day =
1; //loop control variable for song
verses
//Begin 2nd while
{
//Output: "On the"
+ day...
Rachel's Story A mothers' account of raising a transgendered child Rachel's mother is the author of this story. She writes about the first few years of Rachel's life when she was known as Ryan. This is the story of how Ryan became Rachel. Rachel is a beautiful, well-adjusted, happy and healthy nine year old little girl. She likes to do all the things little girls at this age like to do. Sleepovers and ice-cream sundaes are by far her favorite...