How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.

Slides:



Advertisements
Similar presentations
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Advertisements

How Are Algorithms Developed?
Chapter 3: Modularization
Computers Are Your Future
Programming Logic and Design Fourth Edition, Introductory
Introduction to Programming
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
زبانهای برنامه سازی برنامه سازی پیشرفته ارائه دهنده دکتر سيد امين حسيني E.mail: Home page:
Computers Are Your Future © 2006 Prentice Hall, Inc.
Program Design and Development
Computers: Tools for an Information Age
Lecture Notes 1/21/04 Program Design & Intro to Algorithms.
An Overview of Programming Logic and Design
Program Development and Programming Languages
Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved.
An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
COBOL for the 21 st Century Stern, Stern, Ley Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL.
Chapter 1 Program Design
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Lecture Notes 8/30/05 Program Design & Intro to Algorithms.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Chapter 3 Planning Your Solution
PRE-PROGRAMMING PHASE
Programming Concepts and Languages Chapter 12 – Computers: Understanding Technology, 3 rd edition 1November
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
CS102 Introduction to Computer Programming
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Programming Languages CPS120: Introduction to Computer Science Lecture 5.
Structured COBOL Programming, Stern & Stern, 9th edition
CC111 Lec#5: Program Development 1 Program Development and Programming Languages Lecture 4 Reference :Understanding Computers Chapter 13.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Developing a Program.
CIS Computer Programming Logic
สาขาวิชาเทคโนโลยี สารสนเทศ คณะเทคโนโลยีสารสนเทศ และการสื่อสาร.
PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or directs the computer what to do. PROGRAMMING LANGUAGE.
TMF1013 : Introduction To Computing Lecture 1 : Fundamental of Computer ComputerFoudamentals.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
CPS120 Introduction to Computer Programming The Programming Process.
IXA 1234 : C++ PROGRAMMING CHAPTER 1. PROGRAMMING LANGUAGE Programming language is a computer program that can solve certain problem / task Keyword: Computer.
INTRODUCTION TO COMPUTING CHAPTER NO. 04. Programming Languages Program Algorithms and Pseudo Code Properties and Advantages of Algorithms Flowchart (Symbols.
Chapter 12 Computer Programming. Chapter Contents Chapter 12: Computer Programming 2  Section A: Programming Basics  Section B: Procedural Programming.
CPS120: Introduction to Computer Science Decision Making in Programs.
Copyright © Prentice Hall Programming and Languages Chapter 14 Telling the Computer What to Do.
Control Structures CPS120: Introduction to Computer Science Lecture 5.
Chapter One An Introduction to Programming and Visual Basic.
CPS120 Introduction to Computer Science Iteration (Looping)
Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11.
Chapter 14 Programming and Languages McGraw-Hill/Irwin Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved.
How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
Alexandria University Faculty of Science Computer Science Department Introduction to Programming C++
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
PROGRAMMING FUNDAMENTALS INTRODUCTION TO PROGRAMMING. Computer Programming Concepts. Flowchart. Structured Programming Design. Implementation Documentation.
CPS120: Introduction to Computer Science Session 5.
Introduction to Programming Languages © 2005 Prentice Hall, Inc. CXC IT Unit 2: Intro. to Programming.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
PROGRAMMING (1) LECTURE # 1 Programming and Languages: Telling the Computer What to Do.
Victoria Ibarra Mat:  Generally, Computer hardware is divided into four main functional areas. These are:  Input devices Input devices  Output.
Programming Logic and Design Seventh Edition Chapter 1 An Overview of Computers and Programming.
CSCI-235 Micro-Computer Applications
Programming Concepts and Languages
Computer Programming.
CPS120: Introduction to Computer Science
ICT Gaming Lesson 2.
An Introduction to Programming with C++ Fifth Edition
Basic Concepts of Algorithm
CPS120: Introduction to Computer Science
Programming Logic and Design Eighth Edition
Presentation transcript:

How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5

Problem Solving  Is an art, not a science  It must be experienced, it can't be taught Guidelines can be provided –Based on experience –Sound like platitudes –Are internalized as we learn to solve problems  It requires patience

Problem Solving Tasks  Establish the context of the problem Understand the problem Determine the primary goals of the solution Create a solution

Problem Solving Guidelines  One big problem is unsolvable Many small problems can be managed  Understand the problem: What is needed? Write on paper what results are expected What functions (procedures) will be required to generate these results What information will need to be given to these functions Describe what the functions do before you write a single line of code

Programs  A program is a set of step- by-step instructions that directs the computer to do the tasks you want it to do and produce the results you want.

The Program Development Cycle

Understand the problem  Become familiar with what the program is trying to accomplish Read the specifications Ask questions Understand the specifications  Eliminate extraneous information

Plan the Program’s Logic  Decide how to best meet the program’s specifications  Often uses a flowchart or pseudocode  Divide the program into subroutines, functions or modules Subroutines cost less and take less time to maintain Can be used in other programs Several programmers can work on the same project

Code the Program  Put the solution, generally documented with pseudocode or a flowchart into a programming language

Machine-Readable Form  Key the program into a computer

Translate the program  Translated into machine language using an assembler, a compiler or an interpreter  Includes the elimination of syntax errors  Generate executable file

Test the Program  Logic errors are not listed during the translation projects  Only way to find logic errors is to do program testing Involves using sample data as input Executing the program Checking the results manually  Know as debugging

Document the Program  Internal Documentation Comments  External Documentation Program specification Layout chart Hierarchy chart Program flowchart Pseudo-code Data Dictionary –Input, Output, Work Area –Name, description, type, initial value, calculation Source listing Test Plan

Programming Languages  A programming language is a set of rules that provides a way of telling a computer what operations to perform.

Levels of Programming Languages  Machine language  Assembly Language  High Level Languages  Fourth Generation Languages (4GL)

Machine Languages  different for each computer processor

Assembly Languages  different for each computer processor mainproc pay mov ax, dseg mov ax, 0b00h add ax, dx mov a1, b1 mul b1, ax mov b1, 04h

High-Level Languages  Higher Level Languages Use traditional programming logic where the programming instructions tell the computer what to do and how to perform the required operations.  4GLs Use high-level English-like instructions to specify what to do, not how to do it.

Interpreter vs. Compiler  Interpreter Translates instructions to machine code line-by-line.  Compiler Translates the entire program to machine code before running it.

Types of Programming Languages  Machine language  Procedure-oriented languages  Object-oriented languages  Event-driven languages

Early Language History  FORTRAN (short for Formula Translator, developed in the 1950s by IBM  In 1958, a language called ALGOL (Algorithm Language) was developed  COBOL (Common Business Oriented Language) was created in 1960 to serve as the primary language for large-scale programs  In 1964, the BASIC language (Beginners All-Purpose Symbolic Instruction Code) was first used  In 1965, a language called PL/I was developed in hopes of being everything to everyone.  PL/I proved to be too complex.  In the late 1960s, Niklaus Wirth developed a teaching language called Pascal.

Later Language History  Ada, which was developed in 1983, is large and complex.  Smalltalk is graphical and object-oriented. Concepts developed with Smalltalk were important to the development and continued development of languages like C++ and Java  The C language was derived from ALGOL.  C++ is C with the addition of object-oriented concepts.

Procedure-Oriented Languages  FORTRAN  COBOL  Pascal  C  Ada

OOED Languages  Object-oriented languages Smalltalk C++ Ada 95  Event-driven languages Visual Basic most Visual languages

What Can a Program Do?  A program can only instruct a computer to: Read Input Sequence Calculate Store data Compare and branch Iterate or Loop Write Output

Fundamental Programming Concepts  Assignment of values to a variable  Iteration (Looping) Over a set of set of statements With respect to a logical expressions (conditions)  Delegation of sub-tasks to functions / procedures

The Structure Theorem The Structure Theorem states that any algorithm can be built from three basic control structures.  One-after-another (Sequence)  Decision-making (Selection) Making choices between 2 or more alternatives  Repetition (Iteration) Concerned with repetitive tasks (and the termination conditions of loops)

C++ Control Structures 1. "Sequence statements" are imperatives 2. "Selection" is the "if then else" statement – AND, OR, NOT and parentheses ( ) can be used for compound conditions 3. "Iteration" is satisfied by a number of statements – "while" – " do " – "for" 4. The case-type statement is satisfied by the "switch" statement. – CASE statements are used for most non-trivial selection decisions

Sequence Control Structures  Sequence control structures direct the order of program instructions.  The fact that one instruction follows another—in sequence—establishes the control and order of operations.

Calculate  A program can instruct a computer to perform mathematical operations. Add 1 to Counter

Store  A program will often instruct a computer to store intermediate results. Place 1 in Counter

Compare and Branch  A program can instruct a computer to compare two items and do something based on a match or mismatch which, in turn, redirect the sequence of programming instructions. There are two forms: IF-THEN IF-THEN-ELSE

IF-THEN Test condition p falsetrue Entry Exit True statement a

IF-THEN-ELSE falsetrue Entry Exit Test condition p “true” statement a “false” statement a

Iterate  A program loop is a form of iteration. A computer can be instructed to repeat instructions under certain conditions.

Iteration Control Structures  Iteration control structures are looping mechanisms.  Loops repeat an activity until stopped. The location of the stopping mechanism determines how the loop will work:  Leading decisions  Trailing decisions

Leading Decisions  If the stop is at the beginning of the iteration, then the control is called a leading decision.  The command DO WHILE performs the iteration and places the stop at the beginning.

DO WHILE Loop No Yes Entry Exit Test condition p Loop statement a

Trailing Decisions  If the stop is at the end of the iteration, the control mechanism is called a trailing decision.  The command DO UNTIL performs the iteration and puts the stop at the end of the loop.

DO UNTIL Loop Loop statement a NoYes Entry Test condition p Exit

Programmer Productivity Tools  Modular Programming  Structured Programming  Object-oriented Programming

Modular Programming  Large programs are divided by functional parts into subroutines Strong cohesion Loose coupling

Structured Programming  Composed of sequence, decision (selection), and repetition (looping or iteration) structures  Structured program languages lend themselves to flowcharts, structure charts, and pseudocode.  Structured programming languages work best where the instructions have been broken up into small, manageable parts.  Looks at a problem as procedures Data are maintained separately from data

Structured Program Rules 1. Use only sequence, decision, and repetition 2. Only one entrance into and one exit from a structure 3. Connectors only allowed when continuing processing from one column or page to another 4. Decision and repetition structures can be nested 5. Only one STOP instruction is permitted. It must be in the MAINLINE routine

Structured Programming Advantages  Standard method for solving problems  GO-TO less  Easier to test and debug  Written by more than one programmer  Reusability  Thrashing minimized

Object-Oriented Programs  Developed to respond to programming issues that structured programming did not adequately address 1. Rarely possible to anticipate the design of a completed system before implementation 2. GUIs were difficult to develop in traditional procedure- oriented languages 3. Sharing data across routines is error prone Information hiding allows programmers to determine what data is exposed to various routines