This assignment focuses on writing functions. These functions will be used to make the structure of the program cleaner and clearer. They will use parameters. There is no need to use return values in the core of this assignment. (The challenge option might be easier if you use return values. For more information, see section 5.7 in the text.)
Overview
The children's song that we'll work on is "Old McDonald". In case you aren't familiar with it, here are a couple example verses:
Old McDonald had a farm, E-I-E-I-O.
And on that farm he had a chicken, E-I-E-I-O.
With a cluck-cluck here, and a cluck-cluck there.
Here a cluck, there a cluck, everywhere a cluck-cluck.
Old McDonald had a farm, E-I-E-I-O.
Old McDonald 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 a moo-moo there.
Here a moo, there a moo, everywhere a moo-moo.
Old McDonald had a farm, E-I-E-I-O.
Old McDonald had a farm, E-I-E-I-O.
And on that farm he had a duck, E-I-E-I-O.
With a quack-quack here, and a quack-quack there.
Here a quack, there a quack, everywhere a quack-quack.
Old McDonald had a farm, E-I-E-I-O.
The very observant among you may notice that this version of the
song has been simplified slightly.
[Participation fodder: what's the simplification? ]
Standard Version
For the standard version:
The last two three bullet points can be translated as:
There are only two possible answers for the "Do you want a fifth verse?" question. Tell the user what the choices are. If the user picks one of them, do that. If the user's input doesn't match either of your two choices, assume that the user wants to do a fifth verse.
Sample Run
Here is an example of what the Standard assignment will look like, when run. The user input is shown in bold blue characters.
Old McDonald
Old McDonald had a farm, E-I-E-I-O.
And on that farm he had a chicken, E-I-E-I-O.
With a cluck-cluck here, and a cluck-cluck there.
Here a cluck, there a cluck, everywhere a cluck-cluck.
Old McDonald had a farm, E-I-E-I-O.
Old McDonald 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 a moo-moo there.
Here a moo, there a moo, everywhere a moo-moo.
Old McDonald had a farm, E-I-E-I-O.
Old McDonald had a farm, E-I-E-I-O.
And on that farm he had a duck, E-I-E-I-O.
With a quack-quack here, and a quack-quack there.
Here a quack, there a quack, everywhere a quack-quack.
Old McDonald had a farm, E-I-E-I-O.
Enter an animal: horse
Enter the sound the horse makes: neigh
Old McDonald had a farm, E-I-E-I-O.
And on that farm he had a horse, E-I-E-I-O.
With a neigh-neigh here, and a neigh-neigh there.
Here a neigh, there a neigh, everywhere a neigh-neigh.
Old McDonald had a farm, E-I-E-I-O.
Do you want to have a fifth verse (yes/no)?
nah
Enter an animal: pig
Enter the sound the pig makes: oink
Old McDonald had a farm, E-I-E-I-O.
And on that farm he had a pig, E-I-E-I-O.
With a oink-oink here, and a oink-oink there.
Here a oink, there a oink, everywhere a oink-oink.
Old McDonald had a farm, E-I-E-I-O.
In this example, for the obligatory fourth verse, the user entered horse and neigh. Then the user was asked about the fifth verse. The "acceptable answers" are "yes" and "no", as indicated in the question. The user's response was "nah". Since it doesn't match either of the expected answers ("yes" or "no"), the default action (the assumption) is to call the newVerse function and get the animal and sound for a fifth verse. The user entered pig and oink for the fifth verse.
Challenge Version
For the extra-credit version:
Old McDonald had a farm, E-I-E-I-O.
And on that farm he had a pig, E-I-E-I-O.
With an oink-oink here, and an oink-oink there.
Here an oink, there an oink, everywhere an oink-oink.
Old McDonald had a farm, E-I-E-I-O.
Old McDonald had a farm, E-I-E-I-O.
And on that farm he had an owl, E-I-E-I-O.
With a who-who here, and a who-who there.
Here a who, there a who, everywhere a who-who.
Old McDonald had a farm, E-I-E-I-O.
Notes about the challenge version:
def title():
print("The name of the song: "Old McDonald"")
print(" ")
def verse(animal, sound):
print("Old McDonald had a farm, E-I-E-I-O. And on that farm he had
a "+ animal+" , E-I-E-I-O. With a "+ sound+" - "+sound+" here, and
a "+ sound+" - "+sound+" there. Here a "+ sound+" , there a "+
sound+", everywhere a "+ sound+" - "+
sound+" . Old McDonald had a farm, E-I-E-I-O.")
print(" ")
def main():
title()
verse('chicken', 'cluck')
verse('cow', 'moo')
verse('duck', 'quack')
main()
showing indentation:

output:

This assignment focuses on writing functions. These functions will be used to make the structure of...
C++ Programming Assignment S Mammal Lab This lab's goal is to give you some practice using inheritance, virtual functions, pointers, dynamic memory allocation, random numbers, and polymorphism. To complete the lab implement the following steps: Create a class called Mammal. All mammals have a weight and a name, so its data should be the mammal's weight and name. Provide a default constructor that sets the mammal's weight to 0 and name to null, and another constructor that allows the weight...
Suppose you are given the following production function
Q= 21x + 9x2-x3
Compose a table calculating the Total Product (Q), Marginal
Product (MP) and Average Product (AP), for x ranging from 0 to 9
units.
Using the information from the table, graph these individual
curves and identify the rate of which diminishing marginal returns
are evident. Delineate the stages of production and
explain why Stages I and III are considered as
irrational whereas Stage II is termed as rational. What...
You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...
Assignment Predator / Prey Objectives Reading from and writing to text files Implementing mathematical formulas in C++ Implementing classes Using vectors Using command line arguments Modifying previously written code Tasks For this project, you will implement a simulation for predicting the future populations for a group of animals that we’ll call prey and their predators. Given the rate at which prey births exceed natural deaths, the rate of predation, the rate at which predator deaths exceeds births without a food...
Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please write the code according to functions assigned...
Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed for this assignment, so don't use them. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please...
please use python and provide run result, thank you!
click on pic to make it bigger
For this assignment you will have to investigate the use of the Python random library's random generator function, random.randrange(stop), randrange produces a random integer in the range of 0 to stop-1. You will need to import random at the top of your program. You can find this in the text or using the online resources given in the lectures A Slot Machine Simulation Understand...
Choose a symbol from either "The Gift of the Magi" and discuss what significance this symbol had to you as the reader (an example of this would be the combs Jim gave to Della and a discussion about a precious gift that you received or gave). Use text examples in this section. If someone were to write your life story, what symbol would be present and why? How does this symbol represent you? You can attach a picture of your symbol (an...
Hi there! I need to compare two essay into 1 essay, and make it interesting and choose couple topics which im going to talk about in my essay FIRST ESSAY “Teaching New Worlds/New Words” bell hooks Like desire, language disrupts, refuses to be contained within boundaries. It speaks itself against our will, in words and thoughts that intrude, even violate the most private spaces of mind and body. It was in my first year of college that I read Adrienne...
You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...