Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Name: Maiya Patti Built In Function

Review Sheet

1. Next to each language feature, please write the header file that we must
include to use that feature.
cout and cin ----- IOSTREAM
the string data type ----- STRING
setprecision() -----IOMANIP
pow(), sqrt(), fabs() ----- CMATH

2. In C++, do all functions need to accept inputs?


Inputs are not needed

3. In C++, what is another name for a function’s inputs?


Parameters or arguments

4. In C++, do all functions need to return an output?


Output is not needed (void)

5. What is another name for a function’s output?


Return value

6. If we know that a function returns a particular value, are we required to


store the return value in a variable?
It can directly use a cout statement to print its return value or it can be
stored a variable

7. TRUE/FALSE A C++ function can have multiple return values.

8. TRUE/FALSE The order in which we provide the inputs to a


function doesn’t matter.
9. What is the difference between a function’s return value and its return
type?
The return value is the value that the function is returning, and the return
type is the data type of the return value

10. Please determine what is printed to console for the following code
snippets:
a. cout << pow(1.0, 2.0) << endl; ----- 1^2 = 1.0

b. cout << pow(2.0, 1.0) << endl; ----- 2^1 = 2.0

c. cout << pow(2.0, 2.0) << endl; ----- 2^2 = 4.0

d. cout << sqrt(4.0) << endl; ----- 2.0

e. double x = 16.0;
cout << sqrt(x) << endl; ----- 4.0

f. cout << pow(pow(2.0, 2.0), sqrt(4.0)) << endl; ----- pow(4, 2) = 4^2 = 16

g. int result = floor(3.9);


cout << result << endl; ----- 3

h. int result = static_cast<int>(3.9);


cout << result << endl; ----- 3

i. int result = ceil(4.1);


cout << result << endl; ----- 5

j. cout << fabs(-42.0) << endl; ----- 42.0

k. double value = 5.0;


double testValue1 = 5.1;
double difference1 = fabs(value – testValue1);
fabs(5.0 – 5.1) = fabs(-0.1) = 0.1

double testValue2 = 5.2;


double difference2 = fabs(value – testValue2);
fabs(5.0 – 5.2) = fabs(-0.2) = 0.2

if(difference2 < difference1)


cout << “5.2 is closer to 5.0 than 5.1” << endl;
else
cout << “5.1 is closer to 5.0 than 5.2” << endl;

11. Let us assume a built-in function named compute() exists. You are told
that compute() accepts 3 parameters, an int, a double, and a string in this
order. You are also told that compute() returns a bool. Please write code
that would call this function and catch the return value in the appropriate
data type. You can use any values you like for the arguments to the function
– the goal is to verify your function call syntax.

bool result = compute(2, 5.9, “hello”);

12. What is the second argument to the following function call?


bool result = resize(2, 3);

13. For question 12, what is the return type of the resize() function?
bool

14. The following is the Euclidean distance formula. It can be used to find
the distance between two points on a cartesian plane (i.e., the x-y axis). On
the back of the current page, please write a full program that asks the user
for the x and y values of two points and uses the built-in functions you have
learned to evaluate the distance.

d = √¿¿
double x1, x2, y1, y2;
cout << “Please enter the values for x1, x2, y1, y2: ”;
cin >> x1 >> x2 >> y1 >> y2;

double distance = sqrt(pow(x2-x1,2.0) + pow(y2-y1,2.0));

cout << “The distance is “ << distance << endl;

You might also like