Mathematical Functions Quiz
8 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which function would you use to calculate the cosine of an angle given in radians?

  • tan(radians)
  • cos(radians) (correct)
  • asin(a)
  • sin(radians)
  • What does the function log10(x) return?

  • The square root of x
  • e raised to the power of x
  • The natural logarithm of x
  • The base 10 logarithm of x (correct)
  • Which of the following functions is used to obtain the angle in radians for the inverse of cosine?

  • asin(a)
  • acos(a) (correct)
  • atan(a)
  • cos(radians)
  • If you need to round down a floating-point number x, which function should you use?

    <p>floor(x)</p> Signup and view all the answers

    What is the result of calling sin(PI / 6)?

    <p>0.866</p> Signup and view all the answers

    Which function should be used for calculating e raised to the power of x?

    <p>exp(x)</p> Signup and view all the answers

    For which of the following numeric inputs is the function sqrt(x) defined?

    <p>Any non-negative number</p> Signup and view all the answers

    What does the function atan(a) compute?

    <p>The angle in radians for the inverse of tangent</p> Signup and view all the answers

    Study Notes

    Mathematical Functions - Trigonometric

    • Trigonometric functions (sin, cos, tan, asin, acos, atan) operate on angles in radians.
    • These functions are not required to be memorized, but students should know they exist and how to use them (online search).

    Mathematical Functions - Exponent

    • All functions from page 3 to 5 are from the cmath header library.
    • exp(x): Returns e raised to the power of x (ex).
    • log(x): Returns the natural logarithm of x (ln(x)).
    • log10(x): Returns the base 10 logarithm of x (log10(x)).
    • sqrt(x): Returns the square root of x (√x), where x ≥ 0.
    • ceil(x): Rounds x up to the nearest integer (returned as a double).
    • floor(x): Rounds x down to the nearest integer (returned as a double).
    • pow(a, b): Returns a raised to the power of b (ab).

    Mathematical Functions - min, max, abs

    • Functions min(x, y), max(x, y), and abs(x) are from the cstdlib header library.
    • min(x, y): Returns the minimum of x and y (x and y should be the same type).
    • max(x, y): Returns the maximum of x and y (x and y should be the same type).
    • abs(x): Returns the absolute value of x.

    Character Data Type and Operations

    • char stores a single character.
    • Character literals are enclosed in single quotes (e.g., '9', 'Z').
    • ASCII (American Standard Code for Information Interchange) represents characters in 1 byte.

    Escape Sequence

    • Some characters cannot be directly typed or have special meanings in C++.
    • Escape sequences (e.g., \b, \t, \n, \f, \r, \, ', ") represent these characters.
    • A backslash () followed by a character or combination of digits is interpreted as a single character.

    Numeric Operators on Characters

    • char is treated as an integer (byte size).
    • Numeric operators can be applied to char operands.
    • char operands are automatically converted to numbers if the other operand is a number.

    Casting Numeric Types into Chars

    • Positive integers in hex range 0x00 to 0xFF can be implicitly cast to char.
    • For larger integers, only the last byte is used.
    • Floating-point types are explicitly cast into char.
    • C++ first converts them to integers.

    String Type

    • A string is a sequence of characters.
    • Functions length() and size() return the number of characters in a string.
    • at(index) returns the character at the specified index in a string.
    • The subscript operator [] can be used to access and modify characters in a string.
    • Functions like append, substr, and others, can be used to manipulate strings more effectively.

    String Operators

    • Strings can be concatenated using the + operator.
    • Relational operators (==, !=, >, >=, <, <=) compare strings character-by-character.

    Reading Strings

    • Strings can be read from the console using cin.
    • getline(cin, var) reads an entire line of input into a string variable.

    Example - Generate a Random Number

    • The rand() function generates pseudorandom positive integers.
    • The rand() % (max - min + 1) + min; formula generates random numbers between specified limits.
    • srand(time(0)); initializes the random number generator with the current time.

    Example - Generate a Random Character

    • Every character has a unique ASCII code value between 0 and 127.
    • Generate a random integer between 0 and 127, cast to char.

    Checkpoint - Character Functions

    • isdigit(ch) returns non-zero if the character is a digit (0–9).
    • isalpha(ch): returns non-zero if it's a letter.
    • isalnum(ch): returns non-zero if it's a letter or digit
    • islower(ch): returns non-zero if it's a lowercase letter.
    • isupper(ch): returns non-zero if it's an uppercase letter.
    • isspace(ch): returns non-zero if it's a whitespace character.
    • tolower(ch): Converts a character to lowercase.
    • toupper(ch): Converts a character to uppercase.

    Reading and Writing to a File

    • Objects (for File I/O) are defined using the #include <fstream> header file.
    • ofstream objects write to files, ifstream objects read from files
    • open() function initializes these objects with a file.
    • The >> (extraction) and << (insertion) operators are used with files
    • Close the file (using .close() ) when finished to avoid issues if not closed, or in larger programs.
    • Files are stored on a disk and can be accessed later.

    Tips when reading from files.

    • Check if the file exists before trying to read from it.
    • If there is no data when reading from the file, the variables' values will not be updated.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    Description

    Test your knowledge of fundamental mathematical functions including trigonometric functions, exponent functions, and min/max/abs calculations. This quiz will help you understand the application and usage of these functions in various contexts.

    Use Quizgecko on...
    Browser
    Browser