L.A.7.1 • fun2

LAB EXERCISE

FUN2

 

Assignment:

 

1.    The program will be working with pairs of data, first two integers, then two floats.  The lesson will use examples from the student outline regarding function overloading and function templates.

 

2.    Write overloaded functions to get two values from the keyboard and return these values to the formal parameters using reference parameters.  Function main will declare two integers and two floats.  When data is needed for these variables in function main, the function get2Values will be used to fill such variables.  This function get2Values should be overloaded to work with integers in one case, and floats in the other.

 

3.    Write an overloaded function to print two values, integers or floats.  This function should use const reference parameters.

 

4.    Write a function swap as a templated function.  This function will swap the contents of the two memory locations passed to the reference parameters.  If you are coding in Turbo C++ 3.0, remember to define and declare identifiers in the function prototype before function main.

 

5.    Function main should consist of this script of events:

 

a.     Declare two integers and two floats.

b.    Use the overloaded function get2Values to load the two integers.

c.     Use the overloaded function get2Values to load the two floats.

d.    Use the overloaded function print2Values to print the two integers.

e.     Use the overloaded function print2Values to print the two floats.

f.     Use the templated function swap to swap the two integers.

g.     Use the templated function swap to swap the two floats.

h.     Print the two integers again. 

i.      Print the two floats again.

 

6.    Whenever a pair of values is printed to the screen, include some informative introduction of the values.  Example:

 

       The two integers before swapping:   2   5

 

7.    Turn in the source code and a run output of the program.