Comp 14 introduction to programming
Download
1 / 44

COMP 14 Introduction to Programming - PowerPoint PPT Presentation


  • 121 Views
  • Updated On :

COMP 14 Introduction to Programming. Miguel A. Otaduy May 12, 2004. …from Last Time. Homework 1 due Tomorrow Fill in form with personal info Getting started with jGRASP Compile and Run test programs Any problems? Disable test for new versions. Today (ch. 1). Parts of the computer

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'COMP 14 Introduction to Programming' - gaerwn


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Comp 14 introduction to programming l.jpg

COMP 14Introduction to Programming

Miguel A. Otaduy

May 12, 2004


From last time l.jpg
…from Last Time

  • Homework 1 due Tomorrow

    • Fill in form with personal info

    • Getting started with jGRASP

    • Compile and Run test programs

    • Any problems?

    • Disable test for new versions


Today ch 1 l.jpg
Today (ch. 1)

  • Parts of the computer

    • hardware vs. software

    • CPU and memory

  • Binary numbers

  • What is an algorithm?


Reading check up l.jpg
Reading Check-Up

hardware

  • - computer components including the CPU, main memory, I/O devices, and secondary storage

  • - the brain of the computer, containing the CU, PC, IR, ALU, and ACC

  • - computer instructions to solve a problem

  • The digits 0 and 1 are called

    or the shortened term

CPU

program

binary digits

bits


Hardware vs software l.jpg
Hardware vs. Software

A computer is made up of hardware and software

Software

Hardware

  • CPU

    • ex: 1 GHz Pentium III

  • input/output

    • keyboard

    • monitor

    • network card

  • main memory

    • ex: 256 MB RAM

  • secondary memory

    • ex: 20 GB hard drive

  • operating systems

    • Windows XP

    • Mac OS X

  • applications

    • games

    • Microsoft Word

    • Internet Explorer


Hardware organization l.jpg
Hardware Organization

CPU

memory

motherboard

hard drive


Central processing unit cpu l.jpg
Central Processing UnitCPU

  • Control Unit (CU)

    • "the brain" of the CPU

  • Program Counter (PC)

    • points to the next instruction to be executed

  • Instruction Register (IR)

    • holds the currently executing instruction

  • Arithmetic Logic Unit (ALU)

    • carries out all arithmetic and logical ops

  • Accumulator (ACC)

    • holds the results of the operations performed by the ALU


Main memory l.jpg
Main Memory

  • Ordered sequence of cells

  • AKA Random Access Memory (RAM)

  • Directly connected to the CPU

  • All programs must be brought into main memory before execution

  • When power is turned off, everything in main memory is lost


Main memory with 100 cells l.jpg
Main MemoryWith 100 Cells

Each memory cell has a numeric address, which uniquely identifies it


Cpu and main memory l.jpg
CPU and Main Memory

All programs must be brought into main memory before execution

Chip that executes

program instructions

(processor)

Primary storage area

for programs and data

that are in active use

(RAM)


Secondary storage l.jpg
Secondary Storage

  • Provides permanent storage for information

  • Retains information even when power is off

  • Examples of secondary storage:

    • Hard Disks

    • Floppy Disks

    • ZIP Disks

    • CD-ROMs

    • Tapes


Secondary storage12 l.jpg
Secondary Storage

Secondary memory

devices provide

long-term storage

Information is moved

between main memory

and secondary memory

as needed


Input devices l.jpg
Input Devices

  • Definition: devices that feed data and computer programs into computers

  • Examples:

    • Keyboard

    • Mouse

    • Secondary Storage


Output devices l.jpg
Output Devices

  • Definition: devices that the computer uses to display results

  • Examples:

    • Printer

    • Monitor

    • Secondary Storage


Input output devices l.jpg
Input/Output Devices

I/O devices facilitateuser interaction



Opening ms word l.jpg
Opening MS Word

  • Use the mouse to select MS Word

  • The CPU requests the MS Word application

  • MS Word is loaded from the hard drive to main memory

  • The CPU reads instructions from main memory and executes them one at a time

  • MS Word is displayed on your monitor


Questions l.jpg
Questions

  • - points to the next instruction to be executed

  • - a unique location in memory

  • - stores information permanently

  • Instructions executed by the CPU must be first loaded to

program counter (PC)

address

secondary storage

main memory


Software categories l.jpg
Software Categories

  • Operating System

    • controls all machine activities

    • provides the user interface to the computer

    • first program to load when a computer is turned on

    • manages computer resources, such as the CPU, memory, and hard drive

    • examples: Windows XP, Linux, Mac OS X

  • Application

    • generic term for any other kind of software

    • examples: word processors, missile control systems, games


Operating system os l.jpg
Operating System (OS)

  • OS monitors overall activity of the computer and provides services

  • Written using programming language

  • Example services:

    • memory management

    • input/output

    • storage management


Application programs l.jpg
Application Programs

  • Written using programming languages

  • Perform a specific task

  • Run by the OS

  • Example programs:

    • Word Processors

    • Spreadsheets

    • Games


Questions22 l.jpg
Questions

Classify the following pieces of software as operating system or application:

  • Microsoft Windows 2000

  • Microsoft PowerPoint

  • Linux

  • Your COMP 14 programs

OS

app

OS

app


It s all about data l.jpg
It’s All About Data

  • Software is data

    • numbers, characters

    • instructions, programs

  • Hardware stores and processes data

    • read, write

    • add, subtract, multiply, divide


