New Exercises (Section A)
For each procedure, you must also write a program that allows you to test the procedure.
Old Exercises (Section B)
Write a procedure called printBar() which takes two parameters: the first is a character and the second is an integer from 0 to 80. The function should print out a row of the given character, repeated the number of times given by the integer. (Turing Solution)
For example, if the user input the character $ and the number 25, the output would be $ printed 25 times:
Parameters> $ 25
Output> $$$$$$$$$$$$$$$$$$$$$$$$$
(challenging, multiple procedures will help) Write a procedure called rectangle() which takes four parameters: an integer length, an integer width, the x coordinate of the top left corner (column) and its y coordinate (row). The procedure should outline the rectangle in the correct position , with the given length and width using '*' for the border.
Write a procedure called validateUser() that will ask for a username and password. The user has 3 tries to get it right, after which an error message will be output to the screen. (Turing Solution)
Write a procedure printDate() that will have inputs of month, day, and year as integer values. The procedure will output the name of the month, and the numbers for the day and year.
Extend: Check for valid input, and output an error message if any values are out of range
You should review the "if-elsif" conditional statements for this program. You might also look into the "case" statement, but we will cover this command at a later date.
Write and test computeTriangle(), a procedure that returns (by changing input parameters) the area and the perimeter of a triangle given side lengths a, b, and c. You may wish to use existing triangle functions as part of your procedure.
{Note: Cannot be done in Java} A common and useful procedure provides the ability to swap two values. This concept is used frequently when sorting values. Write a procedure called swap() that will have two real values as inputs, and the procedure will then exchange the inputs. This means you will be changing the input parameters, which requires special care when setting up your procedure. (Turing Solution)
Modify your program for the Guessing Game. Replace some blocks of code with one or more procedures to make the overall program simpler to read and understand.
Write a program which makes change for an amount of money less than a dollar. The program should have three functions or procedures called quarters(), dimes() and nickels(). The main program should call each subprogram in turn and then print out the numbers of each type of coin. (Turing Solution with 3 Procedures)
Sample Output (user input in red)
How much change? 92
Quarters = 3
Dimes = 1
Nickels = 1
Pennies = 2
Many advanced calculators have a fraction feature that will simplify fractions for you. You are to write a program that will accept for input a positive or negative integer as a numerator and a positive integer as a denominator, and output the fraction in simplest form. That is, the fraction cannot be reduced any further, and the numerator will be less than the denominator. You can assume that all input numerators and denominators will produce valid fractions. Remember the div and mod operators.
Implement this by writing a procedure that takes in a numerator and denominator, and returns an integer, a new reduced numerator and denominator (i.e., it can change the input parameters). You may also use a combination of functions and procedures for other features in your program.
Sample Output (user input in red)
Numerator: 14
Denominator: 3
Result: 4 2/3
Numerator: 8
Denominator: 4
Result: 2
Numerator: 5
Denominator: 10
Result: 1/2