Question
Please complete the following program given the following program template. #include // to use cin and cout #include // to be able to use operator
Please complete the following program given the following program template.
#include
// Include here the libraries that your program needs to compile
using namespace std;
// Ignore this; it's a little function used for making tests inline void _test(const char* expression, const char* file, int line) { cerr
// Insert here the prototype of the function here
int main() { // Declare variable value, valuero that hold double precision real numbers
// Declare variable decdig that holds whole numbers
// Prompt the user to "Enter the real number: "
// Read from keyboard the value entered by the user and assign it to value
// Prompt the user to "Enter number of digits: "
// Read from keyboard the value entered by the user and assign it to decdig
// Round the real number to the number of decimal digits specified and assign the result to valuero
// Format the output to display the numbers in fixed format with ten decimal digits
// Display on the screen, using 23 columns, the message // "The original number is ", value
// Format the output to display the numbers in fixed format with the number of decimal digits specified plus 2
// Display on the screen, using 23 columns, the message // "The rounded number is ", valuero
system("pause");
// Do NOT remove or modify the following statements cout
test(fabs(round_off(125.123456789,2) - 125.12 )
system("pause");
return 0; }
//************************ Function definition ************************* // Read the handout carefully for detailed description of the functions that you have to implement
// Rounds the value received in the first parameter to the number of digits received in the second parameter
Lab 6: Value-returning functions Problem: You will be have to round numbers very often so you decided to create your own function round off that will receive the number to be rounded and the number of decimal digits that the number should be rounded to and will return the value rounded to the specified number of decimal digits. You need to create a program to test the function. It will ask the user to enter the double precision real number to be rounded and a whole number indicating the number of decimal digits. It will then display the original number with ten digits and the rounded value (also a double precision real number) with the number of digits specified by the user plus 2 more. This assignment will be completed in two steps: 1) First you will implement the algorithm shown below in which the rounding will be done in maino 2) Once you have this working you will need to modify your solution so you: Declare the prototype of the function above main() Call the function in main( to do the rounding Define the function below main() Your task: implement in C++ the algorithm solution shown below for the first step. Algorithm solution (in pseudocode): To solve this problem your program must perform the following tasks: 1. 5 points. Declare variable value, valuero that hold double precision real numbers 2. 5 points, Declare variable decdig that holds whole numbers 3. 8 points. Prompt the user to "Enter the real number: 4. 8 points. Read from keyboard the value entered by the user and assign it to value 5. 8 points. Prompt the user to "Enter number of digits: " 6. 8 points. Read from keyboard the value entered by the user and assign it to decdig 7. 24 points. Round the real number to the number of decimal digits specified and assign the result to valuero 8. 8 points. Format the output to display the numbers in fixed format with ten decimal digits 9. 8 points. Display on the screen, using 23 columns, the message "The original number is", value 10. 10 points. Format the output to display the numbers in fixed format with the number of decimal digits specified plus 2 11. 8 points, Display on the screen, using 23 columns, the message "The rounded number is", valuero The program must compile without errors or warnings. Chat Participants Record Share Screen Reactions FEB x Important: Once you have this program working you will modify it according to step 2. There are comments in the provided cpp file that indicate where you have to insert the prototype and define the function. The call to the function will be done in the statement where you do the rounding in main(). Note: Do NOT remove or modify the statements that I use to test certain things in your program. Run my sample solution to know how your program must behave. Pay attention to the input and the output formats. Your solution must behave exactly like mine. Carefully analyze the following figure and use it as a reference to ensure you do the right things. . IN CAWINDOWS\system32\cmd.ee Enter the real number: 2.23128744 Enter number of digits: 5 The original number is 2.2312874400 The rounded number is 2.2312900 Press any key to continue a Test and compare your solution with mine for different values of the number and the number of digits to ensure they always produce the same outputs. Pay attention to the output format. Ensure your formulas do not use mixed data types
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started