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



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*
// you do NOT want to use the operators <,>,== because you will be comparing the pointers
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)
// use the > operator to compare a & b

// T GetSmaller (T a, T b)
// use the < operator to compare a & b


// T GetLarger (T a, T b, T c)
// log the value you will return like the examples
// DO NOT USE < or > in this function


// T GetSmaller (T a, T b, T c)
// log the value you will return like the examples
// DO NOT USE < or > in this function

// void SwapValues( T & a, T & b)
// DO NOT use the "swap" function

// void PromptForValue ( string message, T & val)
// use cin to read a value into val