a ← expression
DISPLAY (A)
A syntax error in this example occurs because the second statement attempts to display the variable A, which is not the defined variable. Variable names are case sensitive. Therefore, while the variable with a lowercase a in lowercase is defined by the first statement, the variable with a capital A in the second not defined. Therefore, the rules of the programming language were violated
DISPLAY (5/0)
In this example, there is no syntax error, because the language of the code is used correctly. However, this causes a runtime error because you cannot divide by zero. The execution of the program will halt at this line.
a 95
IF (a > 90)
DISPLAY("You got an A.")
IF (a > 80)
DISPLAY("You got a B.")
IF (a > 70)
DISPLAY("You got a C.")
You got an A.
You got a B.
You got a C.
This logic error occurs because the students score is also greater than 80 and 70 with no restriction that prevents multiple grades from being printed.
x - 2000*365
DISPLAY (x)
The result is of the multiplication is a large number. In many languages, this product would be large enough to be outside the range of certain data types. Therefore, if x is defined as a variable of one of those data type, this multiplication will cause an overflow error.
Of course, binary numbers are rarely used in real life.
Therefore, programmers must be able to go back and forth between the binary numbers we use in computing and the decimal numbers that we use in everyday life.
The key is to remember that the different binary digits represent different powers of 2.
For example, let's use the binary number 1101.
We need to find the powers of 2 that add up to the given decimal number. Start by finding the largest power of 2 that is less than the number.
Subtract that number from the original, and repeat until you're down to 0.
Try the example of the decimal number 200.
Images displayed on the screen are converted into binary formats and then processed by a computer displayed on our screen.
Digital images: are a collection of pixels. where each pixel consists of binary numbers.
If we say that one is black (or on) and o is white (or off), then a simple black and white picture can be created using binary Draw a grid and color the squares (1-black and 0-white) to create the picture
However, before creating the grid, the site of the grid needs to be known.
Images: are not often just black and white.
To represent colors computers also use binary numbers.
Color: is based on light.
Any color can be created using red, green and blue light.
The maximum value for any color in decimal 255, which is repte sented by 11111111 in binary.
The minimum number is 0.
A popular way of defining abstraction is information hiding.
Just as related program statements are bundled together, related program variables can be bundled together.
Such abstractions allow us to think of the data within a program hierarchically.
A list is an example of data abstraction.
A list is a data type that holds a collection of values.
aList[3, 7, 11]
aList is described as a "list of integers."
Within a list, when accessing its parts using an integer index, aList[1] gives us the value 3, aList[2] = 7, and so on. Lists allow for data abstraction in that we can give a name to a set of memory cells. For instance, in a colorList, a list that holds three colors ['red', 'blue', 'green'] instead of using three separate variables, colori, color2, etc., one variable colorList holds all the three variables. Each of the contents of the list is accessed by changing the index value.
To assign a value to a variable, the assignment operator is used.
In many programming languages, a single equals sign, =, is used as the assignment operator.
The variable name is always on the left of the ← sign.
The programming language will evaluate the right hand side of the assignment operator and then place the value into the variable on the left-hand side of it.
The previous value stored in a variable is overwritten by a new assignment statement.
Expressions: are calculations to be evaluated to an answer or single value.
In computer science, the value is then assigned to a variable if the value will be needed later.
It also could be displayed on a screen or printed.
You will get an error if you write:
The variable must be on the left and the assignment arrow points left.
The expression will be evaluated and loaded into the variable celsius.
P Parentheses
E Exponents
M Multiplication
D Division
A Addition
S Subtraction
Boolean values: are one of the foundations of computer code.
Understanding Boolean is important for writing correct, readable, and efficient code.
Boolean values can only be true or false, needing only one bit to represent its value.
Relational operators are used with Boolean values.
These are just like in your math class:
These are a key component to many programs.
They use the “if (condition)” structure, and the evaluation of the condition uses Boolean values.
As we know, Booleans can only be either true or false, so the program statements associated with the condition only run when the condition at that moment evaluates to “true.”
This changes the flow of the program from every statement running sequentially to filtering out some of the code that will execute, based on the Boolean value.
Notice that the code to be executed when the condition is true is surrounded by the curly braces, { }, in the “Text” version.
The code within the braces is indented, which helps with readability.
It also makes it easier to see if you are missing a closing brace }!
The REPEAT UNTIL loop has a condition to evaluate at each iteration of the loop.
The loop will continue to run while the condition evaluates to “false.”
This is similar to how an IF statement works except the condition for the IF statement must evaluate to true for it’s code to execute.
Combining Algorithms: One of the key features of algorithms is that once they are created, you can use them over and over, combine them for more complex problem solving, or modify them for a new use.
In a program or code snippet where there is an IF statement within another ser of IF statements, these are called nested IF statements.
When the outer IF statement is executed, the inner IF statement may also get executed.
This allows for the program solution to evaluate another expression after determining the results of a previous decision.
Determining the maximum or minimum number from two or more numbers.
The pseudocode for the maximum of two numbers is:
For the minimum of two numbers:
If you have more than two numbers, a computer can still only compare two at a time.
One number would be the current largest (or smallest), and the other would be the next number to compare it to.
Another common algorithm is calculating the sum and average of a group of numbers.
This is fairly straightforward since it is a concept you have already learned in math class.
One key element to remember is that you need to keep count of how many numbers you have added together so you will be able to calculate the average.
Lists: are a collection of items, such as a grocery list or a playlist of music.
A list in a program can be a collection of numbers, words, phrases, or a combination of these.
Usually a list only contains one type of data in a single list, but some programming languages do allow different types of data in the same list.
Lists provide the ability to store more than one value in the same variable, separated by commas, when the variable is defined as a list.
Lists are also called arrays in some programming languages.
Individual items in a list are called elements and are accessed by position using an index.
Index positions: are always integers and are enclosed within square brackets [index].
Most programming languages will have built-in procedures, or “methods,” of common functionality to use with lists.
Adding an item to a specific position in a list.
The INSERT command causes elements to the right of the indicated index position, i, to shift right one position to make room for the new element.
Appending an item to the end of the list.
The APPEND command will add the new element to the end of the list, so no index position is needed.
The size of the list increases by one.
Removing an item from a list.
The REMOVE command deletes the element at the provided index position and shifts the remaining elements one position to the left.
The size of the list decreases by one.
Length: The length of a list is the number of elements in the list.
Checking Each Item in a List
The above statement is a loop that will automatically repeat the code for each element in the list.
The programmer chooses the name for the iteration variable “item”.
Each pass of the loop will assign the value of the next element in the list to the variable “item”.
Processing lists with a FOR EACH loop takes advantage of features of both structures.
There are algorithms that are frequently needed for processing lists with iteration.
These include finding the largest or smallest number in a list.
Here is an example using a REPEAT UNTIL loop with a list of grades.
Another common algorithm is finding the sum and average of the values in a list.
Searching: deals with finding the needed element from everything in the dataset or determining that it is not there.
Linear Search: Linear searches, also called sequential searches, check each individual record, starting at the beginning and going to the end, one after the other in order to either find the desired data or to determine it is not in the dataset.
Binary Search: Binary searches are far more efficient than linear searches.
Procedures: are also called functions in some programming languages.
These are sections of code that will be executed only when they are called by the main program or another procedure.
They must be defined in a program before they can be used in the program.
Random number generator programs: are useful tools for writing software, mainly in designing games.
A random number generator picks a number at random out of a range of values.
Procedures: have an optional feature called a return statement.
The return statement has two uses.
One purpose is to end a procedure before the end of the code is reached.
No other code in the procedure will be executed after the return statement.
The other use is to send a value back to the calling program.
Built-in Procedures: Built-in procedures are prewritten and tested code that are included with the programming language.
DISPLAY(): DISPLAY() is a built-in procedure used for this course on the exam.
INPUT(): It accepts data from the user, usually from the keyboard.
Parallel computing is needed for real-world simulations and modeling.
Multiple processors can operate independently but share the same memory resources.
Distributed computing allows problems to be solved that could not be solved on a single computer because of either the processing time or storage needs involved.
Parallel computing uses a single computer with multiple processors.
Distributed computing uses multiple computing devices to process those tasks.