Now, it\'s your turn. Write a function that prints the lyrics to the nursery rhy
ID: 3811739 • 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 n 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 ar 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"Explanation / Answer
Script in command window :-
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
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.