17
CISC 110 Day 1 Hardware, Algorithms, and Programming

CISC 110 Day 1 Hardware, Algorithms, and Programming

Embed Size (px)

Citation preview

Page 1: CISC 110 Day 1 Hardware, Algorithms, and Programming

CISC 110Day 1

Hardware, Algorithms, and Programming

Page 2: CISC 110 Day 1 Hardware, Algorithms, and Programming

Outline

• Structure of Digital Computers

• Programming Concepts

• Output Statements

• Variables and Assignment Statements

• Data Types

• String and Numeric Operations

2

Page 3: CISC 110 Day 1 Hardware, Algorithms, and Programming

Structure of Digital Computers I/O DevicesInput/Output Devices: (e.g. Keyboard, Mouse, Webcam)

Communication between the computer and the user, and with other computers

Secondary StorageLong-term memory of data and programs (e.g. hard drive)

3

CPU(Central Processing Unit):

Calculations and the Fetch-Execute Cycle

CPU(Central Processing Unit):

Calculations and the Fetch-Execute Cycle

Main MemoryRAM (Random Access Memory):

Short-term memory of data and programs, while computer is powered on

Main MemoryRAM (Random Access Memory):

Short-term memory of data and programs, while computer is powered on

Page 4: CISC 110 Day 1 Hardware, Algorithms, and Programming

Main Memory (RAM)

11110000101011001101101000110101010000011010101001011101000000001111111111100010101101010001101101001111

byte 3025 byte 3026 byte 3027 byte 3028 byte 3029 byte 3030 byte 3031 byte 3032 byte 3033

byte 3021 byte 3022 byte 3023 byte 3024

2 byte memory location at address 3021: could hold a 16-bit integer

4 byte memory location at address 3024: could hold a 32-bit integer

1 byte memory location at address 3030: could hold one letter

4

Page 5: CISC 110 Day 1 Hardware, Algorithms, and Programming

Memory Sizes

Memory Conversion

1 bit

1 nybble 4 bits

Either 1 or 0

1 kilobyte

1 byte

210 bytes (approx. 1000 bytes)

8 bits

1 terabyte

1 gigabyte

1 megabyte 220 bytes (approx. 1000 kilobytes)

230 bytes (approx. 1000 megabytes)

240 bytes (approx. 1000 gigabytes)

5

Page 6: CISC 110 Day 1 Hardware, Algorithms, and Programming

Computers: A Definition

Computers are machines that can carry out routine mental tasks by performing simple operations at high speeds (operations built into the hardware: machine operations).

6

Page 7: CISC 110 Day 1 Hardware, Algorithms, and Programming

A Definition of an Algorithm

An algorithm is a sequence of instructions that describes how to carry out a task.

7

Page 8: CISC 110 Day 1 Hardware, Algorithms, and Programming

A Mathematically Precise Definition of an Algorithm

An algorithm is a finite sequence of unambiguous, executable instructions for carrying out a task or process in a finite amount of time.

Note: This assumes no intelligence on the part of the user. The intelligence and knowledge of a person is encoded in the algorithm. 8

Page 9: CISC 110 Day 1 Hardware, Algorithms, and Programming

A Definition of a Programming Language

A programming language consists of a repertoire of possible instructions, each of which can be specified in terms of the simple operations (machine operations) a computer can execute.

9

Page 10: CISC 110 Day 1 Hardware, Algorithms, and Programming

Cake-making & Computation

Electronic Computer

Oven & Utensils

(Hardware)

Bit String: Numbers or Characters

Cake Ingredients

(Input)

Bit String: Numbers or Characters

Cake

(Output) 10

Program/Software

Recipe

(Algorithm)

Page 11: CISC 110 Day 1 Hardware, Algorithms, and Programming

A Definition of a Scripting Language

A scripting language is a programming language that allows control of an application, for instance an animation.

The name script is derived from the written script of the performing arts, which tells the actors what to say.

11

Page 12: CISC 110 Day 1 Hardware, Algorithms, and Programming

ActionScript Trace()

Purpose: To display values in the output panel to trace the state of an animation

Examples:trace( 525 );

trace ( “Now starting love scene” );

trace ( “Row ” + 5 + “Col ” + 7 );

trace ( 5 + 7 );

trace ( “5 + 7 = ” + 5 + 7 ); 12

Page 13: CISC 110 Day 1 Hardware, Algorithms, and Programming

Defining Variables to Store Values

Memory:

rowvar row = 5;

row = 8;

var next = row + 1;

next = next + 1;

var s = “hi”;

var val = 3.5;

ActionScript:

val

s

next

13

Page 14: CISC 110 Day 1 Hardware, Algorithms, and Programming

Data Typing Variables ActionScript:

var row: int = 5;

row = 8;

var next: int = row + 1;

next = next + 1;

var s: String = “hi”;

var val: Number = 3.5; 14

Page 15: CISC 110 Day 1 Hardware, Algorithms, and Programming

String Operations

Operators: + Concatenation+= Append

Escape Sequences:\n New Line\t Tab\’ Single Quote\” Double Quote\\ Backslash

Examples:

trace( “Hey” + “you” );

trace( “Hey\nyou” );

trace( “Hey\tyou” );

trace( “Hey\”you\”” );

15

Page 16: CISC 110 Day 1 Hardware, Algorithms, and Programming

Arithmetic Operations

Operators:

+ Addition

- Subtraction

* Multiplication

/ Integer Division

% Mod

(integer remainder of division)

16

Page 17: CISC 110 Day 1 Hardware, Algorithms, and Programming

Imperative ProgrammingStatements:

Variable Assignment (=)

Branching (if, else)

Loops (while, for)

Data Structures:Integers

Strings

Arrays

Classes

Functions17