24
Intro to Programming CST 200 - JavaScript

Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Embed Size (px)

Citation preview

Page 1: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming

CST 200 - JavaScript

Page 2: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 2

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

Page 3: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 3

Software vs. Hardware

• Every computer system combines software and 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

Page 4: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 4

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

Page 5: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 5

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

Page 6: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 6

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

Page 7: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 7

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

Page 8: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 8

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, 10STORE X, r1

Page 9: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 9

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;

Page 10: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 10

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

Page 11: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 11

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

Page 12: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 12

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

Page 13: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 13

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

Page 14: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 14

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

Page 15: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 15

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

Page 16: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 16

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

Page 17: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 17

Sequence Control Structure Example

• Imagine we need a program to draw one red lollipop

1.set color to black2.draw vertical line3.set color to red4.draw circle5.color circle

Page 18: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 18

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

Page 19: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 19

Repetition Control Structure Example

• Imagine we need a program to draw 30 red lollipops

repeat 30 times:set color to blackdraw vertical lineset color to reddraw circlecolor circle

Page 20: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 20

Repetition Control Structure Example (2)

• Imagine we need a program to eat a lollipop

repeat until the lollipop is gonelick lollipop

Each instance of the loop (repetition of the process) is called an iteration

Note indentation

Page 21: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 21

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

Page 22: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 22

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 gonelick lollipop

if lollipop tastes yummydisplay lollipop is yummy

elsedisplay lollipop is not yummy

The decision is based on a condition that evaluates to true or false

Page 23: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 23

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.

Page 24: Intro to Programming CST 200 - JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming

Intro to Programming 24

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