Lecture 1 Overview of Computer Programming.ppt

damditlhare 11 views 37 slides Aug 08, 2024
Slide 1
Slide 1 of 37
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37

About This Presentation

Computer Systems Engineering


Slide Content

An Object-Oriented Approach to
Programming Logic and Design
Fourth Edition
An Overview of Computer
Programming

Learning Objectives
•List and describe computer components and
operations
•Apply simple program logic
•Understand the history of programming languages
•Describe the types of programming languages
•Differentiate between procedural and object
oriented languages
•List programming language generations
2An Object-Oriented Approach to Programming Logic and Design

Understanding Computer
Components and Operations
•Computer system
–Combination of all components required to process and
store data using a computer
•Two major computer system components
–Hardware
•Physical devices associated with the computer
–Software
•Computer instructions that tell the hardware what to do
•Programs (sets of instructions) written by programmers
•Application software: programs applied to a task
•System software: programs that manage computer resources
3An Object-Oriented Approach to Programming Logic and Design

Understanding Computer
Components and Operations (cont’d)
•Three major hardware and software operations
–Input
–Processing
–Output
•Input operation
–A means for data to enter a computer through an input
device such as a mouse or keyboard
4An Object-Oriented Approach to Programming Logic and Design

Understanding Computer
Components and Operations (cont’d)
•Processing data operation
–Organizing or sorting data
–Checking for accuracy
–Performing mathematical operations
–Tasks occur in central processing unit (CPU)
•Output operation
–Means to view, print, or store data using output devices
•Printer or monitor
•Storage devices (e.g., disks, flash media)
•Information: data that has been processed
5An Object-Oriented Approach to Programming Logic and Design

Understanding Computer
Components and Operations (cont’d)
•Programming language
–Instructions controlling data manipulation
–Examples include Visual Basic, C#, C++, or Java
•Syntax
–Rules governing word usage and punctuation for a
programming language
–Syntax errors: mistakes in a language’s usage
•Program code
–Instructions written in a programming language
6An Object-Oriented Approach to Programming Logic and Design

Understanding Computer
Components and Operations (cont’d)
•Computer memory (RAM)
–Temporary, internal storage
•Executable statements
–Statements that carry out a program’s actions
•Compiler or interpreter
–Translate high level programming language statements into
low-level machine or binary language
–Point out syntax errors
7An Object-Oriented Approach to Programming Logic and Design

Understanding Computer
Components and Operations (cont’d)
•Compiler
–Translates entire program before execution
•Interpreter
–Translates an instruction just prior to execution
•Source code
–Program statements written in a programming language
•Object code
–Code translated into machine language statements
8An Object-Oriented Approach to Programming Logic and Design

Understanding Simple Program Logic
•Logic errors
–Program may execute but produces incorrect results
–Can be avoided by
•Writing program instructions in specific sequence
•Removing extraneous instructions
•Including all required instructions
–Example of logic errors 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
9An Object-Oriented Approach to Programming Logic and Design
Danger:
Do not follow these cake-
baking instructions!

Understanding Simple Program Logic
(cont’d)
•Computer programs include steps that perform
input, processing, and output
•Sample instructions written in English-like language
–Program doubles any given number
–Requires three operations: input, processing, and output
input myNumber  input
myAnswer = myNumber * 2  processing
output myAnswer  output
10An Object-Oriented Approach to Programming Logic and Design

Understanding the Evolution
of Programming Models
•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
11An Object-Oriented Approach to Programming Logic and Design

Understanding the Evolution
of Programming Models (cont’d)
•Newer programming languages
–Look like natural language
–Use meaningful names for memory locations
–Allow creation of self-contained modules or program
segments
•Can be pieced together
•Can be reused
12An Object-Oriented Approach to Programming Logic and Design

Understanding the Evolution
of Programming Models (cont’d)
•Major program development techniques
–Procedural programming
•Focuses on actions that are carried out
•Breaks down processes into manageable subtasks
–Object-oriented programming – focuses on objects
–Objects: entities that have attributes, behaviors, and states
•Attributes: object features
•Behaviors: what object does
•States: set of all values of attributes
–Primary difference is focused on early planning stages
13An Object-Oriented Approach to Programming Logic and Design

