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...
I HOPE TO SEE MY PILOT FACE TO FACE WHEN I HAVE CROSSED THE BAR England's great poet laureate was nearing the end of life. His time was running out, and he knew it. But he knew it with- out fear, and without regret. For to him death was not an end but a beginning; death was not the final curtain but merely a change of scene, the transition to another and perhaps an infinitely better life. Alfred Tennyson believed...
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...
This part of the Uber continuing case focuses on Chapter 14 and covers principles related to power, influence, and leadership. This continuing case's real-world application of management knowledge and skills is designed to help you develop critical thinking ability and realize the practical power of sound managerial skills for solving problems in your job and career. Read the continuing case and respond to the questions that follow. Situational approaches to leadership tell us that effective leadership depends on the situation...
Please, need help with this problem ! ( Cell Biology ) Thank You Problem 9 - Panoptes In Ancient Greek mythology, the giant Argus was attributed the nickname "Panoptes" ("all seeing") because he had 100 eyes spread all over his head and body. And our friend Argus Panoptes, herem is afflicted with ubiquitous expression of the eyeless gene Aristotle and molecular biology Nowadays, researchers induce mutations in animal models to better understand mutations in humans In fruit flies, a genetic...
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...
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...
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...