The purpose of this question set is to give you a chance to focus your knowledge of the built-in libraries in C/C++.
Show the preprocessor directive(s) needed to include any library in your program. (What symbol makes this a preprocessor directive?)
#include <______> ^ ^ | | | +------ fill in the library's name | +------ the # symbol makes this a preprocessor directive We also need to place a using directive to more conveniently use standard library features (since they are all collected in a namespace called std).
Which of the following are part of the built-in library suite? (Remember that there are two different naming conventions!)
If it is a library, tell if it is C or C++ native (also tell if it is using a new-style or old-style name). If it isn't, explain the confusion.
The pow function comes from the cmath library. So does the fabs function for absolute value. However, the abs and labs functions for absolute value are in the cstdlib library (along with the functions for random number generation).
Translate the following math/physics formulas to C++ expressions (variables need not be declared; they'd all be floating-point anyway, right?):
pow(x, y+7) (-b + sqrt( b*b - 4*a*c))/(2*a) fabs(x - y)
P + rho*v*v/2 + rho*g*y 2*M*R*R/5 OR pressure + density*velocity*velocity/2 OR 2*mass*radius*radius/5 + density*gravity*height
TRUE✗ | / | FALSE✓ | When I include functions from the built-in library suite, I must also type their prototypes into the main application file myself. |
---|---|---|---|
TRUE✗ | / | FALSE✓ | My variable names must match the names of the arguments listed in the library function's head. |
TRUE✗ | / | FALSE✓ | It is common for programmers to browse the physical contents of .h files (i.e. actually look at the library header files). |
TRUE✗ | / | FALSE✓ | Libraries contain only functions — no constants or variables. |
TRUE✓ | / | FALSE✗ | C libraries work exactly the same as C++ libraries (although they have funny names on some systems). |
Name at least three of the objects, functions, and/or constants provided by each of the following libraries.
fabs ceil log asin sin pow exp log10 acos cos floor sqrt atan2 atan tan
toupper ispunct isdigit isupper tolower iscntrl isalnum islower isspace isalpha isxdigit
cout .ignore .fail .precision cin .peek .flush cerr .clear .setf
RAND_MAX abs rand labs srand
TRUE✗ | / | FALSE✓ | The tolower function will only work on alphabetic values. |
---|---|---|---|
TRUE✗ | / | FALSE✓ | The argument (and return value) of tolower is of type char. |
TRUE✓ | / | FALSE✗ | Your program must use/store the value returned from tolower — your variable is not automatically altered. |
TRUE✓ | / | FALSE✗ | However, to print the returned value directly, you must type-cast it or the ASCII value of the lowercase version will be printed instead of the lowercase version itself! |