Chapter 1 An Overview of Computers and Logic

Slides:



Advertisements
Similar presentations
Chapter 3: Modules, Hierarchy Charts, and Documentation
Advertisements

Lecture 1: Overview of Computers & Programming
CHAPTER 1: AN OVERVIEW OF COMPUTERS AND LOGIC. Objectives 2  Understand computer components and operations  Describe the steps involved in the programming.
Chapter 1 - An Introduction to Computers and Problem Solving
Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming.
COSC 120 Computer Programming
CIS105 Chapter 1 Theory Review. Page 2 Hardware and Software are the two major components o any computer system Hardware is the set of physical devices.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Computers: Tools for an Information Age
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition by Tony Gaddis, Judy Walters,
An Overview of Computers and Logic
An Overview of Programming Logic and Design
Modules, Hierarchy Charts, and Documentation
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
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.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
Programming Logic and Design Fourth Edition, Introductory
An Overview of Computers and Programming
CS102 Introduction to Computer Programming
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Programming Logic and Design Fifth Edition, Comprehensive
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Chapter Introduction to Computers and Programming 1.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
An Overview of Computers and Logic
Topics Introduction Hardware and Software How Computers Store Data
Programming Logic and Design Sixth Edition Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Input, Output, and Processing
Visual C++ Programming: Concepts and Projects
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
P ROGRAMMING L OGIC AND D ESIGN S IXTH E DITION Chapter 1 An Overview of Computers and Programming.
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC LECTURE ONE.
An Object-Oriented Approach to Programming Logic and Design Chapter 1 An Overview of Computers and Logic.
Introduction to Programming with RAPTOR
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Chapter One An Introduction to Programming and Visual Basic.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Programming Logic and Design Seventh Edition
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Chapter 1: Introduction to Computers and Programming.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
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.
Chapter 1: Introduction to Computers and Programming
Topics Designing a Program Input, Processing, and Output
CSCI-235 Micro-Computer Applications
Chapter 1: An Overview of Computers and Programming Languages
DDC 1023 – Programming Technique
C++ Programming: From Problem Analysis to Program Design
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 2 Applications and Data.
Chapter 1: Introduction to Computers and Programming
Topics Introduction Hardware and Software How Computers Store Data
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Chapter 4: Writing and Designing a Complete Program
Programming Logic and Design Eighth Edition
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

Chapter 1 An Overview of Computers and Logic An Object-Oriented Approach to Programming Logic and Design Second Edition Chapter 1 An Overview of Computers and Logic

Objectives Learn about computer components and operations Learn about the evolution of programming techniques Learn about the steps involved in the programming process Learn about flowcharts and pseudocode statements An Object-Oriented Approach to Programming Logic and Design

Objectives (cont’d.) Create an application class with a main()method Use and name variables Assign values to variables Describe data types Learn about various forms of input An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations Two major computer system components Hardware Equipment or devices associated with the computer Software Programs (sets of instructions) written by programmers Application software: applied to a task (word processing, spreadsheets, payroll, etc.) System software: manages computer resources An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations (cont’d.) Four major hardware and software operations Input Processing Output Storage Input operation A means for data to enter computer through an input device Mouse Keyboard An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations (cont’d.) Processing data operation Organizing Checking for accuracy Performing mathematical operations Tasks occur in central processing unit (CPU) Using machine instructions Software Provides machine instructions to CPU Written using programming languages An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations (cont’d.) Output operation A means to view, print, interpret, store data using output devices Printer Monitor Hardcopy Printed computer output Softcopy Screen output An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations (cont’d.) Storage operation Storing output information on storage device hardware Magnetic disks, compact discs, USB drives Computer software Instructions controlling data manipulation Data input Data processing Data output or storage form Gives hardware a purpose An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations (cont’d.) Obtaining programmer’s instructions (software) Buying prewritten software stored on Downloading software from the web Write your own software instructions Enter instructions through hardware devices Store on storage device (disk, CD) An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations (cont’d.) Programming languages Common languages Visual Basic, C#, C++, COBOL, RPG, Fortran, JAVA Programmers may specialize Syntax Rules governing usage and punctuation Must be perfect An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations (cont’d.) Machine language Circuitry consisting of millions of on-off switches Computer’s on-off circuitry language Compilers and interpreters Language translation software Identify correct/incorrect language use Compilers Create and store reusable machine instructions Interpreters Interpret programming language at run-time An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations (cont’d.) Two programming language errors Syntax errors Incorrect spelling Incorrect structure of language elements Semantic (logic) errors Incorrect instructions Incorrect order of instructions Logic Providing computer instructions in a specific sequence An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations (cont’d.) Logic (cont’d.) Example: a logic error in cake-making instructions Stir Add two eggs Add a gallon of gasoline Bake at 350 degrees for 45 minutes Add three cups of flour Run or executed Occurs after program written and compiled successfully An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations (cont’d.) Program instructions example Written in English-like language Three operations (input, processing, output) Get inputNumber. Compute calculatedAnswer as inputNumber times 2. Print calculatedAnswer. An Object-Oriented Approach to Programming Logic and Design

