study foc final

Subdecks (2)

Cards (47)

  • How to read an integer input from the user in C++
    int inputInt; cin >> inputInt;
  • How to output a prompt message followed by an integer variable 'num' to the console in C++
    cout << "The number is " << num;
  • If the user enters 3.14 in response to the statement 'int value = 3.14;', the value stored in value will be 3
  • The C++ code 'int x; cin >> x;' reads an integer input from the user into x
  • Header file required to use manipulators setprecision and setw
    #include <iomanip>
  • setw(n) manipulator in C++
    • Formats the output of an expression in a specific number of columns
    • The default output is right-justified
    • If the number of columns specified exceeds the number of columns required, the outputs are left blank
  • Purpose of endl and "\n" when used in the cout statement in C++
    It initializes a new line
  • Output for the code 'double x = 15.6470; cout << setprecision(2) << fixed << x <<endl;'
    • 15.64
  • cin requires the user to press the [Enter] key when finished entering data
  • In the statement cin >> x;, x must be a variable
  • The statement cin >> x >> y; requires the input values for x and y to appear on the same line
  • cin >> skips all leading whitespace characters when searching for the next data in the input stream
  • The manipulator setprecision formats the outputs floating-point numbers in the fixed decimal format
  • Program that prompts the user to enter a decimal number and then outputs this number rounded to two decimal places
    Prompt the user to enter a decimal number
    2. Read the decimal number into a variable
    3. Output the number rounded to two decimal places
  • bool
    Logical data type in C++
  • Type-casting bool to int
    true => 1, false => 0
  • Type-casting int to bool
    A Zero value => false, A Non-Zero value => true
  • Prints 5. This is not a logical expression. It is an assignment expression.
  • Logical Expression
    Another way to complement an expression is just putting a Not operator (!) in front of it.
  • Branching/ Selection