csci 240

Cards (149)

  • int(integer)

    A - / + number between -2.1b and 2.1b
  • unsigned int

    Exclusively non-negative number between 0 and 4.2b
  • float & double

    Represent real numbers with decimal points, with the only difference being the amount of precision. Double is more
  • char
    A single, ASCII character, usually represented by a value stored within a pair of SINGLE-quotes, e.g. 'a'
  • string
    Effectively an array of character values
  • bool
    A variable that contains ONLY true or false
  • ifstream & ofstream

    For opening input/output files, respectively
  • Anytime we declare variables or instantiate objects from a class, we always start with the data type of the variable, followed by the programmer-defined name
  • cout is our "standard output stream" that we would print "stuff" to using the "output stream operator" or <<
  • cin is our "standard input stream" that we would extract data from the user through the keyboard using the "input stream operator" >>
  • endl and "\n" do the same thing: print a new line
  • Conditional statements
    If-statements, if-else statements, switch statements
  • Relational expressions evaluate to true or false
  • The && (and) operator requires both relational expressions to evaluate to true for the result to be true
  • The || (or) operator requires EITHER relational expression to evaluate to true for the result to be true
  • == is the equality operator, = is the assignment operator
  • Switch statements

    Great for testing for direct equality to a great number of potential outcomes or use-cases, the unique keyword is case
  • Loop structures

    • for loop
    • while loop
    • do-while loop
  • To utilize "random" numbers, we start with "seeding" our RNG or "random number generator"
  • Arrays
    Allocate LOTS of variables all at once, the first element is always at index 0, the last legal index is at size - 1
  • Manipulating arrays

    1. Iterate from start to finish
    2. Iterate in reverse order
    3. Access individual elements
  • To find the mid-point of an array, we can use array[MAXIMUM_ARRAY_SIZE / 2]
  • Calculating the average of an array
    1. Sum up all the elements
    2. Divide the sum by the number of elements
  • The return 0; statement is commonly the "exit point" of the program
  • How to open a file 

    #include <iostream>
    #include <fstream>
    int main() {
    // 1. Declare an object of type fstream.
    std::fstream file;
    // 2. Open the file using the open function.
    file.open(" file_name.txt ", std::ios::in);
    // 3. Check if the file is successfully opened.
    if (!file.is_open()) {
    std::err << "Unable to open file_name.txt";
    return 1;
    }
    // 4. File operations go here...
    // 5. Close the file using the close function.
    file.close();
    return 0;
    }
  • Bool is true or false not true and false? Is this True or False
    True
  • #include <iostream>
    // cout, cin, endl
  • #include <iomanip>

    fixed, setprecision, setw, left, right
  • #include <fstream>
    ifstream, ofstream, fstream
  • What is an example of a standard library?

    #include <iomanip>
  • The values in array are equal to 7
      for ( int i = 0 ; i < MAXIMUM_ARRAY_SIZE ; i++ )  {    if ( array[i] = 7 )      cout << "This value is equal to 7." << endl;  }*/
  • Before I can start generating random numbers, I have to seed my RNG first
    RNG or "random number generator"  srand( 33 ); // We can do this with a fixed value to ensure the same sequence of  // numbers are used
  •   cout << rand() % 101 << endl; // Will generate random numbers in the range [0, 100]  cout << rand() % 61 + 15 << endl; // [15, 75]  cout << rand() / 61 << endl;What are the bounds of this code?
    (15 to 75)
  • Integer variable

    Holds a numerical value
  • String variable

    Holds text data
  • slacker == 100
  • myName == "Daniel"
  • slacker > 0

    Slacker is positive
  • slacker > 0 && (slacker % 30 == 0)

    Slacker is a positive value and a multiple of 30
  • switch (slacker)

    1. case (0): slacker == 0
    2. default: This is the default statement