Robotics C++ Physics II AP Physics B Electronics Java Astronomy Other Courses Summer Session  

Concepts and Terminology

 

Algorithm

Assignment Operators

Selection Statements

Formating

Pseudocode

Increment and Decrement Operators

Repetition Statements

Casting

 

Algorithm

 

 

A procedure for solving a problem in terms of the actions to execute and the order in which these actions execute.

 

Pseudocode

 

Statement of the solution to a problem in English, without the syntax of a language. Pseudocode normally describes only executable statements. It is used to develop an algorithm.

 

Assignment Operators

 

Operator 

Example Expression 

Meaning 

+=

c += 7

c = c + 7

-=

c -= 4

c = c - 4

*=

c *= 3

c = c*3

/=

c /= 9

c = c/9

%=

c %= 2

c = c % 2

 

Increment and Decrement Operators (we will focus on the ones in red - primarily the first one: ++)

 

Operator 

Name

Example

Meaning

++

preincrement

++a

Increment a by 1, then use the new value of a in the expression in which a resides

++

postincrement

a++

Use the current value of a in the expression in which a resides, then increment by 1

- -

predecrement

- - b

Decrement by 1, then use the new value of b in the expression in which b resides

- -

postdecrement

b - -

 value of b in the expression in which b resides, then decrement by 1

 

Note: For non-integer increments or decrements, you cannot use ++ or --. In this case the longer version (a = a + 1.07, for example, is required.

 

Selection Statements

 

if (this chapter), if else (this chapter), switch (chapter 5)

 

if:

 

    if (a > b)

    {

 

    }

 

    Checks the Boolean at the beginning - may not execute at all

    If Boolean is true, the following statement executes

    If Boolean is false, the following statement is skipped

 

if else:

 

    if (a > b)

    {

        //code

    }

    else

    {

        //code

    }

 

    Boolean if checked at beginning, may not execute at all

    Checks the Boolean following the if, same as above

    However, if Boolean if false, the else statement is executed

 

switch: (covered later)

 

    Selects from alternatives

    Useful in situations where a large number of if statements would be required

 

Repetition Statements

 

while (this chapter), do while (chapter 5), for (chapter 5)

 

while:

 

    while (a > b)

    {

        //code

        //counter increment or decrement statement

    }

 

    Boolean is checked at beginning - may not execute at al

    Executes as long as the Boolean is true

    If Boolean is false, the statement is skipped

    When Boolean becomes false, remaining statements are executed

    Need a sentinel that is either incremented or decremented - otherwise get an infinite loop

 

do while:

 

    do

    {

        //code

        //counter increment or decrement statement

    }

 

    while (a > b)

 

    Note that it always executes at least once

    Boolean is checked at the end

 

for:

 

    for (int a = 1; a <=10;a++)

    {

 

    }   

 

Repeats for a specified number of times until termation condition is encountered

   

Formatting

 

Not tested but may be on lab exercises

 

Casting

 

Used to change the data type of a variable for an operation

It does not change the original declaration for the data type of the variable