Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

50 Tips And Tricks For MongoDB Developers Get The Most Out Of Your Database

Authors: Kristina Chodorow

1st Edition

1449304613, 978-1449304614

More Books

Students also viewed these Databases questions

Question

Never mind, I figured it out.

Answered: 1 week ago

Question

7. Identify six intercultural communication dialectics.

Answered: 1 week ago