240 likes | 388 Views
Intro to Programming. CST 200 - JavaScript. Objectives. Define software Identify the different types of software Differentiate the different types of programming languages – machine language, assembly language, high-level languages
E N D
Intro to Programming CST 200 - JavaScript
Objectives • Define software • Identify the different types of software • Differentiate the different types of programming languages – machine language, assembly language, high-level languages • Differentiate between procedure-oriented programs and object-oriented programs • Understand the three basic control structures: sequence, selection and repetition • Define an algorithm Intro to Programming
Software vs. Hardware • Every computer system combines softwareand hardware • Software is the collection of computer programs and related data that tells a computer what to do • Series of instructions • Hardware consists of the physical, electronic, mechanical components • Keyboard, mouse, monitor, memory, hard drive Intro to Programming
Types of Software • Two categories of software exist: • Application software describes computer programs that allow users to perform specific tasks • word processors, web browsers, email client • System software describes computer programs that operate and control the hardware connected to the computer • Operating systems, device drivers Intro to Programming
Programming • Computer programming is the art and science of specifying the set of instructions (programs) that tell the computer what to do • Computer programs are written in programming languages • Just as written languages define symbols and rules that enables humans to communicate, programming languages define symbols and rules that enable humans to communicate with computers Intro to Programming
Types of Programming Languages • Programming languages fall into different categories, based upon who (or what) is able to understand and execute it • Three categories are: • Machine language • Assembly language • High-level language Intro to Programming
Machine Language • Machine language (machine code) is the series of instructions that a computer (machine) directly understands • Binary language, consisting entirely of 0 and 1’s • Extremely difficult to program • Hardware-dependent: each family of CPU’s (Intel x86, AMD Athlon, etc.) has its own machine code • Example machine code: 000000 00001 00010 00110 00000 100000 Intro to Programming
Assembly Language • Assembly language is a more human-friendly programming language that uses mnemonics in place of 0’s and 1’s in a program • Still difficult to program • Still hardware-dependent • Assembly programs are converted to machine code through an assembler • Example assembly language code: SET r1, 10 STORE X, r1 Intro to Programming
High-Level Language • High-level languages allow programmers to write instructions that more closely resemble English language. • Much easier to learn and program • Hardware Independent: high-level programs can be compiled to run on many different computer platforms • Example high-level code: var age = 30; Intro to Programming
Types of High-Level Languages • High-level languages can be classified into different styles, based on how the language conceptualizes a computer program • Two main categories of high-level languages are • Procedure-Oriented Languages • Object-Oriented Languages Intro to Programming
Procedure-Oriented Programs • Procedure-oriented programs conceptualize a computer program as set of processes that call one another, each performing a series of sequential steps • In procedure-oriented programs, programmer focuses on the specific steps (or actions) the program must take to solve a task • Very linear, step-by-step Intro to Programming
Object-Oriented Programs • Object-oriented programs conceptualize a computer program as a series of objects that send messages and pass data amongst each other • In object-oriented programs, programmer focuses on the objects that interact to perform a task • Objects can be defined to represent real-world things Intro to Programming
JavaScript Programming Language • JavaScript is an Object-based, client-side web programming language • JavaScript is a high-level programming language • JavaScript is used in both a procedure-oriented and object-based way • Object-based, because it does not have all the features of an object-oriented language Intro to Programming
Control Structures • A computer program is a series of instructions that directs a computer to perform a task • When writing programs, programmers need ways to control the order that instructions execute • This order of instructions is called the control flow • All programming languages contain control structures to dictate the control flow of a program Intro to Programming
Control Structures • Every computer program uses one or more of the three basic control structures: sequence, selection and repetition • All three control structures are used by all of us every day in solving problems Intro to Programming
Control Structure: Sequence • In order for each of us to complete a task, we understand that we have to do things one step at a time, in a specific order • The sequence control structure directs a computer program to process the program instructions, one after the other, in the order listed on the program • Every program uses the sequence control structure Intro to Programming
Sequence Control Structure Example • Imagine we need a program to draw one red lollipop 1.set color to black 2.draw vertical line 3.set color to red 4.draw circle 5.color circle Intro to Programming
Control Structure: Repetition • In order for each of us to complete a task, we often have to repeat some part of the task over and over • The repetition control structure directs a computer program to repeatedly perform one or more action (loop) until some condition is met • Often represented with for, while or repeat-until loops Intro to Programming
Repetition Control Structure Example • Imagine we need a program to draw 30 red lollipops repeat 30 times: set color to black draw vertical line set color to red draw circle color circle Intro to Programming
Repetition Control Structure Example (2) • Imagine we need a program to eat a lollipop repeat until the lollipop is gone lick lollipop Each instance of the loop (repetition of the process) is called an iteration Note indentation Intro to Programming
Control Structure: Selection • In order for each of us to complete a task, we often have to have to make decisions • The selection control structure (also called decision structure) directs a computer program to make a decision, and then choose an action based on that decision • Often represented with if-then-else statements Intro to Programming
Selection Control Structure Example • Imagine we need a program to eat a lollipop and then display a message whether or not the lollipop was yummy or not repeat until the lollipop is gone lick lollipop if lollipop tastes yummy display lollipop is yummy else display lollipop is not yummy The decision is based on a condition that evaluates to true or false Intro to Programming
Algorithms • On the previous slides, the set of instructions that solved the problems are called algorithms • An algorithm is a set of step-by-step instructions that accomplish a task • The algorithms for all computer programs contain one or more of the sequence, repetition and selection control structures. Intro to Programming
In-Class Practice • Write an algorithm to perform the following tasks (a) Get dressed in the morning (b) Make a cup of tea (c) Cross the street Intro to Programming