This week's tasks are:
Practice 1Comparing two values (such as numerical, string and some other data type values) is a routine task you would see in many programs. Your first task is to code the following functions as template functions:
define them so that they can only be visible (usable) within that source, which contains the statements using those functions. Practice 2Once you finish coding the above code, test your template function with various data types. You should test it at least with the following data types:
Practice 3Your next task is to build a generic template class, which implements comparison of two values. Your template class should appropriately overload:
as well as providing a getter method to retrieve the value (getValue()). Practice 4Once the above template class is programmed, check its behaviour with various data types. You should test it at least with the following data types:
Practice 5Modify your code so that your comparison template class compare two strings based on their "length" rather than the order in a dictionary. Practice 6Write your template class code in a header file (XXX.h). Furthermore, provide function body outside of the class definition. Once you separate the class definition and the function definition, put some function definitions in a separate file (XXX.cpp). Write your main() function, which tests your template class, in a separate file (YYY.cpp), and compile the project. You should try various combinations of where to put the function definitions in order to use the template without linker errors. Practice 7Write a main() function, which tests your template class with two or more cases of the same data type. For instance: ... Comp<int> values[] = {32, 44, 559, 321, 98}; Comp<int> values2[] = {859, 484, 399, 21, 2398}; ... And confirm that only one generated Comp class to deal with int type exists. Sample Solutions |