Skip to main content
In this program, you’ll see how to call functions. Functions are chunks of code with a name, and “calling” a function means to call on the function to do a task for you.Files NeededSample Output
Finish the program provided. You’ll need to write five if statements and some function calls. If you do it right it should display a phrase in an interesting way.Files NeededSample Output
In this program, you’ll look at a function that “returns a value”. When you call on the function to do a task, it will give you back a result.Files NeededSample Output
Write a function to compute the distance between two points. Given two points (x1, y1) and (x2, y2), the distance between these points is given by the formula: Distance FormulaYou must name the function distance, and it must return a double giving the distance between the two points.Files NeededSample Output
Write a function. It will return the name of a month of the year, given the month number, according to the table below. Make sure you do not put any input or output statements in the function; the month number will be passed in and the string containing the name will be returned.The function must be called month_name(), and must have one parameter (an integer), and return a String.And finally, here’s some starter code.Files NeededSample Output
Write a function to give you the “month offset” given a number representing the month. You can get the month offset from the following table:Of course, here’s the main() to test your function.Files NeededSample Output
Using the functions you wrote in previous assignments and the leap year function provided, write a function to determine the day of the week a person was born given his or her birthday. The following steps should be used to find the day of the week corresponding to any date from 1901 through the present.In the following explanation, the following terms will be helpful. Assuming I type in my birthday as “6 10 1981”:The month is 6. The day of the month is 10. The year is 1981.
  1. Find the number of years since 1900, and put it into a variable called yy. Simply subtract 1900 from the year to get this.
  2. Divide the number of years since 1900 by 4. Put the quotient in a variable called total. For example, if the person was born in 1983, divide 83 by 4 and store 20 in total.
  3. Also add the number of years since 1900 to total.
  4. Add the day of the month to total.
  5. Using the function month_offset() you wrote, find the “month offset” and add it to total.
  6. If the year is a leap year and if the month you are working with is either January or February, then subtract 1 from the total. You can use the function is_leap() provided to determine if the year is a leap year.
  7. Find the remainder when total is divided by 7. Pass this remainder to the function weekday_name() you wrote to determine the day of the week the person was born.
  8. Finally, build up a single String value containing the whole date (day of week, month, day, year). You’ll need to use the function month_name() you wrote to show the month name rather than its number.
  9. Return that String value.
Whew. Here’s some code to get you started.Files NeededSample Output
Write a program to calculate the area of four different geometric shapes: triangles, squares, rectangles, and circles. You must use functions. Here are the functions you should create:
Your program should present a menu for the human to choose which shape to calculate, then ask them for the appropriate values (length, width, radius, etc.). Then it should pass those values to the appropriate function and display the resulting area.Notice that you must not input the values inside the functions, and you must not display the values inside the functions. All input and output must be in the main(), and values must be passed to the functions and returned from them.You’ll need the value of π\pi for area_circle(); feel free to use the built-in double variable called Math.PI.The menu should keep looping until the human chooses to quit.Sample Output
Download and finish the following code to practice writing function calls.Files NeededSample Output
Note that this exercise only requires you to write function calls. The function implementations are already complete. If you do everything correctly, it should produce output like the following:
Download and finish the following code to practice working with functions:Files NeededIf you do everything correctly, it should produce output like the following:Sample Output
Download and finish the following code to practice working with functions:Files NeededIf you do everything correctly, it should produce output like the following:Sample Output
Write a program that pulls up a menu with 4 options. It should look something like…Sample Output
  • You will need to create functions for each of the 4 menu options. Entering the number will call the correct function.
  • This assignment does not require you to complete ANY of the functionality except for the working menu system. There is no need for you to program the ability to add keychains, remove keychains, view orders or checkout.
  • The functions should be named add_keychains(), remove_keychains(), view_order() and checkout().
  • Each function should print a message that it has been called.
  • The user should be able to keep putting in choices until the checkout() function is called. When checkout() is finished, the program should end.
Okay, now it is time to make the keychain shop actually work.Sample Output
  • You will need 2 new variables in main, one to store the current number of keychains, and one to store the price per keychain.
  • The price should be $10 per keychain.
  • add_keychains() will need to be passed one int, and have a return type of int. It will ask the user for the number of keychains to add to the order, and then return the new number of keychains.
  • remove_keychains() will need to be passed one int, and have a return type of int. It will ask the user for the number of keychains to remove from the order, and then return the new number of keychains.
  • view_order() will need to be passed two ints, and have a return type of void. It will display, on three different lines, the number of keychains in the order, the price per keychain, and the total cost of the order.
  • checkout() will need to be passed two ints, and have a return type of void. It will ask the user for his/her name in order to deliver them correctly, display the order information, and then thank the user, by name, for ordering.