EE221 Assignment 10

Program 1 (30pts.)

Rewrite the provided rotary Queue class or the dynamic rotary Queue class that you have developed in the recent homework assignment into a queue class template.

Test your library using a simple program that adds and remove elements from the queue. For your convenience, a ready to use interactive test program has been provided.

You must use at least two files to get full credit. You do not have to print the provided test program, just the library file(s) and the output of a running program.

Program 2 Version 1 (30pts.)

Write a function template that calculates a maximum of three variables of the same type that are passed by constant reference. Assume that you can compare the variables using > operator. Write a short program and test your template on int, float and string-class variables.

Program 2 Version 2 (30pts.)

Write a function template that accepts a two dimensional array of something (or perhaps the array of it is the "something"), the used number of rows and columns (unsigned int), and the column number (unsigned int) that needs to be processed. Your function template should add (use operator + to do the addition) together values from all rows and the given column and return it using return statement. Write a short program and test your template on int, double and string-class arrays of various size. You can use a program similar to ones that are used in the examples that illustrate the use of arrays in function templates material (You can use the pre-initialized arrays).

Hint: The function declaration may look like
template<typename TA, typename TD> TD function(const TA& A, unsigned rows, unsigned cols, unsigned given_column, TD initial) { ... }
You may consider to examin two examples: passing a 2D array to a function template as T (not as T[maxr][maxc]), and adding up elements of a 1D array passed to a function as T (not as T[]). Remember that you need to write a short program in order to test your template.

web site front local main page local list page print this page   general bookmarks software bookmarks go back close this page copyright info   visitor counter