Question: The objectives for this assignment involve function and class templates. Objectives 1 Demonstrate how to prototype ( declare ) a function template. 2 Demonstrate how

The objectives for this assignment involve function and class templates.
Objectives
1 Demonstrate how to prototype (declare) a function template.
2 Demonstrate how to define a class template.
Use the assignment project and files provided. There are several overloaded functions for different types
of arrays that return the maximum value in the array. Replace (remove) the overloaded function
prototypes and definitions with just one function template prototype and definition.
Requirements
1 Replace the 5 overloaded function declarations and definitions for amax in TestTemplates.cpp
with a single function template declaration/definition.
2 The existing function call statements should all work the same and produce the same
output as they did before calling a template function.
3
Use the Distance class as is; no modifications are necessary. (Note that when passing a
Distance array to the template function, the return value will be a Distance object and
therefore cannot be inserted directly into the output stream.)
4
Add another function template to print the elements of the arrays to a file. Include at
least 2 examples using 2 different array types - print each to a different file. Call the
print function somewhere before the array out-of-bounds error at the end of the
program listing, or comment-out that line; otherwise the program will exit before the
print function can be called. Also, do not attempt to use the Distance array since it will
not work with the insertion << operator.
5
Make SafeArray a class template and demonstrate how to create safe arrays using
different types, including the Distance type. Also, write class
ArrayIndexOutOfBoundsException in separate .h and .cpp files, and modify the
SafeArray class so that it throws this exception instead of printing a message and
abnormally ending the program. Use a try-catch with the main program statement
that is causing the program to end abnormally so that instead the main program prints
the error message but continues to the normal end of program where main returns.
Considerations:
Review the lab exercises for function and class templates for hints about syntax issues.
Note that an array parameter is a pointer; this works because an array variable is a constant address,
and because the array subscript operator [] works with a pointer to an array.
For Requirement #5, do not attempt to pass a SafeArray object to the template function; it is an
object, not an array, and will not work with the array subscript operator [] inside the template
function. It has its own max member function.
Additional Requirements:
Include your name, course, section (CSC240) at the top of the EVERY program file as a comment. Submit
all .cpp and .h files that you either created or modified. Any files that were provided that did NOT have
changes do NOT need to be submitted.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!