Question: Implement a function template that can compare two parameters. This function should return a negative value (the value should be meaningful if possible; otherwise just

Implement a function template that can compare two parameters. This function should return a negative value (the value should be meaningful if possible; otherwise just make sure its negative) if the first parameter is smaller, 0 if they are equal, and a positive value if the first parameter is larger (the value should be meaningful if possible; otherwise make sure its positive). This function should work with int, char, double, and string types.

Your program should include the following testing main function and return the expected output.

int main()

{

std::cout << compare(5, 5) << std::endl; // ==, return 0

std::cout << compare('A', 'a') << std::endl; // <, return neg (prefer -32)

std::cout << compare(4.5, 4.0) << std::endl; // >, return pos (prefer 0.5)

std::string str1 = "dave", str2 = "peter";

std::cout << compare(str1, str2) << std::endl; // <, return neg (prefer -1)

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!