1/35
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What are the typical architecture and components of a computer?
The von Neumann architecture use a single storage structure to hold the set of instructions and data.
The CPU actually runs programs.
What are the different types of memory?
Main Memory: RAM (random access memory) - the computer can read or change in any order, usually stores working data and machine code, but requires power (volatile)
Secondary Storage: Direct-access data storage media, such as hard drives or CDs; sequential access data storage media, such as a tape. Is nonvolatile, and retains info after power is removed.
Compiled Language
must be translated to machine-readable instructions using compilers (human-readable source code becomes executable file); ex. C++
Interpreted Language
instructions are not precompiled for the target machine in a machine-readable form, and are assisted by an interpreter (source code becomes target code line by line); ex. Python, JavaScript
Compiled v. Interpreted Languages
Compiled: entire source code is translated to machine code before execution, binary code is platform-dependent, and code must be recompiled if changed
Interpreted: each source code command is translated to machine code and then executed, is platform-independent because interpreters themselves execute the source code, and there is no need for compilation
Dynamically Typed Language vs. Statically Typed Language
Dynamically Typed: no variable declaration, only variable assignments, type safety occurs at runtime (ex. Python)
Statically Typed: variables are declared, source code is analyzed to verify type safety
How to use std::cout with any number of outputs cascaded using the stream insertion operator <<?
std::cout « “phrase to be executed” OR
std::cout « variable «
How to use literals and variables in an output statement, including strings, characters, integers, floating points?
Block Comment v. Line Comment
Line Comment: used for short comments (//)
Block Comment: used for long comments and documentation (/*, */)
What are variables in a C++ program?
a named storage location in computer memory where you can store and manipulate data
Why do we use variables?
they keep values accessible and can be easily reused
variables give values context
What are the rules governing the naming of variables (or more generally identifiers) and the conventions typically used?
names can begin with an upper or lowercase letter, or an underscore
the rest of the name can have letters, digits (0-9), or underscores, but no special symbols
names are case sensitive, and some reserved C++ keywords cannot be used
How to declare and initialize a variable, and different ways to initialize a variable in declaration?
type of variable and then variable name
ex: int count, weight, height
How to swap the value of two variables?
in the case of swapping a and b:
declare a = value, b = value, and tmp (temporary placeholder variable)
tmp = a
a = b
b = tmp
How to declare variable using type inference?
type inference infers the type of variable you are declaring
ex: auto x = 5; x is inferred to be int
auto y = 3.14; y is inferred to be double
auto z = “Hello”; z is inferred to be char
Numeric literals
if a numeric literal is provided without a suffix:
if it does not have a decimal point, then it is treated as int
if it has a decimal point, then it is treated as double
type suffix in integer literals:
l or L: long
u or U: unsigned integer
ul or UL or lu or LU: unsigned long
ll or LL: long long
ull or ULL or LLU or llu: unsigned long long
type suffix in floating point literals:
f or F: float
l or L: long double
Integer Overflow
when you attempt to store a value in an integer variable that is outside of the range that can be represented by the variable- leads to undefined behavior
Arithmetic and Arithmetic Operators
addition (+)
subtraction (-)
multiplication (*)
division (/)
integer division (/) (rounded)
modulus (%) -remainder of a/b
Rounding
round to nearest, ties to even
ex: 1.5 =2 -1.5 = -2
2.5 = 2 -2.5 = -2
3.5 = 4 -3.5 = -4
4.5 = 4 -4.5 = -4
1.15 = 1.1
1.25 = 1.2
1.35 = 1.4
1.45 = 1.4
String Type
#include <string>
std::string variable
string sentencing
std::string variable
std::cout « “Statement”
std::getline(std::cin, variable)
std::cout«”echo of input”
String Literals
sequence of characters that together form a null-terminated string; enclosed between double quotation marks
ex: “Hello World!”
Escape Sequences
new line: \n
horizontal tab: \t
backslash: \\
double quote: \"
Concatenating String Literals
string literals can be directly concatenated:
std::cout «”statement”
Raw String
text is included exactly as written, including newlines and quotations
std::cout« R”(“…”)”;
Namespace/Resolving Scope of a Name/using directive
a namespace is a declarative region that provides a scope to the identifiers (names of types, functions, variables) inside it.
they organize code into logical groups to prevent name collisions
scope resolution: std::string variable1; ms::string variable2
using directive for a single identifier: using std::string; string variable 1; ms:: string variable2
using directive for all the identifiers in a namespace: using namespace std;, string var1, cout «”text”, ms::string var2
Operator Precedence Rules
start from left to right, but multiplication has higher precedence than addition.
Integer to/from signed or unsigned binary numbers
positive number to unsigned integer: divide integer by wo until you reach 0, read remainder from bottom to top, and pad 0 in front for a total of 8 bits
binary value of a negative integer: find binary representation of the positive value, invert the bits, and add 1 to the result.
Size of basic data types?
one byte is 8 bits, 256 diff values;
char: 1 byte
bool: 1 byte
int: 4 bytes
short: 2 bytes
long: 4 or 8 bytes
long long: 8 bytes
float: 4 bytes
double: 8 bytes
long double: 8, 12, 16
decimal precision of basic data types:
float = 6-7 decimal digits
double = 15 decimal digits
long double = 18 decimal digits
Integer and Floating Point Types/Range based on bytes/Precision
Floating Point: FP 32 (single precision), sign bit = 1, exponent width = 8, precision = 24
FP 64 (double precision), sign bit = 1 , exponent width = 11, precision = 53
precision
std::cout.setf(std::ios::fixed;
std::cout.setf(std::ios::showpoint)
std::cout.precision(number)
Implicit Type Conversions
in arithmetic operations, if operants are of mixed types, then the types of operants are matched, and the result is typically of the same type as the operant with a higher precision.
std::cin»
std::cin » variable