Computers & Programming PDF
Document Details
Uploaded by RetractableLapSteelGuitar
Tags
Summary
This document provides a basic overview of computer systems and programming. It covers topics like simple program logic, steps in program development, and different programming models. Includes details on hardware and software.
Full Transcript
# Computers & Programming ## In this Lecture, you will learn about: * Computer systems * Simple program logic * The steps involved in the program development cycle * Pseudocode statements and flowchart symbols * Using a sentinel value to end a program * Programming and user en...
# Computers & Programming ## In this Lecture, you will learn about: * Computer systems * Simple program logic * The steps involved in the program development cycle * Pseudocode statements and flowchart symbols * Using a sentinel value to end a program * Programming and user environments * The evolution of programming models * Declaring and Using Variables * Arithmetic Operations * Routine Components in Programs * Loops, if-then-else * Counter, accumulator, indicators * Program Design * Programming & user environments * C++ program ## Computers & Programming Every computer system is composed of multiple pieces of hardware and software. * **Hardware** is the equipment, or the physical devices: * For example: Keyboards, mice, speakers, CPU * **Software** is computer instructions that tell the hardware what to do. * Software is programs, which are instruction sets written by programmers. * For example, businesses use word-processing and accounting programs, along with games. * You can write your own programs. ## Computers * Primitive Computers * "The Box" * CRT Display * CD-ROM Drive * Keyboard ## Software Types * **System Software** * Operating Systems * Communications * Device drivers and utilities * Performance management * **Business Software** * General businesses * Applications by business/interest area * Desktop publishing * Project management * Image processing * **Development Software** * Programming Languages * Computer-assisted software engineering * Web site development software ## Programming Models * **Procedural Programming** focuses on the procedures that programmers create. * Procedural programmers focus on the actions that are carried out. * **Object-oriented Programming** focuses on objects, or "things", and describes their features (also called attributes) and behaviors. ## Programming Language You write computer instructions in a computer programming language such as Visual Basic, C++, C#, or Java. * Programmers write programs in different languages. * Some programmers work exclusively in one language, others know several and use the one that is best suited to the task at hand. * The instructions you write using a programming language are called **program code**. * Every programming language has rules governing its word usage and punctuation. * These rules are called the language's **syntax**. * Mistakes in a language's usage are **syntax errors**. ## Computer Languages Computer languages may be divided into three general types: * **Machine Languages** * **Assembly Languages** * **High-Level Languages** The process of compiling a high-level language program into machine language can take a considerable amount of computer time. * **Interpreter programs** were developed to execute high-level language programs directly, although much more slowly. ## Understanding the Programming Process **Programming steps:** 1. Understand the Problem. 2. Plan the Logic. 3. Code the Program. 4. Translate the program into machine language. 5. Test the Program. 6. Put the program into production. 7. Maintain the program. ### Envisioning the Objects * **Programmer** * Envisions objects needed * Writes programming language instructions to create objects * **Distinct steps** * Data modeling * Identify all manipulated objects and relations * Create class * General object category * Establish communication means * Between objects, user ### Planning the Logic * **Heart of programming process** * **Programmer** * Plans program steps * Decides steps to include and order * Leads from available input to desired output * Plans the solution: logic tools * Flowcharts * Pseudocode * Both use English-like code * Language syntax not a concern ### Coding the Program * **Write class definitions** * Descriptions data in each class * Operations performed with data in each class * **Object-oriented Languages** * C++, C#, Java, Visual Basic, COBOL * **Similarity** * All create objects and establish communication ### Coding the Program (cont'd.) * **Program object and logic needed to work with the objects.** * Executed using any number of languages * **Syntax (correct spelling and punctuation)** * Concern once language chosen * **Experienced programmers** * Combine planning and program coding in one step ### Translating the Program Code * **Many programming languages** * **Computer knows one language** * Its machine language consisting of many 1s and 0s * **Translator programs (compilers or interpreters)** * Change English-like high-level programming into low-level machine language * Executable program * **Syntax error** * Issues when translator cannot translate the code * Must be corrected to allow compilation to complete * **Debugging** is the process of finding and correcting program errors. ### Testing the Program * **Syntax error-free program** * **Not necessarily free of logical errors** * Must test for logical errors * **Requires entering of sample data** * Select test data carefully * **Error discovery may require changes:** * To program logic * To actual object design * **Process resembles syntax error correction cycle** ### Putting the Program into Production * **Program adequately tested** * Ready for organizational use * **Putting program into production** * Time to implement * Can be short or long * Depends on the program nature, size, and user needs * **Factors** * Training, data format changes, new platform causing users to make choices in unanticipated combinations. ### Maintaining the Program: * **Maintenance** * Process of making required changes * **Reasons** * New legislation * Input file format alterations * End user requires additional information * Not included in original output specifications ## The Program Development Cycle **The program development cycle** Understand the Problem Plan the Logic Write the Code Translate the Code Test the Program Put the Program into Production Maintain the Program ## Algorithm **An algorithm** is a set of rules or instructions for doing a task or solving a problem. * **A computer program** is simply an algorithm for a computer that is written in a programming language. * Programmers often use one of two tools: * **Pseudocode** (pronounced sue-doe-code) or * **Flowcharts** * **To plan the logic** for a programming problem solution. ## Some Symbols Used In Flowcharts * **1 - Terminal symbol:** * Indicates the beginning and the end of processing. * **2 - I/O symbol:** * Indicates that the computer is to obtain new data or to record the results of computations. * **3 - Decision symbol:** * Represents a branch in the flow of a program. * **4 - Process symbol:** * Contains instructions that are not represented by other symbols. * I.e., it contains calculations, storage of data. * **5 - Flow direction lines:** * Indicate the flow of the program. * Arrowheads are drawn where flow direction lines join and where flow direction lines meet other symbols. * **6 - Comment or annotation symbol:** * Is used to annotate other entries. * A dashed line indicates the position of the comment. * **7 - Connector:** * Is used to join areas of a flowchart. * **8 - Striped symbol:** * Is used to represent a predefined process (or series of operations) when the flowcharts that define the process are included with the current set of flowcharts. * **9 - Predefined process symbol:** * Is used to represent a predefined process, when the flowcharts that define the process are not included with the current set of flowcharts. * **10 - Off-page connector:** * Is used to join areas of a flowchart when the points joined occur on different pages. ## Pseudocode * **Pseudocode** (pronounced sue-doe-code) is an English-like representation used by programmers to plan the logical steps for solving a programming problem. * "Pseudo" is a prefix that means FALSE, and to code a program means to put it in a programming language; pseudocode simply means false code. * Pseudocode for a particular program is often similar in appearance to the final coded program. * The chief difference is that pseudocode does not follow the syntax rules of a programming language. **Example** **Flowchart** ``` Start Read InputNumber Result = InputNumber * 2 Print Result Stop ``` **Pseudocode** ``` Start Input myNumber set myAnswer = myNumber * 2 output myAnswer Stop ``` ## Repeating Instructions **Flowchart** ``` start input myNumber set myAnswer = myNumber* 2 output myAnswer input myNumber set myAnswer = myNumber * 2 output myAnswer input myNumber set myAnswer = myNumber * 2 output myAnswer stop ``` **Pseudocode** ``` start input myNumber set myAnswer = myNumber * 2 output myAnswer Stop ``` ## Using a Sentinel Value to End a Program ``` start input myNumber if myNumber = -1 stop else set myAnswer = myNumber * 2 output myAnswer go to start ``` ## Complex Flowchart This flowchart shows the flow for what happens to the values of x and y as the program runs: * **X** is increased by 1. * **Y** is increased by the value of **X**. ## Exercises **Excercise #1** Examine the following flowchart, fill in the table of values, and answer the questions. * What numbers will be printed? * What values will x and y have when the program ends? **Excercise #2** Examine the following flowchart, and fill in the table values. What will the values of x, y and z be when this program ends? **Table of Values** | X | Y | Z | | ----- | ---- | ---- | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ## End of Document.