Download presentation
Presentation is loading. Please wait.
1
COMP 110 Introduction to Programming Mr. Joshua Stough August 27, 2007 Monday/Wednesday/Friday 3:00-4:15 Gardner Hall 307
2
Announcements Registration – Today is last day to add – Tricia Robinson ( tmrobins@cs.unc.edu ) – HW 0 due today 11:59pm Please pay attention to what you are supposed to name the file. – Questions I responded to? Office hours: W F after class, and by appointment
3
Questions from Last Time Note announcements on Blackboard Slide links on the schedule. Schedule at http://cs.unc.edu/~stough/teaching/COMP110 -F07/schedule.html http://cs.unc.edu/~stough/teaching/COMP110 -F07/schedule.html Examples from the book are on the included disk and accessible through the schedule.
4
Questions from Last Time AFS: –http://help.unc.edu/643http://help.unc.edu/643 –http://help.unc.edu/?id=134http://help.unc.edu/?id=134 –Call help, 962-HELP
5
Last Time in COMP 110 Syllabus Honor Code Blackboard jGRASP Hello_World, SimpleIO_Demo Most of you bored is not the right ratio. Thank you for helping each other. Due today –Homework 0
6
Today in COMP 110 Parts of the computer –hardware vs. software –CPU and memory Binary numbers What is an algorithm? Book references: Chapter 1
7
Reading Check-Up 1.- computer components including the CPU, main memory, I/O devices, and secondary storage 2.- the brain of the computer, containing the CU, PC, IR, ALU, and ACC 3.- computer instructions to solve a problem 4.The digits 0 and 1 are called or the shortened term
8
Before Programming... You need a basic understanding of how a computer works –if you’re going to drive a car, you need to know that it runs on gasoline... Understanding the pieces will help you understand what your programs actually do Plus, we want you to be able to talk intelligently about computers
9
Hardware vs. Software A computer is made up of hardware and software Hardware Software CPU - ex: 1.8 GHz Core 2 Duo input/output - keyboard - 15.4” wide screen LCD - network card main memory - ex: 2 GB RAM secondary memory - ex: 160 GB hard drive operating systems - Windows XP - Mac OS X applications - games - Microsoft Word - Mozilla Firefox
10
Hardware Organization motherboard CPU memory hard drive
11
Central Processing Unit CPU 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
12
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
13
Main Memory With 100 Cells Each memory cell has a numeric address, which uniquely identifies it
14
CPU and Main Memory Chip that executes program instructions Primary storage area for programs and data that are in active use (RAM) All programs must be brought into main memory before execution
15
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, DVDs –Tapes
16
Secondary Storage Secondary memory devices provide long-term storage Information is moved between main memory and secondary memory as needed
17
Input Devices Definition: devices that feed data and computer programs into computers Examples: –Keyboard –Mouse –Secondary Storage
18
Output Devices Definition: devices that the computer uses to display results Examples: –Printer –Monitor –Secondary Storage
19
Input/Output Devices I/O devices facilitate user interaction
20
Hardware Components
21
Opening Notepad Use the mouse to select Notepad The CPU requests the Notepad application Notepad is loaded from the hard drive to main memory The CPU reads instructions from main memory and executes them one at a time Notepad is displayed on your monitor
22
Questions 1. - points to the next instruction to be executed 2. - a unique location in memory 3. - stores information permanently 4.Instructions executed by the CPU must be first loaded from
23
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 Vista/XP, Linux, Mac OS X Application –generic term for any other kind of software –examples: word processors, missile control systems, games
24
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
25
Application Programs Written using programming languages Perform a specific task Run by the OS Example programs: –Word Processors –Spreadsheets –Games
26
Questions Classify the following pieces of software as operating system or application: 1. Microsoft Windows 2000 2. Microsoft PowerPoint 3. Linux 4. Your COMP 14 programs
27
It’s All About Data Software is data –numbers, characters –instructions, programs Hardware stores and processes data –read, write –add, subtract, multiply, divide
28
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
29
H i, H e a t h e r. 72 105 44 32 72 101 97 116 104 101 114 46 Representing Text Digitally All information in a computer is digitized, broken down and represented as numbers. Corresponding upper and lower case letters are separate characters.
30
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?
31
1 bit 0101 2 bits 00 01 10 11 3 bits 000 001 010 011 100 101 110 111 4 bits 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Each additional bit doubles the number of possible permutations Bit Permutations
32
2 1 = 2 items 2 2 = 4 items 2 3 = 8 items 2 4 = 16 items 2 5 = 32 items 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 2 N permutations of N bits –N bits are needed to represent 2 N unique items
33
Binary Numbers N bits to represent 2 N values N bits represent values 0 to 2 N -1 Example: 5 bits –32 unique values (0-31) –00000 = 0 –11111 = 31 2 4 2 3 2 2 2 1 2 0 16 + 8 + 4 + 2 + 1
34
Decimal to Binary 114 1110010 NumberPlace ValueDigit 1142 6 = 641 502 5 = 321 182 4 = 161 22 3 = 80 22 2 = 40 22 1 = 21 02 0 = 20
35
Questions Binary 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
36
KB2 10 = 1024 MB2 20 (over 1 million) GB2 30 (over 1 billion) TB2 40 (over 1 trillion) UnitSymbolNumber of Bytes kilobyte megabyte gigabyte terabyte Storage Capacity Every memory device has a storage capacity, indicating the number of bytes (8 bits) it can hold Various units:
37
Programming Languages Evolution Early computer programmers 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
38
Assembly and Machine Language
39
Programming Languages Evolution High-level languages make programming easier Closer to spoken languages Examples: –Basic –FORTRAN –COBOL –C/C++ –Java
40
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
41
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
42
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
43
Problem-Analysis-Coding-Execution most important step without computer with computer
44
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
45
Resulting Algorithm 1. Get the change in cents 2. Find the number of half-dollars 3. Calculate the remaining change 4. Find the number of quarters 5. Calculate the remaining change 6. Find the number of dimes 7. Calculate the remaining change 8. Find the number of nickels 9. Calculate the remaining change 10. The remaining change is the number of pennies.
46
6 Fundamental Concepts of Programming Variables, and Assignment (data storage) Expressions, and Data Retrieval Conditional statements (making choices) Loops (repetition) Structured data, arrays (data abstraction) Functions (procedural abstraction)
47
Program 1 and Homework 1 Smith Center Banners –posted on Blackboard Book problems: Ch.1 and first part of Ch. 2. –Put some format into the notepad file please. Make sure program compiles and runs Due Wednesday 5 th at 11:59pm
48
What’s Ahead... Java Basics Reading: Ch 2 (pgs. 21-37) Program 1 due on Wednesday, 5 th Homework 1 due on Wednesday, 5 th
49
Remember Follow instructions in the assignment. Follow the file naming format. Jar your code files.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.