C++

Ace your homework & exams now with Quizwiz!

Variable

A named storage container which holds a value that programs can manipulate. Each variable has it's own type, and, the type determines the size & layout of the variables memory as well as the set of operations that can be assigned to that variable. C++ Example: int a(1); -or- int b = 13;

int

A native type representing the integers, which are positive whole numbers and their opposites. Ex: int myInt; myInt = 13;

#include

A pre-processor directive - or - Replaces the directive with the content of thee file whose name is listed in the directive. - or - A directive that instructs the computer to make available facilities from a file. Ex: #include <iostream>

Expression Statement

A statement can involve an expression, an expression can be inside of a statement. When a statement causes an expression to be carried out, it's known as an expression statement. Ex: x=4; When you have x=4; you're using the assignment operator to take the value 4 and assign it to the variable x. That statement causes an expression to be computed and it's essentially giving that value 4 to the variable x. An expression statement can 1) assign values to one to more variables 2) invoke a method 3) delete a property from an object 4) the = operator is used for assignment 5) the += etc. operators can also be used

else if statement

A type of selection statement, that allows you to check a second conditional if your first conditional was false. Ex: //if expression1 was true then statement1 gets run //if exp1 is false & exp2 is true, then state2 gets run //if one is false the other gets run, both can run if both true, or neither can run if neither are true. if (Expression1) { Statement1 } else if (Expression2) { Statement2 } in the execution of a conditional statement, a statement that indicates that the following block only executes if the previous statement's parameter evaluates to false and the current statement's parameter evaluates to true The most general way of writing a multi-way decision. 1. The expressions are evaluated in order. 2. If any expression is true, the block associated with it is executed and this terminates the whole chain. Used if statement is false Specifies a new condition if the first condition is false

std::

C++ Standard namespace. Ex: std::cout << "Hello World!" Can be declared before main function to negate its reuse. Ex: using namespace std; int main() { cout << "Hello World!" }

char

C++ datatype that can only contain a single character (symbol or variable). In order to initialize a char type variable, you must put single quotes around the character with an assignment operator for your variable. Example: char myCharacter; myCharacter = 'y';

Imperative programming language

Imperative Programs, based on the imperative paradigm, perform computations based on state changes (where a state is a small amount of memory). Simply put, imperative programs calculate values and store the values into variables for latter use. e.g., C, C++, Java, C#, Python, PERL, Pascal, Ada, etc.

Statement

Something that executes a sequence of operations. It carries out an action without returning a value. It doesn't return something, although it can change things. When a statement changes something, like the value of some sort of variable, it's known as a side effect. Ex: int x; When you declare a new variable such as an integer, like, int x; you're actually creating a statement. Notice that there's a semicolon at the end of a statement but not necessarily. A statement can involve an expression, an expression can be inside of a statement. When a statement causes an expression to be carried out, it's known as an expression statement. - or - A syntactic unit of an imperative programming language that expresses some action to be carried out. A program written in such a language is formed by a sequence of one or more statements. A statement may have internal components (e.g., expressions).

Expression

Something that takes a combination of operators, and, operands (which operators act upon), & returns some sort of value after performing some type of computation. Ex: 2+2 An expression such as 2+2 would return the number 4 because the computer knows that 2+2 is a sort of command that tells it to perform a computation of addition on the two numbers on either side of the plus(+) operator. Ex2: "hello" The string of characters, "Hello", is something that returns the value of Hello in the form of a string. - or - An expression in a programming language is a combination of one or more constants, variables, operators, and functions that the programming language interprets (according to its particular rules of precedence and of association) and computes to produce ("to return", in a stateful environment) another value.

Truth Values

The attribute by which a statement is either true or false. Zeroes == False && Nonzeroes == True. Truth Values: 0 is false 1 is true -1 is true 00 is false 0.00 is false 0.0000001 is true Notes: • An expression returns a value and each expression can be evaluated for the truth value of such an expression. Truth values are one of two states; true or false. Depending on the Truth Value of a particular expression or value of some variable, you may wish to perform actions. You may wish to perform some set of instructions if that truth value is true, and, a different set of instructions if that truth value is false. Or you may wish to have a set of instructions that only gets executed if a certain condition is true & does not execute anything at all if that is false. For that reason it's necessary to determine the truth value of a particular expression. • Any numerical value other-than-zero is considered true in computer-logic terms. The number 1 is true, as is -1 because it's a non-zero. This is where you have to be careful because you may perform some sort of computation with a high degree of accuracy with the result being some floating point number very close to zero, you may wish to perform some sort of steps in your code depending on if that value is zero or nonzero. IF it's a very small value, such as 0.0000001, that still evaluates to true because it's nonzero! • All ASCII characters have a numerical representation, for example, the lowercase letter a has an ASCII code of 097. So, because all characters have a numerical value, they thus have a truth value. So the letter, or character, of a, would evaluate to true.

