LAB 07A - MISCELLANEOUS FUNCTIONS

Concepts

The focus on this lab is to gain more experience with user-defined functions. In class, you learned the difference between parameters and arguments and, due to scope, how they can be the same variable name. You also learned about global variables. You will gain experience with these new concepts herein. This lab will be submitted with Homework 07. While Homework 07 is due after the exam, we encourage you to complete this lab before the exam (good practice!)

Get Started

To begin, create an empty project (however fits your fancy!). Next, for all the functions you define below, place the definition of the function below main(). This means you'll need a function prototype in each case.

User-Defined Function 1: Rectangle Area

Write a function to calculate the area of a rectangle. The parameters of the function should be two double inputs (named length and width) that are passed by value, and the return value should be a double that is the area of the rectangle. The calling arguments should also be two double inputs (named length and width), both of which the user enters prior to the function call.

While these variable names for the parameters and arguments are the same, they are different due to scope. Really?? Test this theory by modifying length in the function, and then printing length after the function call. Holy cow! (Note: whether to declare the same variable name as the parameters and arguments is a style choice.)

User-Defined Function 2: Diameter Input

Write a function that serves as a way for the user to enter the diameter of a circle. The function should have no parameters/arguments, and return a double. When the function is called, the output should be:

Hello! Here is your joke of the day:

What do you get if you divide the circumference of a pumpkin by its diameter?
Pumpkin pi of course. Yum.

Please enter your pumpkin's diameter: 23.2

If the user enters 23.2, then the function should return 23.2.

User-Defined Function 3: Divide by Two

Write a function that divides all inputs by two. Specifically, this function should have three double parameters (named num1, num2, and num3). These three parameters should be passed by reference, and then the function should divide each by two. The function should have no return.

User-Defined Function 4: Number of Vowels

Write a function that has one string parameter (which is passed by reference, but not allowed to change; hmmm, how do you do that?). The function should return an integer, which is the number of vowels (a, e, i, o u) in the string that was passed. Try to modify the input string in the function to ensure that the compiler will NOT allow the string to be modified.

Your main()

Your main function should include enough calls to the various functions that you've defined, so you can ensure they are working correctly.