Understanding the Evolution
of Programming Models (cont’d)
•Object-oriented approach
–Defining the objects needed to accomplish a task
–Each object maintains its own data and carries out tasks
–“Natural” way of thinking about the world
•Types of object-oriented approach applications
–Computer simulations
•Mimic real-world activities
•Users apply programs to tasks after the programs are written
–Graphical user interfaces (GUIs)
•Users interact with program in graphical environment
14An Object-Oriented Approach to Programming Logic and Design

Understanding the Steps
in the Programming Process
•System program
–A group of many programs
•Object-oriented approach involves
–Analyzing the system
–Designing the system
–Writing the programs
•Programmer may do all tasks or use systems analysts
and/or software testers
15An Object-Oriented Approach to Programming Logic and Design

Understanding the Steps
in the Programming Process (cont’d)
•Types of software testing
–Black box
•Tester provides input and checks for valid output
–White box
•Tester looks at code, tests all logical paths
16An Object-Oriented Approach to Programming Logic and Design

Analyzing the Program or System
•Programmers provide a service to users
•Object-oriented analysis (OOA)
–Understand the users’ needs
–Needs are often not well defined
–Can be difficult and time consuming
–Frequently, several program revisions are necessary to
satisfy the user
17An Object-Oriented Approach to Programming Logic and Design

Designing the System
•Designers using object-oriented design (OOD)
–Envision the objects needed
–Determine objects’ attributes and behaviors
–Decide the relationship between objects
•Describe how objects communicate with and react to each
other
•Expressed as verb phrases
•Examples of relationships: “Has a,” “is a,” “creates a”
•Class
–A general category that describes entities
–May be reused from other programs or modified
18An Object-Oriented Approach to Programming Logic and Design

Writing and Testing Programs
•Writing a program involves several subtasks
–Developing the program logic
–Coding the program
–Translating the program into machine language
–Testing the program
19An Object-Oriented Approach to Programming Logic and Design

Writing and Testing Programs (cont’d)
•Planning the logic
–Heart of the programming process
–Also referred to as developing an algorithm
–Decide steps to include and their order
–Planning tools
•Flowcharts and pseudocode
•Both use English-like code
–Language syntax not a concern
–Desk-checking
•Reviewing program logic on paper
20An Object-Oriented Approach to Programming Logic and Design

Writing and Testing Programs (cont’d)
•Coding the program
–Writing program statements in a programming language
–Object-oriented languages
•C++, C#, Java, Visual Basic, SmallTalk, OO COBOL, and Simula
•Create objects and establish communication between them
•Language chosen determines syntax
–Coding usually less difficult than planning step
21An Object-Oriented Approach to Programming Logic and Design

Writing and Testing Programs (cont’d)
•Use software to translate program into machine
language
–Many programming languages
–Computer knows only machine language (1s and 0s)
•Compilers or interpreters
–Translate English-like, high-level programming language
into low-level machine language
22An Object-Oriented Approach to Programming Logic and Design

Writing and Testing Programs (cont’d)
•Syntax error
–Occurs when translator cannot translate the code
–Causes: misspellings, illegal grammar, non-existent words
–Programmer must correct code and recompile the
program before it can execute
23An Object-Oriented Approach to Programming Logic and Design
Creating an executable program
Figure 1-1

Writing and Testing Programs (cont’d)
•Testing the program
–Program that is free of syntax errors is not necessarily free
of logical errors
•Must test for logical errors
–May require entering of sample data
•Select test data carefully
•Error discovery may require changes to program logic
24An Object-Oriented Approach to Programming Logic and Design

Writing and Testing Programs (cont’d)
•After the program is written and tested
–Ready to be used
•Additional tasks associated with programs written for
organizations
–Preparing manuals
–Training users
–Converting existing data to new system’s format
•Conversion
–Actions an organization take to switch to a new program
–Can take months or years to accomplish
25An Object-Oriented Approach to Programming Logic and Design

