Lesson 3

Cards (34)

  • Program – a collection of text that commands a computer to perform algorithms
  • Programming Language – A collection of rules and syntax used to describe a program, employed based on the user’s objective and the computer's format and usage
  • Programming – An act of writing algorithms while utilizing a programming language
  • Low-Level Language – programming languages written in a format that is easy for computers to interpret, examples include Machine language and Assembly language
  • High-Level Language – programming languages written in a format that resembles human language and diminishes user awareness of hardware devices, examples include C, C++, Java, Python, etc.
  • C++ Language – a general-purpose programming language with a bias towards systems programming that supports data abstraction, is a better C, supports generic and object-oriented programming, and is case sensitive
  • Parts of a C++ Language:
    • Pre-processor directive instructs the compiler to locate the file that contains code for the <iostream> library
    • Allows you to use cout and endl without the prefix std::
    • Entry point for the application when program execution starts
    • Closing curly brace
    • Opening curly brace
    • Body of the program where the content is located or written
    • Used to end a function or method when a value is expected to be sent back to a caller
  • Processing a C++ Program:
    • Step 1: SOURCE CODE / SOURCE PROGRAM: a program written in a high-level language, created in the text editor, must be saved in a file with the extension .cpp
    • Step 2: PREPROCESSOR DIRECTIVES: statements that begin with the symbol # processed by a preprocessor program
    • Step 3: COMPILER: checks the source program for syntax errors and translates the entire source program into the equivalent machine language with an executable format
    • Step 4: LINKER: combines the object program with other programs in the library to create the executable code
    • Step 5: LOADER: loads the executable program into main memory for execution
    • Step 6: EXECUTION: process by which a computer or virtual machine executes the instructions of a computer program
  • Terms to Remember:
    • Value: representation of an entity that can be manipulated by a program and is classified based on different data types
    • Variable: a one-word name that points to a value
  • C++ Data Types:
    • Data Type: determines the type of data that a variable can hold
    • Primitive Data Type: built-in or predefined data types that can be used directly by the developer to declare variables
    • INTEGER: Keyword int, deals with integers or numbers without a decimal part
    • FLOATING-POINT: Keyword float, single precision data type that deals with decimal numbers, max number of decimal places: 7
    • DOUBLE FLOATING POINT: Keyword double, double precision data type that deals with decimal numbers, max number of decimal places: 15
  • Primitive Data Types:
    • Double: double precision data type dealing with decimal numbers, max 15 decimal places
    • Boolean: used to store Boolean or logical values like True or False
  • Character Data Types:
    • Char: represents characters (letters, digits, special symbols)
    • Wide Character (wchar_t): character data type with a size greater than the normal 8-bit datatype
  • Storage and Values of Data Types:
    • Char: 1 byte, signed -128 to 127, unsigned 0 to 255
    • Bool: 1 byte, true and false
    • Int: 4 bytes, signed -2,147,483,648 to 2,147,483,647, unsigned 0 to 4,294,967,295
    • Short: 2 bytes, signed -32,768 to 32,767, unsigned 0 to 65,535
    • Long: 4 bytes, signed -2,147,483,648 to 2,147,483,647, unsigned 0 to 4,294,967,295
  • String:
    • A sequence of zero or more characters enclosed in double quotation marks
    • Determining the length of the string includes counting any spaces
  • C Strings:
    • One-dimensional arrays of characters terminated by a null character ‘\0’
    • Example: char greeting[] = “Hello”;
  • String Functions:
    • strcat: concatenates string s2 onto the end of string s1
    • strncat: concatenates string s2 onto the end of string s1 up to n characters
    • strcmp: compares two strings lexicographically and returns values: 0 if s1 and s2 are the same, less than 0 if s1 < s2, greater than 0 if s1 > s2
    • strcpy: copies string s2 into string s1
    • strncpy: copies string s2 into string s1 up to n characters
    • strlen: returns the length of a string
  • Derived Data Types:
    • Function: block of code defined to perform a specific task
    • Array: collection of items stored at continuous memory locations
    • Pointers: symbolic representation of addresses enabling call-by-reference and dynamic data structures
    • Reference: alternative name for an existing variable
  • Abstract Data Types:
    • User-defined data types like class, structure, union, and enumeration
  • Terms to Remember:
    • Operators: symbols for calculation, relationship, comparison, and operations on operands
    • Constant: memory location with content not allowed to change during program execution
  • C++ Tokens:
    • Token: smallest individual unit of a program
    • Special Symbols: operators in the form of mathematical symbols, punctuation marks, or two characters regarded as a single symbol
  • C++ Operators:
    • Arithmetic Operators: used for mathematical operations like addition, subtraction, multiplication, and division
    • Increment and Decrement Operators:
    • Pre-increment: ++variable
    • Post-increment: variable++
    • Pre-decrement: --variable
    • Post-decrement: variable-
  • Increment and decrement operators in C++:
    • Pre-increment: ++variable
    • Post-increment: variable++
    • Pre-decrement: --variable
    • Post-decrement: variable--
  • Relational operators in C++ are used to compare values and return True or False according to the condition
  • Logical operators in C++ are used to perform logical AND, OR, and NOT operations
  • Assignment operators in C++ are used to assign values to variables
  • C++ tokens are the smallest individual units of a program written in any language
  • Identifiers in C++ consist of letters, digits, and the underscore character (_), and must begin with a letter or underscore
  • Legal identifiers in C++ can include words like first, conversion, payrate, counter1, but cannot have spaces or special characters like + or begin with a digit
  • C++ statements:
    • Declaration statements are used to declare things such as variables
    • Executable statements perform calculations, manipulate data, create output, accept input, and more
  • Output statements in C++ involve the output stream, where bytes flow from main memory to the device (display) using the stream insertion operator
  • Expressions in programming are combinations of values, variables, and operators
  • Casting in C++:
    • Implicit Type Coercion automatically changes a value of one data type to another
    • Cast Operator (static_cast) is an explicit type conversion to avoid implicit type coercion
  • Escape sequences in C++ are special characters used in control strings to modify the format of an output
  • Three-step rule in programming:
    1. Visualize the problem by creating an algorithm using a flowchart
    2. Translate into pseudocodes
    3. Write the equivalent C++ codes for each pseudocode