Write a program that tests whether the examples of the math library function calls below actually produce the indicated results.
```
ex06_02.cpp
#include
using namespace std;
int cube(int y); // function prototype
int main() {
int x{0};
for (x = 1; x <= 10; x++) { // loop 10 times
cout << cube(x) << endl; // calculate cube of x and output results
}
}
// definition of function cube
int cube(int y) {
return y * y * y;
}
```
```
// ex06_03.cpp
// Testing the math library functions.
#include
#include
#include
using namespace std;
int main() {
cout << fixed << setprecision(1);
cout << "sqrt(" << 9.0 << ") = " << sqrt(9.0);
cout << "\nexp(" << 1.0 << ") = " << setprecision(6)
<< exp(1.0) << "\nexp(" << setprecision(1) << 2.0
<< ") = " << setprecision(6) << exp(2.0);
cout << "\nlog(" << 2.718282 << ") = " << setprecision(1)
<< log(2.718282)
<< "\nlog(" << setprecision(6) << 7.389056 << ") = "
<< setprecision(1) << log(7.389056);
cout << "\nlog10(" << 10.0 << ") = " << log10(10.0)
<< "\nlog10(" << 100.0 << ") = " << log10(100.0) ;
cout << "\nfabs(" << 5.1 << ") = " << fabs(5.1)
<< "\nfabs(" << 0.0 << ") = " << fabs(0.0)
<< "\nfabs(" << -8.76 << ") = " << fabs(-8.76);
cout << "\nceil(" << 9.2 << ") = " << ceil(9.2)
<< "\nceil(" << -9.8 << ") = " << ceil(-9.8);
cout << "\nfloor(" << 9.2 << ") = " << floor(9.2)
<< "\nfloor(" << -9.8 << ") = " << floor(-9.8);
cout << "\npow(" << 2.0 << ", " << 7.0 << ") = "
<< pow(2.0, 7.0) << "\npow(" << 9.0 << ", "
<< 0.5 << ") = " << pow(9.0, 0.5);
cout << setprecision(3) << "\nfmod("<< 2.6 << ", " << 1.2 << ") = "
<< fmod(2.6, 1.2) << setprecision(1);
cout << "\nsin(" << 0.0 << ") = " << sin(0.0);
cout << "\ncos(" << 0.0 << ") = " << cos(0.0);
cout << "\ntan(" << 0.0 << ") = " << tan(0.0) << endl;
}
```
```
sqrt(9.0) = 3.0
exp(1.0) = 2.718282
exp(2.0) = 7.389056
log(2.718282) = 1.0
log(7.389056) = 2.0
log10(10.0) = 1.0
log10(100.0) = 2.0
fabs(5.1) = 5.1
fabs(0.0) = 0.0
fabs(-8.8) = 8.8
ceil(9.2) = 10.0
ceil(-9.8) = -9.0
floor(9.2) = 9.0
floor(-9.8) = -10.0
pow(2.0, 7.0) = 128.0
pow(9.0, 0.5) = 3.0
fmod(2.600, 1.200) = 0.200
sin(0.0) = 0.0
cos(0.0) = 1.0
tan(0.0) = 0.0
```
You might also like to view...
Answer the following statements true (T) or false (F)
1. In C#, a variable must be assigned a value before it can be used on the right side of an assignment statement. 2. The C# compiler will compile code that attempts to use an unassigned variable. 3. You can declare multiple variables of different data types in one program statement. 4. If you need to store numbers and perform mathematical operations on them, you have to use a numeric data type.
Answer the following statements true (T) or false (F)
1. The algorithm will produce a different output depending on the specific secret key being used at the time. The exact substitutions and transformations performed by the algorithm depend on the key. 2. When using symmetric encryption it is very important to keep the algorithm secret. 3. On average, half of all possible keys must be tried to achieve success with a brute-force attack. 4. Ciphertext generated using a computationally secure encryption scheme is impossible for an opponent to decrypt simply because the required information is not there. 5. Monoalphabetic ciphers are easy to break because they reflect the frequency data of the original alphabet.
Which of the following is a switching location in a packet switching network?
a. a PAD b. a Node c. an IXC d. none of the above
Which of the following should you use to check for opens or breaks in a copper cable by determining if the signal sent from one end reaches the other end of the cable?
A. OTDR B. traceroute C. continuity tester D. voltmeter