Understanding the Evolution of Programming Techniques Storage categories Internal and external needed by computer system Internal storage Memory, main memory, primary memory Volatile main memory: lost when power turned off Inside machine Most often discussed in book An Object-Oriented Approach to Programming Logic and Design

Understanding the Evolution of Programming Techniques (cont’d.) Storage categories (cont’d.) External storage Persistent (relatively permanent) storage Outside main memory (not necessarily outside computer) Exists in devices Disk drives: hard and floppy Flash media Magnetic tape An Object-Oriented Approach to Programming Logic and Design

Understanding the Evolution of Programming Techniques (cont’d.) Program execution Program copy stored in main memory Required data must be in memory location Program calls location to obtain data Processing occurs Output displayed An Object-Oriented Approach to Programming Logic and Design

Understanding the Evolution of Programming Techniques (cont’d.) Modern computer programs Around since 1940s Oldest programming languages Programmers worked with memory addresses Memorized awkward codes associated with machine languages Written as one piece An Object-Oriented Approach to Programming Logic and Design

Understanding the Evolution of Programming Techniques (cont’d.) Newer programming languages Look like natural language Easier to use Reasons for ease of use Use meaningful names for memory locations No awkward memory addresses Allow creation of self-contained modules or program segments Can be pieced together An Object-Oriented Approach to Programming Logic and Design

Understanding the Evolution of Programming Techniques (cont’d.) Program development techniques Procedural programming Procedures created to manipulate data Actions carried out (getting input data for an employee and writing the calculations) Breaks process into manageable subtasks An Object-Oriented Approach to Programming Logic and Design

Understanding the Evolution of Programming Techniques (cont’d.) Program development techniques (cont’d.) Object-Oriented programming (OOP) Objects, attributes, behaviors, states Attributes: object feature Behaviors: what object does States: set of all values of attributes Describes objects’ features or attributes An Object-Oriented Approach to Programming Logic and Design

Understanding the Evolution of Programming Techniques (cont’d.) Program development techniques (cont’d.) Differences Programmer focus area in early stage Object-oriented approach application types Computer simulations Create a model Graphical user interfaces Users interact with program in graphical environment Natural use for object orientation An Object-Oriented Approach to Programming Logic and Design

Understanding the Programming Process Computer software system development Three object-oriented approach tasks Object-oriented analysis (OOA) Analyzing the system Object-oriented design (OOD) Designing the system Object-oriented programming (OOP) Writing the programs An Object-Oriented Approach to Programming Logic and Design

1. Understanding the Problem Programmer Write programs to satisfy others needs Provide services to users First understand what users want Well designed program Steps might involve a short meeting Poorly designed program Steps might take many meeting hours Thoroughly understanding problem A most difficult aspect of programming An Object-Oriented Approach to Programming Logic and Design

2. 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 An Object-Oriented Approach to Programming Logic and Design

3. 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: two tools Flowcharts and pseudocode Both use English-like code Language syntax not a concern An Object-Oriented Approach to Programming Logic and Design