Writing and Testing Programs (cont’d)
•Maintenance
–Process of making required changes after program is put
into production
•Reasons why maintenance may be necessary
–Fixing previously undiscovered errors
–Updating values such as a tax rate
–Changing format of input data
–Input data may no longer be available
–User wants additional functionality
26An Object-Oriented Approach to Programming Logic and Design

Using Pseudocode and Flowcharts
•Pseudocode
–English-like representation of logical program steps
–Looks like programming language but is not
–Flexible planning tool
•Example
•Starting and ending statements often used
•Punctuation and syntax are not important
27An Object-Oriented Approach to Programming Logic and Design
start
input myNumber
myAnswer = myNumber * 2
output myAnswer
stop

Drawing Flowcharts
•Flowchart
–Pictorial representation of logical program steps
–Helps programmer visualize how statements connect
–Uses geometric shapes connected with arrows (flowlines)
•Common flowchart symbols
–Input symbols (parallelograms)
–Processing symbols (rectangles)
–Output symbols (parallelograms)
–Terminal symbols (lozenges – flattened ovals)
–Decision symbols (diamonds)
28An Object-Oriented Approach to Programming Logic and Design

Drawing Flowcharts (cont’d)
29An Object-Oriented Approach to Programming Logic and Design
Flowchart and pseudocode of a program
that doubles a number if it is less than 10
Figure 1-3

Drawing Flowcharts (cont’d)
•Software applications with flowcharting tools
–Microsoft Word
–Microsoft PowerPoint
–Visio
–Visual Logic
30An Object-Oriented Approach to Programming Logic and Design

Understanding Program Comments
•Program comments
–Non-executing statements in a program added for
documentation
•Programmers write comments for themselves and
others who read program
•Minimally, comments should include author, date,
and purpose of the program
•C++, Java, and C# use two forward slashes
// This is a comment
31An Object-Oriented Approach to Programming Logic and Design

Annotation symbol used for comments on a flowchart
32An Object-Oriented Approach to Programming Logic and Design
Three-sided box
with dashed line
connects to the
step it explains Figure 1-4

Understanding Programming
and User Environments
•Flowcharts created by hand or with software
•Pseudocode written by hand or with a word processor
–Plain text editor
–Text editor in an integrated development environment (IDE)
•Text editor
–Program used to create simple text files
–Similar to a word processor, but less robust
–Example: Notepad in Microsoft Windows
–Complete program does not require much disk space
33An Object-Oriented Approach to Programming Logic and Design

Understanding Programming and
User Environments (cont’d)
•Integrated development environment (IDE)
–Software package that includes an editor, compiler, and
other programming tools
•Advantages of using IDE
–Uses colors to display various language components
–Highlights syntax errors visually
–Employs automatic statement completion
–Provides tools to step through a program to find errors
•Disadvantages of using IDE
–Requires much more storage space than plain text editor
34An Object-Oriented Approach to Programming Logic and Design

•A user might execute program in different
environments: command line, GUI
•The logical process is the same regardless of the
environment
Understanding User Environments
35An Object-Oriented Approach to Programming Logic and Design
Executing a number-doubling program in a
command-line environment
Executing a number-doubling
program in a GUI environment
Figure 1-7
Figure 1-8

Summary
•Hardware and software accomplish three major
operations: input, processing, and output
•For a program to work properly, you must develop
correct logic
•Logical errors are more difficult to locate than syntax
errors
•Developing a system involves analyzing the system,
designing it, and writing the programs
•Writing programs involves logic planning, coding the
program, translating into machine language, and testing
36An Object-Oriented Approach to Programming Logic and Design

Summary (cont’d)
•Flowcharts and pseudocode are tools for planning a
program’s logic
•Pseudocode is an English-like representation of a
program’s logical steps
•Flowchart is a pictorial representation of a program
•Program comments document a program
•Plain text editor or an integrated development
environment (IDE) can be used to type a program
•A program’s data input can be at a command line or a
graphical user interface (GUI)
37An Object-Oriented Approach to Programming Logic and Design