CS 101 Programming Programming Programming is creating the

  • Slides: 16
Download presentation
CS 101 Programming

CS 101 Programming

Programming • Programming is creating the instructions the computer will follow to accomplish a

Programming • Programming is creating the instructions the computer will follow to accomplish a task. – Augusta Ada King, Countess of Lovelace (10 December 1815 – 27 November 1852)

Congratulations, you are a programmer!

Congratulations, you are a programmer!

How do we write instructions for non computer tasks? • We usually use normal

How do we write instructions for non computer tasks? • We usually use normal human language in a step by step manner. For example: – – –. 1 Turn to your left 2 Take 5 steps 3 Go to whiteboard 4 Pick up pen 5 Write President’s name on board Etc.

What type of instructions do computers need? • Very detailed and in binary (also

What type of instructions do computers need? • Very detailed and in binary (also called Machine Language) 00000100000110100001100111000111000000111010101010000101100111110110001011011100100 0000101001010001011100101000010101111101000000111 110101010110000110010110011100000011101 0101011101010101000010110011111011000101101110 0100000010100101000101110010100001010111110100000 011111010101011000011001011001110000001 110101010101010100001011001111101100010110 1110010000001010010100010111001010000101011111010 000001111101010101100001100101100111000 0001110101010101010000101100111110110001 0110111001000000101001010001011100101000010101111 101000000111110101010110000110010110011100011 1000000111010101010101000010110011111011 0001011011100100000010100101000101110010100001010 11111010000001111101010

Program Languages are for humans! 1. We create instructions using a programming language. For

Program Languages are for humans! 1. We create instructions using a programming language. For example the below Python code for altering the color of a picture : – – – – def make. Sunset 2(picture): reduce. Green 30 Percent(picture) reduce. Blue 30 Percent(picture) – – def reduce. Blue 30 Percent(picture): for p in get. Pixels(picture): value = get. Blue(p) set. Blue(p, value*0. 7) def reduce. Green 30 Percent(picture): for p in get. Pixels(picture): value = get. Green(p) set. Green(p, value*0. 7) 2. > then> Another program (compiler or interpreter) turns the Python code into the binary code the computer can run: 10101100001100101100111000111 000000111010101010101 00001011001111101100010110111001 0000001010010100010111001 01000010101111101000000111110101011000011001011001110001 11000000111010101010101 01000010110011111011000101101110 0100000010100101000101110 010100001010111110100000011111010110000110010110011100000011101010101010000101100111110110001011011 1001000000101001010001011 10010100001010111110100000011111010100100

To hard to write binary instructions so instead we use programming languages • John

To hard to write binary instructions so instead we use programming languages • John Backus created the first programming language, FORTRAN, at IBM in 1957 • Programmers write instructions for computers using a programming language. • After we write the instructions in a program language another program then turns the instructions into the machine language the computers needs. Admiral Grace Hopper

Many Types of Program Languages • Low Level Languages – Machine Languages (1 GL)

Many Types of Program Languages • Low Level Languages – Machine Languages (1 GL) – Assembly Languages (2 GL) • High Level Languages – Procedural Languages (3 GL) – Task Oriented Languages (4 GL) – Problem Constraint Languages (5 GL) • (Someday) Natural Languages • “Star Trek”

“Hello World” Program Written In A 1 st Generation Machine Language 1010110000110010110011100000011101011101 010101010000101100111110110001011011100100000 0101001010001011100101000010101111101000000111

“Hello World” Program Written In A 1 st Generation Machine Language 1010110000110010110011100000011101011101 010101010000101100111110110001011011100100000 0101001010001011100101000010101111101000000111 110101010110000110010110011100000011 101011101010101000010110011111011000101 1011100100000010100101000101110010100001010111 1101000000111110101010110000110010110011100000011101010101010100001011001 1111011000101101110010000001010010100010111001 01000010101111101000000111110101010110000110100001 100101100111000000111010101010101000010110011111011000101101110010000001010010100 0101110010100001010111110100000011111010101011 000011010000110011100011100000011101010101

“Hello World” Program Written In A 2 nd Generation Assembly Language. HW: stringz "Hello

“Hello World” Program Written In A 2 nd Generation Assembly Language. HW: stringz "Hello World". text. align 16. global main#. proc main# main: . prologue 14, 32. save ar. pfs, r 33 alloc r 33 = ar. pfs, 0, 4, 1, 0. vframe r 34 mov r 34 = r 12 adds r 12 = -16, r 12 mov r 35 = r 1. save rp, r 32 mov r 32 = b 0. body addl r 14 = @ltoffx(. HW), r 1 ; ; ld 8. mov r 14 = [r 14], . HW ; ; st 8 [r 34] = r 14 ld 8 r 36 = [r 34] br. call. sptk. many b 0 = puts# mov r 1 = r 35 ; ;

“Hello World” Program Written In The 3 rd Generation Language C++ // Hello World

“Hello World” Program Written In The 3 rd Generation Language C++ // Hello World in C++ (pre-ISO) #include <iostream. h> main() { cout << "Hello World!" << endl; return 0; }

“Hello World” Program Written In The 4 th Generation Language Python print("Hello World")

“Hello World” Program Written In The 4 th Generation Language Python print("Hello World")

Someday “Star Trek” https: //www. youtube. com/watch? v=5 Lgw. AD-Iio. Y

Someday “Star Trek” https: //www. youtube. com/watch? v=5 Lgw. AD-Iio. Y

Hello World In Other Program Languages • http: //helloworldcollection. de

Hello World In Other Program Languages • http: //helloworldcollection. de

Nice Intro to Programing Dataquest code. org is a nice way to get an

Nice Intro to Programing Dataquest code. org is a nice way to get an introduction to programming

How to create a program • 1 Program Specification – Define the problem •

How to create a program • 1 Program Specification – Define the problem • 2 Program Design – Create an algorithm • Can use: – – – Top-Down Design OOP (Object Oriented Design) Logic Structures Flow Charts Etc. • Create Pseudocode • • 3 Program Code 4 Program Test 5 Program Documentation 6 Program Maintenance