3. Planning the Logic (cont’d.) Think about all possible data values program might encounter How to handle each scenario Desk-checking Walking through program’s logic on paper Before writing the program Focus of course An Object-Oriented Approach to Programming Logic and Design

4. 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, Smalltalk, OO COBOL, Simula Similarity All create objects and establishing communication An Object-Oriented Approach to Programming Logic and Design

4. 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 An Object-Oriented Approach to Programming Logic and Design

5. 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 An Object-Oriented Approach to Programming Logic and Design

5. Translating the Program Code (cont’d.) Figure 1-1 Creating an executable program. An Object-Oriented Approach to Programming Logic and Design

6. 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 An Object-Oriented Approach to Programming Logic and Design

7. 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 program nature, size and user needs Factors Training, data format changes, new platform causing users to make choices in unanticipated combinations An Object-Oriented Approach to Programming Logic and Design

7. Putting the Program into Production (cont’d.) Non working program may cause significant monetary loss Testing before deployment must be thorough Conversion Entire set of actions organization takes to switch over to new program (set of programs) May take months or years to accomplish An Object-Oriented Approach to Programming Logic and Design

8. Maintaining the Program Maintenance Process of making required changes Reasons New legislated tax rates Input file format alterations End user requires additional information Not included in original output specifications An Object-Oriented Approach to Programming Logic and Design

9. Retiring the Program Final programming process step Program no longer needed by organization New program in process of going into production An Object-Oriented Approach to Programming Logic and Design

Using Flowcharts and Pseudocode Statements Pictorial representation of logical program steps Program steps in boxes Connected with flowlines (arrows) Shows processing order Pseudocode English-like representation of logical program steps Looks like programming language (is not) Important part of permanent documentation Design and operation of software system An Object-Oriented Approach to Programming Logic and Design

Using Flowcharts and Pseudocode Statements (cont’d.) Figure 1-2 Flowchart of number-doubling problem An Object-Oriented Approach to Programming Logic and Design

Creating an Application Class with a main() Method Purely object-oriented programming languages Every statement (application) part of class “Pure View” Application Program accomplishing some task Application pseudocode Begins with word class Ends with word endClass No object-oriented programming language uses endClass Used here for clarity An Object-Oriented Approach to Programming Logic and Design

Creating an Application Class with a main() Method (cont’d.) Set of statements performing task or group of tasks Where program actions take place If class contains one executable method Method named main() Identifier Name of programming object Class, method, or variable An Object-Oriented Approach to Programming Logic and Design

Creating an Application Class with a main() Method (cont’d.) Figure 1-3 Flowchart and pseudocode for main() method that prints “Hello” An Object-Oriented Approach to Programming Logic and Design

Creating an Application Class with a main() Method (cont’d.) Specific programming languages Have rules for identifier structure Book pseudocode rules Identifier names One word Letters, digits, hyphens, underscores No spaces Identifiers should have appropriate meaning Compound words allowed Example: Helloclass An Object-Oriented Approach to Programming Logic and Design

Creating an Application Class with a main() Method (cont’d.) main() statement Method header Class containing main() method An executable program Every method ends with return statement main() method action statements Placed between main() method header and return statement An Object-Oriented Approach to Programming Logic and Design

Creating an Application Class with a main() Method (cont’d.) Figure 1-4 The Hello class written in the Java programming language Figure 1-5 The Hello class written in the C# programming language An Object-Oriented Approach to Programming Logic and Design

Using and Naming Variables Variables (fields) Memory locations Contents can change over time Holds just one value at any given time Most objects in programs contain variables holding objects’ attributes Same rules for naming variables as naming classes An Object-Oriented Approach to Programming Logic and Design

Using and Naming Variables (cont’d.) Table 1-1 Valid and invalid variable names for an employee’s last name An Object-Oriented Approach to Programming Logic and Design

Assigning Values to Variables Assignment statement Statement assigning values to variables Example: calculatedAnswer = inputNumber * 2 Assignment operator Example: equal sign Requires memory location name on left side where result stored Named constant Named memory location (similar to variable) Value never changes during program execution An Object-Oriented Approach to Programming Logic and Design

