Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "An Object-Oriented Approach to Programming Logic and Design Chapter 1 An Overview of Computers and Logic."— Presentation transcript:

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

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

3 An Object-Oriented Approach to Programming Logic and Design 3 Objectives (continued) Create an application class with a main() method Use and name variables Assign values to variables Describe data types

4 An Object-Oriented Approach to Programming Logic and Design 4 Understanding Computer Components and Operations Two major components of any computer system: –Hardware: equipment or devices associated with the computer –Software: programs, or sets of instructions, written by programmers Application software – applied to a task, such as word processing, spreadsheets, payroll, etc. System software – manage computer resources

5 An Object-Oriented Approach to Programming Logic and Design 5 Understanding Computer Components and Operations (continued) Together, hardware and software accomplish four major operations: –Input –Processing –Output –Storage

6 An Object-Oriented Approach to Programming Logic and Design 6 Understanding Computer Components and Operations (continued) Input: a means for data to enter the computer through an input device such as: –Mouse –Keyboard –Scanner

7 An Object-Oriented Approach to Programming Logic and Design 7 Understanding Computer Components and Operations (continued) Processing: performing mathematical or other operations on the data –Takes place in the central processing unit (CPU) using machine instructions –Software provides machine instructions to the CPU –Software is written using programming languages

8 An Object-Oriented Approach to Programming Logic and Design 8 Understanding Computer Components and Operations (continued) Output: a means for data to be viewed, printed, interpreted, or stored, using devices such as: –Printer –Monitor –Speakers

9 An Object-Oriented Approach to Programming Logic and Design 9 Understanding Computer Components and Operations (continued) Storage: maintaining the data in internal or external storage devices Internal storage: main memory, which is volatile (lost when the power is turned off) External storage: permanent storage outside of main memory in devices such as –Disk drives: hard and floppy –USB memory drives –Magnetic tapes and cartridges –Compact discs (CD-ROMs) and digital video discs (DVDs)

10 An Object-Oriented Approach to Programming Logic and Design 10 Understanding Computer Components and Operations (continued) Programming languages: used to create machine instructions in a language that humans can understand –Common languages include Visual Basic, C#. C++, COBOL, RPG, Fortran, Java, etc. –Programming languages have rules governing the usage and punctuation, called the syntax –Programming language instructions are translated to machine instructions using a compiler or interpreter

11 An Object-Oriented Approach to Programming Logic and Design 11 Understanding Computer Components and Operations (continued) Two kinds of programming language errors: –Syntax errors: incorrect spelling or incorrect structure of the language elements –Semantic (logic) errors: incorrect instructions or incorrect order of instructions When the program has been written and compiled, it must then be executed or run

12 An Object-Oriented Approach to Programming Logic and Design 12 Understanding Computer Components and Operations (continued) Example of a logic error in instructions for making a cake: Stir Add two eggs Add a gallon of gasoline Bake at 350 degrees for 45 minutes Add three cups of flour

13 An Object-Oriented Approach to Programming Logic and Design 13 Understanding the Evolution of Programming Techniques: Languages Computer programming began in the 1940s, using machine instructions and codes for memory addresses Newer languages look more like natural languages, using variables to represent memory addresses

14 An Object-Oriented Approach to Programming Logic and Design 14 Understanding the Evolution of Programming Techniques: Structure Older programs were written as one component, from start to finish Newer programs are written as separate, self- contained, reusable components that are combined together

15 An Object-Oriented Approach to Programming Logic and Design 15 Understanding the Evolution of Programming Techniques: Techniques Two major techniques for developing programs: –Procedural programming: focuses on creating procedures and steps for accomplishing subtasks –Object-Oriented programming (OOP): focuses on objects, their attributes, behaviors, and states Attributes: features of an object Behaviors: what the object does States: the set of values of all of the attributes

16 An Object-Oriented Approach to Programming Logic and Design 16 Understanding the Programming Process Object-oriented approach to developing a computer software system involves three tasks: –Object-oriented analysis (OOA): analyzing the system –Object-oriented design (OOD): designing the system –Object-oriented programming (OOP): writing the programs Our focus is on writing programs that are already designed

17 An Object-Oriented Approach to Programming Logic and Design 17 Understanding the Programming Process (continued) Steps in writing programs: 1.Envision and create the objects that are required, and identify how they relate to each other (data modeling) 2.Create the classes (the code to create a general category, or template, for an object including its attributes and behaviors) 3.Code the statements in the program to manipulate the objects

18 An Object-Oriented Approach to Programming Logic and Design 18 Understanding the Programming Process (continued) Steps in writing programs (continued): 4.Compile the program to obtain machine instructions 5.Test the program 6.Put the program into production

