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
Demonstrate how to prototype declare a function template.
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
Replace the overloaded function declarations and definitions for amax in TestTemplates.cpp
with a single function template declarationdefinition
The existing function call statements should all work the same and produce the same
output as they did before calling a template function.
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.
Add another function template to print the elements of the arrays to a file. Include at
least examples using different array types print each to a different file. Call the
print function somewhere before the array outofbounds error at the end of the
program listing, or commentout 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.
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 trycatch 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 # 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 CSC 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