Assigning Values to Variables (cont’d.) High-level computer language Programmers pick reasonable “English” name for memory address Computer keeps track of memory location Mathematical operations Performed on memory address contents Operator precedence rules Multiplication and division: precedence over addition and subtraction Assignment operator has very low precedence An Object-Oriented Approach to Programming Logic and Design

Understanding Data Types Basic data types: text and numeric Numeric constant (43) Specific numeric value Does not change Digits with no quotation marks Used for numeric calculations String constant (“chris”) Specific character set enclosed in double quotes Character constant: single quotes (‘C’) An Object-Oriented Approach to Programming Logic and Design

Understanding Data Types (cont’d.) Two distinct variable types Numeric variable Holds a number Character variables Hold single character String variables hold group of characters Distinguish between numeric and character Computers handle two data types differently Language syntax rules define data type to expect Done differently in every language An Object-Oriented Approach to Programming Logic and Design

Understanding Data Types (cont’d.) Variable declaration statement Contains data type and identifier Initializing a variable Setting initial starting variable value Popular languages (C++, C#, java, Visual Basic) Distinguish integer (whole number) numeric variables and floating-point (fractional) numeric variables containing decimal point Three broad types of variables Numeric, character, string An Object-Oriented Approach to Programming Logic and Design

Understanding Data Types (cont’d.) Garbage value Uninitialized variable containing unknown value Default value Automatic values for uninitialized variables Text or character data handled differently from numeric data (every computer) First step in writing programs Identifying variables correctly Numeric, character, string Any programming language An Object-Oriented Approach to Programming Logic and Design

Understanding Data Types (cont’d.) Table 1-2 Some examples of legal and illegal assignments An Object-Oriented Approach to Programming Logic and Design

Figure 1-6 Flowchart and pseudocode for the DoubleNumber class An Object-Oriented Approach to Programming Logic and Design

Understanding Various Forms of Input Simple programs require simple data Data values often entered from keyboard Users presented with a prompt Message on monitor asking for user response User interface User’s means of interacting with the computer Command prompt Input area on computer screen User can type text that communicates with computer’s operating system An Object-Oriented Approach to Programming Logic and Design

Understanding Various Forms of Input (cont’d.) Figure 1-7 A prompt followed by a response and output in a command-line environment An Object-Oriented Approach to Programming Logic and Design

Understanding Various Forms of Input (cont’d.) Figure 1-8 Flowchart and pseudocode for prompt and response in number-doubling program An Object-Oriented Approach to Programming Logic and Design

Understanding Various Forms of Input (cont’d.) Text environment Many programs do not run at command prompt Run using GUI Typically contains graphical controls (buttons and text boxes) User can manipulate with a mouse or other pointing device An Object-Oriented Approach to Programming Logic and Design

Understanding Various Forms of Input (cont’d.) Figure 1-9 A prompt, a response, and output in a GUI environment An Object-Oriented Approach to Programming Logic and Design

Understanding Various Forms of Input (cont’d.) Figure 1-10 Flowchart and pseudocode for text box response in number-doubling program An Object-Oriented Approach to Programming Logic and Design

Summary Hardware and software accomplish four major operations: input, processing, output, and storage Computer programming languages used to write machine instructions Requires specific syntax Procedural programming focuses on procedures programmers creates to manipulate data OOP focuses on objects Describes features or attributes and their behaviors An Object-Oriented Approach to Programming Logic and Design

Summary (cont’d.) Programmer Identifies objects and classes, codes program, translates into machine language, tests, puts into production Flowcharts and/or pseudocode used to plan programming solution logic Program actions occur within a method Variables Named memory locations, contents can vary Choose meaningful variable names An Object-Oriented Approach to Programming Logic and Design

Summary (cont’d.) Assignment always takes place from right to left Variable declaration tells computer type of data to expect Numeric, character, and string variables handled differently by computer User input data Text or graphical environment File stored alone or in database An Object-Oriented Approach to Programming Logic and Design