19 An Object-Oriented Approach to Programming Logic and Design 19 Understanding the Programming Process (continued)

20 An Object-Oriented Approach to Programming Logic and Design 20 Using Flowcharts and Pseudocode Statements Flowchart: a pictorial representation of the logical steps of the program –Program steps are in boxes, connected with flowlines (arrows) to show the order of processing Pseudocode: an English-like representation of the logical steps of the program; looks like a programming language, but isn’t

21 An Object-Oriented Approach to Programming Logic and Design 21 Using Flowcharts and Pseudocode Statements (continued) Example: Flowchart

22 An Object-Oriented Approach to Programming Logic and Design 22 Creating an Application Class with a main() Method In “pure view,” every application is a class Pseudocode for an application begins with the word class and end with endClass Method: a set of statements that performs some task or group of tasks If a class contains only one method that executes, the method is named main()

23 An Object-Oriented Approach to Programming Logic and Design 23 Creating an Application Class with a main() Method (continued) Identifier: the name of a programming object such as a class, method, or variable –Specific programming languages have rules for the structure of identifiers Our rules for pseudocode are: –Identifier names must be one word, with letters, digits, hyphens, underscores, but no spaces –Identifiers should have an appropriate meaning –Compound words such as HelloClass are OK

24 An Object-Oriented Approach to Programming Logic and Design 24 Creating an Application Class with a main() Method (continued) The statement main() is the method header A class that contains a main() method is an executable program Every method ends with a return statement. Place the action statements of the main() method between the main() method header and the return statement

25 An Object-Oriented Approach to Programming Logic and Design 25 Creating an Application Class with a main() Method (continued)

26 An Object-Oriented Approach to Programming Logic and Design 26 Creating an Application Class with a main() Method (continued)

27 An Object-Oriented Approach to Programming Logic and Design 27 Creating an Application Class with a main() Method (continued)

28 An Object-Oriented Approach to Programming Logic and Design 28 Using and Naming Variables Variables or fields are memory locations whose contents can change over time Most of the objects in programs contain variables that hold the objects’ attributes Use the same rules for naming variables as for naming classes

29 An Object-Oriented Approach to Programming Logic and Design 29 Using and Naming Variables (continued)

30 An Object-Oriented Approach to Programming Logic and Design 30 Assigning Values to Variables Assignment statements: assign values to variables calculatedAnswer = inputNumber * 2 Assignment operator: requires the name of a memory location on its left side where the result will be stored Named constant: a named memory location, similar to a variable, whose value never changes during program execution

31 An Object-Oriented Approach to Programming Logic and Design 31 Understanding Data Types Two basic types of data—text and numeric Numbers: written as digits with no quotation marks; used for numeric calculations. Ex: 42 String constant: a specific set of characters enclosed in quotations. Ex: “Chris” Character variables: variables that hold a single character String variables: variables that hold a group of characters

32 An Object-Oriented Approach to Programming Logic and Design 32 Understanding Data Types (continued) Variable declaration statement: contains the data type and the identifier Initializing a variable: setting an initial starting value for the variable Types of numeric data (depending on the programming language) may include integer, floating point, and other types Default values – automatic values for uninitialized variables

33 An Object-Oriented Approach to Programming Logic and Design 33 Understanding Data Types (continued) Example: Declare the variable, and set the value afterwards

34 An Object-Oriented Approach to Programming Logic and Design 34 Understanding Data Types (continued) Example: Initialize the variable when declaring it

35 An Object-Oriented Approach to Programming Logic and Design 35 Understanding Data Types (continued) Example: DoubleNumber class allows the user to enter a number and see the result when the value is doubled.

36 An Object-Oriented Approach to Programming Logic and Design 36 Summary Hardware and software accomplish four major operations: Input, Processing, Output, and Storage Computer programming languages are used to write machine instructions Object-oriented programming, or OOP, focuses on objects and describes their features, or attributes, and their behaviors

37 An Object-Oriented Approach to Programming Logic and Design 37 Summary (continued) A programmer must identify objects and classes, code the program, translate it into machine language, test it, and put it into production Flowcharts and/or pseudocode are used to plan the logic for a programming solution Variables are named memory locations whose contents can vary –Choose meaningful names for your variables

38 An Object-Oriented Approach to Programming Logic and Design 38 Summary (continued) Assignment always takes place from right to left Variable declaration tells the computer what type of data to expect Numeric, character, and string variables are handled differently by the computer


Download ppt "An Object-Oriented Approach to Programming Logic and Design Chapter 1 An Overview of Computers and Logic."

Similar presentations


Ads by Google