Create a C++ program that tests built-in functions. Built-in functions to be tes
ID: 3795759 • Letter: C
Question
Create a C++ program that tests built-in functions. Built-in functions to be tested are: pow(x, y), squareroot (x), floor(x), ceil(x), fabs(x) Call and use a void function named: testBuiltlnFunctions This function will do the calculations. This function will test for negative values and omit squareroot (x) calculation. Use a loop to allow user to continue entering values until exit is desired. Carefully review the sample output below for how your code should operate! Compile, execute, and fully test for proper operation. Sample output Built in function tester for ITS-25 theta! Enter a decimal value to test : 3.1 *** Results *** 3.1 squared is 9.61 3.1 raised to the 7th power is 2751.26 squareroot of 3.1 is: 1.76068 Floor of 3.1 is: 3 Ceiling of 3.1 is 4 Absolute value of 3.1 is 3.1 Enter a decimal value to test : -2.2 *** Results *** -2.2 squared is 4.84 -2.2 raised to the 7th power is: -249.436 WARNING: squareroot of negative value not calculated! Floor of 2.2 is -3 Ceiling of 2.2 is -2 Absolute value of 2.2 is 2.2 Enter a decimal value to test : theta Program over!Explanation / Answer
// C++ code
#include <iostream>
#include <fstream>
#include <cctype>
#include <cstring>
#include <stdlib.h> /* srand, rand */
#include <iomanip>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
void testSquare(double number)
{
cout << number << " squared is: " << (number*number) << endl;
}
void testPower(double number)
{
cout << number << " raised to the 7th power is: " << pow(number,7) << endl;
}
void testSqrt(double number)
{
if(number < 0)
cout << "WARNING: square root of negative value not calculated! ";
else
cout << "Square rot of " << number << " is: " << sqrt(number) << endl;
}
void testFloor(double number)
{
cout << "Floor of " << number << " is: " << floor(number) << endl;
}
void testCeiling(double number)
{
cout << "Ceiling of " << number << " is: " << ceil(number) << endl;
}
void testAbs(double number)
{
cout << "Absolute value of " << number << " is: " << abs(number) << endl;
}
int main()
{
double number;
while(true)
{
cout << " Enter a decimal value to test < 0 to quit>: ";
cin >> number;
if(number == 0)
{
cout << "Program Over!";
break;
}
testSquare(number);
testPower(number);
testSqrt(number);
testFloor(number);
testCeiling(number);
testAbs(number);
}
return 0;
}
/*
output:
Enter a decimal value to test < 0 to quit>: 3.1
3.1 squared is: 9.61
3.1 raised to the 7th power is: 2751.26
Square rot of 3.1 is: 1.76068
Floor of 3.1 is: 3
Ceiling of 3.1 is: 4
Absolute value of 3.1 is: 3.1
Enter a decimal value to test < 0 to quit>: -2.2
-2.2 squared is: 4.84
-2.2 raised to the 7th power is: -249.436
WARNING: square root of negative value not calculated!
Floor of -2.2 is: -3
Ceiling of -2.2 is: -2
Absolute value of -2.2 is: 2.2
Enter a decimal value to test < 0 to quit>: 0
Program Over!
*/