CPU -Central Processing Unit -Runs programs
RAM -Random Access Memory -Stores programs & Data -Volatile: when computer is shut down data is lost
ROM -Read-only memory -retains content when powered off.
Secondary storage- USB, external hard drive, CD ROM,
Programs
Note: CPU only understands machine language (binary)
Fetch-decode-execute cycle:
1) Fetch: read the instruction from memory
2) Decode: CPU determines which operation to preform
3) Execute: preforms the operation
Languages
Assembly Language: Uses word called mnemonics for instructions EX: ADD, SUB, AND, OR, MOV, NOT
High- level Language
Uses Keywords or reserved words that are easy to understand
Note: Not necessary to know how CPU works
EX: C, C++, JAVA, Visual basic, Python
Syntax
How key or reserved words are used
Compiler:
Translates high-level program into machine language for binary
Interpreter
Compiles and executes instructions (slower than compiler)
Source Code
Program in high-level language
Integrated Development Environment (IDE)
Has an editor, compiler, and debugging tools
Types of Software
1) System software: operating System: Windows/Mac OS/ Linux/ iOS
2) Application Software: Programs you run
26 MAR 2015
Design Programs
Program Development Cycle:
1) Design Program
2) Write Code
3) Correct Syntax Errors
4) Test Code
5) Debug Code
Pseudo code
Written in clear language
To display some string to the screen, use Display.
Ex) Display “Have a great day!”
Variables: Names (word) that represent memory addresses
Variable names:
Use a letter as the first character.
Must be one word
Note: If two words:
Can use underscore
Ex) pay_rate
Capitalize the second and all following words on.
Ex) payRate
Can’t do: pay rate
To Display value of variable:
Display variable_name
Ex) Display pay_rate
To Display string and variable
Use comma after closing quotes (and before next opening quote)
Ex) Display “the area of a circle with radius of”, radius (variable), “is”, area (variable), ”.”
To input a value (from user)
Input variable_name
Ex) Input name
To store a value in a variable:
Set variable_name= number
Ex) Set price= 5.00
Ex) Set pay= wage*hours
Note: Use order of operations: PEMDAS Ex) Set results = 15-2(7-4)/3 =15-2(3)/3 =15-6/3 =15-2 =13
For exponents, use ^(carrot)
Ex) 5^2= 52 = 25
Modulo (Modulus) Operations
Does division, returns remainder
Same order of operation as multiple/ divide
Ex) 6 Mod 5 6/5= remainder of 1
Ex) 14 Mod 4 14/4= remainder of 2
Flow charts
Graphically depicts steps in a program
Use Ovals for start and end:
Use parallelograms for Display and Input:
Use rectangles for the set statements:
Use Diamonds for decisions:
Ex) Design a program that asks user for # miles and # gallons used, and calculate miles per-gallon.
Pseudo code
1) Display “Enter number miles”
2) Input miles
3) Display “Enter number gallons”
4) Input gallons
5) Set mpg= miles/gallons
6) Display MPG (optional)
Ex) Make a flow chart out of this information.
02 Apr 2015
Declaring Variables
Need to declare a variable before using it
Need to indicate data type
Data Types:
1) Integer: 17, -4
2) Real (for decimals): 5.68, -2.4
3) String: “Hello”
In Pseudocode Use: Declare data_type variable_name Ex) Declare Integer grade Flow Chart: Use rectangle
Initialize Variables
Ex) Declare Integer grade= 0
Ex) Declare String name= “No Value” Data type compatibility
Need to match data types with values
Ex) Declare Integer grade = 95 (Good)
Ex) Declare Integer (needs to be Real) grade = 94.7 (not good)
Constants
Values do not change Use Constant instead of Declare
Ex) Constant Real Pi = 3.1415
Visual Basic
1) To display to screen use Console.write (“ ”) or Console.Writeline (“ ”) <- Cursor goes to next line Ex) Console.WriteLine (“Hi”) Console.WriteLine (“Bye”) Output: HI or Bye Ex) Console.Write (“Hi”) Console.Write (“Bye”) Output: HiBye
2) Declare variables:
Use: Dim variable_name As