Analog vs digital l.jpg
Analog vs. Digital

  • Analog

    • continuous wave forms

    • ex: sound, music on an audio tape

  • Digital

    • the information is broken down into pieces, and each piece is represented separately

    • represented as series of 0 and 1

      • 0 - low voltage

      • 1 - high voltage

    • can be copied exactly

    • ex: music on a compact disc


Representing text digitally l.jpg
Representing Text Digitally

  • All information in a computer is digitized, broken down and represented as numbers.

H i , H e a t h e r .

72 105 44 32 72 101 97 116 104 101 114 46

Corresponding upper and lower case letters are separate characters.


Language of a computer l.jpg
Language of a Computer

  • Machine language: the most basic language of a computer

  • A sequence of 0s and 1s

    • binary digit, or bit

    • sequence of 8 bits is called a byte

  • Every computer directly understands its own machine language

    • why can't Windows programs run on Apple computers?


Bit permutations l.jpg

1 bit

2 bits

3 bits

4 bits

0

1

00

01

10

11

000

001

010

011

100

101

110

111

0000

0001

0010

0011

0100

0101

0110

0111

1000

1001

1010

1011

1100

1101

1110

1111

Bit Permutations

Each additional bit doubles the number of possible permutations


Bit permutations28 l.jpg

1 bit ?

2 bits ?

3 bits ?

4 bits ?

5 bits ?

How many

items can be

represented by

Bit Permutations

  • Each permutation can represent a particular item

  • There are 2N permutations of N bits

    • N bits are needed to represent 2N unique items

21 = 2 items

22 = 4 items

23 = 8 items

24 = 16 items

25 = 32 items


Binary numbers l.jpg
Binary Numbers

  • N bits to represent 2N values

  • N bits represent values 0 to 2N-1

  • Example: 5 bits

    • 32 unique values (0-31)

    • 00000 = 0

    • 11111 = 31

24 23 22 21 20

16 + 8 + 4 + 2 + 1


Decimal to binary l.jpg
Decimal to Binary

114

1110010

Place Digit Value

26 1 64

25 1 32

24 1 16

23 0 0

22 0 0

21 1 2

20 0 0


Questions binary numbers l.jpg
QuestionsBinary Numbers

  • What’s the maximum value a 6-bit number can represent?

  • What’s the decimal representation of 111010?

  • What’s the binary representation of 35?

63

58 = 32+16+8+2

100011


Storage capacity l.jpg
Storage Capacity

  • Every memory device has a storage capacity, indicating the number of bytes (8 bits) it can hold

  • Various units:

Unit Symbol Number of Bytes

KB 210 = 1024

kilobyte

megabyte

gigabyte

terabyte

MB 220 (over 1 million)

GB 230 (over 1 billion)

TB 240 (over 1 trillion)


Programming languages evolution l.jpg
Programming LanguagesEvolution

  • Early computers programmed in machine language (only 0s and 1s)

  • Assembly languages were developed to make programmer’s job easier

  • Assembler: translates assembly language instructions into machine language



Programming languages evolution35 l.jpg
Programming LanguagesEvolution

  • High-level languagesmake programming easier

  • Closer to spoken languages

  • Examples:

    • Basic

    • FORTRAN

    • COBOL

    • C/C++

    • Java


From java to machine language l.jpg
From Java to Machine Language

  • Computers understand only 0 and 1 (machine language)

  • Compiler translates source code into machine code

  • Java compiler translates source code (file ending in .java) into bytecode (file ending in .class)

    • bytecode is portable (not machine-specific)

  • Java interpreter reads and executes bytecode

    • different Java interpreters for different types of CPUs and operating systems (OS)

      • Intel/Windows, Motorola/Mac OS X, Intel/Linux


Problem solving l.jpg
Problem Solving

  • The purpose of writing a program is to solve a problem

  • The general steps in problem solving are:

    • understand the problem

    • dissect the problem into manageable pieces

    • design a solution

    • consider alternatives to the solution and refine it

    • implement the solution

    • test the solution and fix any problems that exist


Algorithm l.jpg
Algorithm

  • Sequence of instructions used to carry out a task or solve a problem

  • May be written in either English or pseudocode

    • outline of a program that could be translated into actual code

  • May need refinement as you work

    Always write out your algorithm before you begin programming


Problem analysis coding execution l.jpg
Problem-Analysis-Coding-Execution

most important step

without

computer

with

computer


Algorithm design example l.jpg
Algorithm Design Example

Problem: Convert change in cents to number of half-dollars, quarters, dimes, nickels, and pennies to be returned.

Example:

  • given 646 cents

  • number of half-dollars: divide 646 by 50

    • quotient is 12 (number of half-dollars)

    • remainder is 46 (change left over)

  • number of quarters: divide 46 by 25

    • quotient is 1 (number of quarters)

    • remainder is 21 (change left over)

  • number of dimes, nickels, pennies

  • result: 12 half-dollars, 1 quarter, 2 dimes, 0 nickels, 1 penny


Resulting algorithm l.jpg
Resulting Algorithm

  • Get the change in cents

  • Find the number of half-dollars

  • Calculate the remaining change

  • Find the number of quarters

  • Calculate the remaining change

  • Find the number of dimes

  • Calculate the remaining change

  • Find the number of nickels

  • Calculate the remaining change

  • The remaining change is the number of pennies.


Exercise l.jpg
Exercise

  • Execution of c=2*a+b in a computer


To do l.jpg
To do

  • Read ch. 2

  • Exercises 10 & 11 in ch. 1 (algorithm design)


What s ahead l.jpg
What’s Ahead...

  • Java Basics

  • Homework 1 due tomorrow

  • Homework 2 assigned tomorrow

  • Quiz Friday: computers and Java basics


ad