Lab 8.
Functions and Parameter Passing
Points (10 overall)
Collaboration policy:
You will be working in pairs during labs.
Pairs will be randomly selected and will be announced by the TA. Each week you will have a new random
partner. You will discuss the programs
with your partner, but you will still be typing in your own code to show to the
TA. You can help each other debug, give
plenty of suggestions and hints, **explain** why things work or don't work,
etc.
To gain experience with
Write a swap function to swap the values of two integers.
Write an order function that takes three integers and guarantees that they are stored in the parameters in ascending order upon completion of the function.
Write a short program to verify correctness.
Write a program that allows the user to enter a number (0-999) and output each digit separately. The user should be able to enter numbers and see the digits as often as they want. A negative number will be used to quit the program. Values over 999 should simply be stated to be invalid input.
For this program, you
should have at least one function called find_digits. Since three values need to be calculated and
a function can only return one value, you should use pass-by-reference to “return”
the digits. Thus the function should have a return type of void and
take 4 parameters, the number, and a reference for each digit.
Write a function called transaction that simulates a bank transaction. It should take as parameters the current amount in the account, an integer code to represent a deposit (1) or withdrawal (2), and the amount to be withdrawn or deposited. This function should perform the transaction, adjusting the current amount. Do not let the account be overdrawn (have a negative balance). If a transaction cannot be performed, the function should return a 0. If the transaction was able to be completed without errors, a 1 should be returned. Be sure to use good parameter passing for each parameter.
Write a short program to verify this function, allow the user to perform as many deposits or withdrawals as they want, give a menu to allow them to continue choosing between (making a deposit, making a withdrawal, or quitting the program).