Download Understanding Computers: Hardware, Software, and Programming - Prof. Ahmed Emam and more Study notes Computer Science in PDF only on Docsity! 1/27/2009 1 INTRODUCTION TO PROGRAMMING (CS230) – SPRING 09 Ahmed Emam
[email protected] What Is a Computer? • Computer • Device capable of performing computations and making logical decisions • Computer programs • Sets of instructions that control computer’s processing of data • Written by people called computer programmers • Hardware • Various devices comprising computer • Keyboard, screen, mouse, disks, memory, CD-ROM, processing units, etc. 1/27/2009 2 COMPUTER ORGANIZATION Six logical units of computer 1. Input unit : Keyboard, mouse, microphone, scanner, networks, etc. 2. Output unit : Screen, printer, networks, control other devices 3. Memory unit : Immediately available for processing (RAM and ROM) 4. Arithmetic and logic unit (ALU) : Performs arithmetic calculations and logic decisions 5. Central processing unit (CPU) : “Administrative” section to coordinates and supervises other sections of computer 6. Secondary storage unit : Stores inactive programs or data ( Hard drives, CDs, DVDs ) OPERATING SYSTEMS • Personal computers : Popularized in 1977 by Apple Computer and Legitimized in 1981 by IBM Personal Computer (XT, AT, 386, 486, 586) • Operating systems : Software systems that manage transitions between jobs to increased throughput (amount of work computers can process) UNIX Li M OS X d Mi ft’• , nux, ac an croso s Window-based systems support these capabilities 1/27/2009 5 FORTRAN, COBOL, Pascal & Ada • FORmula TRANslator (FORTRAN ) :Used in engineering applications • COmmon Business Oriented Language (COBOL ) Used in business software • Pascal :Designed to teach structured programming • Ada : Capable of multitasking Java • Designed by Sun Microsystems • Originally for intelligent consumer-electronic devices • Then used for creating Web pages with dynamic content • Now also used for: • Develop large-scale enterprise applications • Enhance World Wide Web server functionality • Provide applications for consumer devices (cell phones, etc.) 1/27/2009 6 Basic, Visual Basic, Visual C++, C# and .NET • Beginner’s All-Purpose Symbolic I t ti C d (BASIC)ns ruc on o e : Familiarize novices with programming techniques • .NET platform : Provides developers with capabilities • Visual Basic .NET :Based on BASIC • Visual C++ : Based on C++ • C# :Based on C++ and Java Computers and Complicated Tasks 1. Tasks are broken down into instructions that can be expressed by a computer language 2. A program is a sequence of instructions 3. Programs can be only a few instructions or millions of lines of instructions 1/27/2009 7 All Programs Have in Common: • Take data and manipulate it to produce a result • Input – Process – Output • Input – from files, the keyboard, or other input device • Output – to the monitor printer file or , , , other output device Programmer and User • Programmer : the person who solves the problem and writes the instructions for the comp ter u • User : any person who uses the program written by the programmer • Problem Solving is the developing the solution to a problem • Algorithm : a step by step series of instructions to solve a problem 1/27/2009 10 Windows and Its Little Windows • Difference between Windows and windows. • Title bar indicates if window is active. Mouse Actions: 1. Hover 2. Drag and drop 3. Click 4. Right-click 5. Double-Click 1/27/2009 11 Files and Folders File: holds programs or data. Its name usually consists of letters, digits, and spaces. Folder: contains files and other folders (called subfolders). Key Terms in using Folders and Files Term Example • Disk Hard disk, CD • File name PAYROLL • Extension .TXT • Filename PAYROLL.TXT • Path TextFiles\PAYROLL.TXT • Filespec C:\TextFiles\PAYROLL.TXT 1/27/2009 12 Windows Explorer • Used to view, organize and manage folders and files. • Manage: copy, move, delete • To invoke Windows Explorer • Right-click on Windows Start button • Click on Explore in context menu Display File Extensions • In XP • Alt/Tools/Folder Options • Click the View tab. • Uncheck "Hide extensions for known file types“. • Click OK. • In Vista • Click on Windows Start button. T F ld O i i S h b• ype o er pt ons nto earc ox. • Press Enter key. • Click on View tab in dialog box. • Uncheck ″Hide extensions for known file types″. • Click OK. 1/27/2009 15 Program Development Cycle 1. Analyze: Define the problem. 2. Design: Plan the solution to the problem. 3 Choose the interface: Select the objects (text. boxes, buttons, etc.) 4. Code: Translate the algorithm into a programming language. 5. Test and debug: Locate and remove any errors in the program. 6. Complete the documentation: Organize all the materials that describe the program. Programming Tools 1. Flowcharts 2 Pseudocode. 3. Hierarchy Chart 4. Direction of Numbered NYC Streets Algorithm 5. Class Average Algorithm 1/27/2009 16 Programming Tools • Three tools are used to convert algorithms into computer programs: • Flowchart : Graphically depicts the logical steps to carry out a task and shows how the steps relate to each other. • Pseudocode : Uses English-like phrases with some Visual Basic terms to outline the program. • Hierarchy chart : Shows how the different parts of a program relate to each other. Problem solving example • How many stamps do you use when mailing a letter? • One rule of thumb is to use one stamp for every five sheets of paper or fraction thereof. 1/27/2009 17 Stamps Algorithm Algorithm is a step by step series of instructions for solving a problem (a recipe is an example of an algorithm) 1.Request the number of sheets of paper; call it Sheets. (input) 2.Divide Sheets by 5. (processing) 3 Round the quotient up to the next highest. whole number; call it Stamps. (processing) 4.Reply with the number Stamps. (output) Flowcharts • Graphically depict the logical steps to carry out a task and show how the steps relate to each other. 1/27/2009 20 Hierarchy charts example Divide-and-conquer method • Used in problem solving – take a large problem and break it into smaller problems solving the small ones first • Breaks a problem down into modules 1/27/2009 21 Statement structures • Sequence : follow instructions from one line to the next without skipping over any lines • Decision : if the answer to a question is “Yes” then one group of instructions is executed. If the answer is “No,” then another is executed • Looping : a series of instructions are executed over and over Sequence flow chart 1/27/2009
Is
condition
true?
f condition is true Then
Process step(s) 1 Process Process
Else
step(s) 2 step(s) 1
Process step(s) 2 068) a6)
nd If
Is
condition
true?
Deo While condition is true
Process step(s)
OOP
Process
step(s)
Ld
22
1/27/2009 25 Class Average Algorithm • Problem: Calculate and report the grade- point average for a class h d l h• Discussion: T e average gra e equa s t e sum of all grades divided by the number of students • Output: Average grade I t St d t d• npu : u en gra es • Processing: Find the sum of the grades; count the number of students; calculate average Flowchart 1/27/2009 26 Pseudocode Program: Determine the average grade of a class I iti li C t d S t 0n a ze oun er an um o Do While there are more data Get the next Grade Add the Grade to the Sum CIncrement the ounter Loop Computer Average = Sum / Counter Display Average Hierarchy Chart 1/27/2009 27 Comments • When tracing a flowchart, start at the start symbol and follow the flow lines to the end symbol • Testing an algorithm at the flowchart stage is known as desk checking • Flowcharts, pseudocode, and hierarchy charts are program planning tools that are not dependent on the programming language being used Comments continued • There are four primary logical programming constructs • sequence • decision • loop • unconditional branch