Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Now, it\'s your turn. Write a function that prints the lyrics to the nursery rhy

ID: 3814654 • Letter: N

Question

Now, it's your turn. Write a function that prints the lyrics to the nursery rhyme "Old MacDonald Had a Farm" when given the name of an animal and the sound that animal makes. An example verse for the input "cow" and "moo" is given below old macdonald cow 'moo' Old MacDonald had a farm E-I-E-I-O! And on that farm he had a cow E-I-E-I-O! With a moo-moo here, and moo-moo there. Here a moo, there a moo, everywhere a moo-moo. Old MacDonald had a farm E-I-E-I-O! Then, write a script that uses your function to print the lyrics of the song for 5 different animals. Here are several animals and the sounds they make: Dog goes "woof" Cat goes "meow" Bird goes "tweet" And mouse goes "squeek" Cow goes "moo Frog goes "croak" And the elephant goes "toot" Ducks say "quack" And fish go "blub" And the seal goes "ow ow ow" But there's one sound that no one knows: what does the fox say?

Explanation / Answer

Script that uses the function :-

animals = {'cat' 'dog' 'cow' 'bird' 'frog'};
sounds = {'meow' 'woof' 'moo' 'tweet' 'croak'};

len = size(animals,2);
for i = 1:len
old_macdonald(animals{i}, sounds{i});
end

Function:-

function str = coin_value(animal, sound)
str = sprintf(' Old MacDonald had a farm, E-I-E-I-O! And on that farm he had a %s, E-I-E-I-O! With a %s-%s here, and %s-%s there. Here a %s, there a %s, everywhere a %s-%s. Old MacDonald had a farm E-I-E-I-O!',animal,sound,sound,sound,sound,sound,sound,sound,sound)
end