Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IMPORTANT: please type code to_string() in header, cpp will only have main() function This is all to the question!!! if more info needed, let me

IMPORTANT: please type code to_string() in header, cpp will only have main() function

image text in transcribed

image text in transcribedimage text in transcribed

This is all to the question!!! if more info needed, let me know again
Writing to_string U sing the to_string() examples from the lesson, write a template function and place it into the h15.h header file. . Make sure you surround it with the #if preprocessor directive, so it will only be included when compiling with early versions of C++. Fully qualify each library name. Do not put using namespace in your header file. Add your id to h15.cpp. This will be the only code inside h15.cpp. . Do make test to check your code. This will compile your code using C++98 and C++17, and then test the functions using C++11. Unfortunately, all does not seem perfect. Testing using C++98 Checking: to_string function + to_string(42)->"42" X to_string(3.F): expected [3.000000) but found [3] + to_string(-10) -> "4294967295" + to_string(4L)->"4" X to_string(1.7L): expected [1.700000] but found [1.7] X to_string(2.7e13): expected [27000000000000.000000] but found [2.7e+13] + to_string(2.17e-4)-> "0.000217" + to_string(1.0/0.0)->"inf" + to_string(-1.0/0.0)->"-inf" + to_string(0.0/0.0)->"-nan" Tests passing 7/10 (70%). You want your code to act exactly like the new, standard library version of this function. The expected values above are what the standard library returns when run with each of these tests. (We're using the C++17 library as a test oracle here.) this is the example to_string() #include #include using namespace std; int main() cout " " to_string(3.14159) " using namespace std; string STUDENT = "WHO AM I?"; // Add your Canvas/occ-email ID // NO OTHER CODE IN THIS FILE // PUT EVERYTHING IN THE HEADER FILE As you can see, the floating-point numbers don't produce the correct output. It looks like in the C++11 version of to_string(), floating-point numbers are converted using fixed notation, even if they were originally otherwise. Change one line to solve this problem. out "42" X to_string(3.F): expected [3.000000) but found [3] + to_string(-10) -> "4294967295" + to_string(4L)->"4" X to_string(1.7L): expected [1.700000] but found [1.7] X to_string(2.7e13): expected [27000000000000.000000] but found [2.7e+13] + to_string(2.17e-4)-> "0.000217" + to_string(1.0/0.0)->"inf" + to_string(-1.0/0.0)->"-inf" + to_string(0.0/0.0)->"-nan" Tests passing 7/10 (70%). You want your code to act exactly like the new, standard library version of this function. The expected values above are what the standard library returns when run with each of these tests. (We're using the C++17 library as a test oracle here.) this is the example to_string() #include #include using namespace std; int main() cout " " to_string(3.14159) " using namespace std; string STUDENT = "WHO AM I?"; // Add your Canvas/occ-email ID // NO OTHER CODE IN THIS FILE // PUT EVERYTHING IN THE HEADER FILE As you can see, the floating-point numbers don't produce the correct output. It looks like in the C++11 version of to_string(), floating-point numbers are converted using fixed notation, even if they were originally otherwise. Change one line to solve this problem. out

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

Introduction To Managerial Accounting

Authors: Peter Brewer, Ray Garrison, Eric Noreen

9th Edition

1265672008, 978-1265672003

More Books

Students also viewed these Accounting questions