Template Functions
Lecture Video
For this lab you will create several functions using template parameters
A sample main to test your functions has been provided for you have your output to the console AND THE LOG
match the runme_example
copy the files over as you have done in the previous labs
you will complete the functions in "template_functions.h"
File: template_functions.h
#include <iostream>
#include "cmpslib19.h"
#include "easylogging++.h"
// here are copies of GetLarger and GetSmaller for datatype char*
// prior to the creating of the std::string class text could only be stored in arrays of characters
// to compare text in character arrays you need to use the strcmp function
// you do NOT want to use the operators <,>,== because you will be comparing the pointers
// so I created to functions for use with the char* data type
const char * GetLarger (const char* a, const char* b)
{
LOG(INFO) << "Start " << __PRETTY_FUNCTION__ << endl;
const char *temp = (strcmp(a,b) <= 0) ? b:a;
LOG(INFO) << "End " << __PRETTY_FUNCTION__ << endl;
LOG(INFO) << "Returning " << temp << endl;
return temp;
}
const char * GetSmaller (const char* a, const char* b)
{
LOG(INFO) << "Start " << __PRETTY_FUNCTION__ << endl;
const char *temp = (strcmp(a,b) >= 0) ? b: a;
LOG(INFO) << "End " << __PRETTY_FUNCTION__ << endl;
LOG(INFO) << "Returning " << temp << endl;
return temp;
}
// T GetLarger (T a, T b)
// return the larger value a or b
// use the > operator to compare a & b
// T GetSmaller (T a, T b)
// return the smaller value a or b
// use the < operator to compare a & b
// log the value you will return like the examples
// T GetLarger (T a, T b, T c)
// return the larger value a,b or c
// log the value you will return like the examples
// you only need to call the GetLarger for 2 parameters twice , first with a & b then use that result to compare with c
// DO NOT USE < or > in this function
// we want to use this function to work for ( char * ) or constant c strings too you cant use < or > on them
// T GetSmaller (T a, T b, T c)
// return the smaller value a,b or c
// log the value you will return like the examples
// you only need to call the GetSmaller for 2 parameters twice , first with a & b then use that result to compare with c
// DO NOT USE < or > in this function
// void SwapValues( T & a, T & b)
// swap the values in the two parameters passed in
// DO NOT use the "swap" function
// void PromptForValue ( string message, T & val)
// display the text in message
// use cin to read a value into val
Be sure to type 'make setPermissions' or 'make sp' to set your file permissions so they can be collected for grading