if statement

The common programming structure that implements "conditional statements". A line that determines whether or not you run a certain chunk of code. Example1: if (expression) { statements... } // what goes in parenthesis is known as a conditional. Example2: int a = 5; int b = 4; if (a==b) { cout << "Hello!"; } Statement1; STatement2; // Hello will never be printed because a!=b // If there are further statements below, code gets run down until the if statement, which is when the conditional is checked, then the flow of control goes from the main function where you were before in the program, then to the conditional, if the conditional evaluates to true then the flow of control is inside the if body (cout<<hello in this example), and then whenever the if body is finished, the flow of control resumes after the ending curly brace (}) in your if body, and statement 1 followed by statement 2 get run. // Now if the if statement evaluates to false then the entire body of the if statement gets skipped and the flow of control continues right after that ending curly brace and the rest of the program gets run. // So if you were to have another if statement right after the first then the flow of control would go in to the if body and if true will display World! See Ex3 below. Example3: int a = 5; int b = 4; if (a==b) { cout << "Hello!"; } if (a!=b) { cout << "World!"; }

Assignment operator

The equal sign (=) in an assignment statement. - or - The '=' character causes the compiler or interpreter to evaluate to the expression on its right and store the result in the variable(s) on its left.

Value

The numerical amount denoted by an algebraic term; a magnitude, quantity, or number. Ex: "the mean value of x" - or - The representation of some entity that can be manipulated by a program. The members of a type are the values of that type. The "value of a variable" is given by the corresponding mapping (aka association) in the environment. https://en.wikipedia.org/wiki/Value_(computer_science)

Fundamental Data Types

Three data types are Integral, Floating Point, & Void. Native types represent the integers, which are positive whole numbers & their opposites with a max size of four bytes. Three fundamental datatypes; 1. Integral; 1a. int (4 bytes) - Cannot store larger numbers. 1b. short (<int) - For very small numbers. 1c. long (>int) - For large numbers. 1d. char (1 byte) - Single character value. 1e. bool (1 byte) - True or False 2. Floating point; Consists of a integer component, as well as, a fractional component (represented to the right of a decimal point). Computers represent large numbers like 7,289 as 7.289x10³ which looks like this 7.289e3. 2a. float (4 bytes) 2b. double (> float) - Rare, for great precision. 2c. long double (>double) - Rarely needed. 3. Void; specifies empty values and no variable of datatype void can be specified. Void datatypes are mainly used to describe the return type for functions that don't return anything.

Relational Operators

Used to compare two values. Operators include: > greather than (ex: if 5>4 then is true) < less than (4<5 is false) >= greater than or equal (4>=4 or 5>=4 is true) <= less than or equal (4<=4 or 4<=5 is true) == equal to (5==5 is true) (4==5 is false) != not equal to (5!=4 is true) ! negation operator aka "is not" (!false is true, !(5!=4) is false) Note: • Both >= and <= are considered a single type of operator. They are an "inclusive or", not an "exclusive or", meaning that if one or the other are true, or if both are true, then you get a true result. • Double equals (==) is equal-to, where as a single equals sign (=), is an assignment operator. • A string object type in C++ can be used to compare one string to another string! • So, we can compare one thing to another with relational operators and we can see the truth value that results from such a comparison. Now, how do we use that?... How do we, say for example, write some code that we wish to run based on a condition that we check? Say that we have a couple of integer variables and one equals five and another equals four. We may wish to run some section of code based on the comparison of those two operators of those two values... So, how do we compare two things? This is a very powerful tool, and is used very commonly in nearly all programming languages and it's known as the "if" statement. The if statement is something that can compare two things or more. It can run some sort of check and if that check returns true then execute some body of code.

if-else statement

allows your program to perform one action if the Boolean expression evaluates to true and a different action if the Boolean expression evaluates to false. Control structure that lets us do either one section of code or another depending on a test. executes a segment of code when a given condition is true, and a different segment of code when it is false Example: int main() { int a(1); int b = 13; if (a < b) { cout << "a is less than b." << endl; } system("pause"); }


Related study sets

OB Chapter 13 Labor and Delivery

View Set

DLC210: Implementing the Army's Physical Readiness Training (PRT) Program

View Set

Genetics - Ch. 9 DNA Replication & Recombination

View Set

Practice - questions test bank - Chapter 6, Values, Ethics, and Advocacy

View Set

Personal Financial Planning Final Exam

View Set

How can an organization provide superior customer value to customers? Group of answer choices

View Set

VNSG 5 Pharmacology 🙏❤️🙏

View Set