Title: An ObjectOriented Approach to Programming Logic and Design
1An Object-Oriented Approach to Programming Logic
and Design
- Chapter 1
- An Overview of Computers and Logic
2Objectives
- Understand computer components
- Understand the evolution of programming
techniques - Describe the steps involved in the programming
process - Understand flowcharts and pseudocode statements
3Objectives (continued)
- Create an application class with a main() method
- Use and name variables
- Assign values to variables
- Describe data types
4Understanding 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
5Understanding Computer Components and Operations
(continued)
- Together, hardware and software accomplish four
major operations - Input
- Processing
- Output
- Storage
6Understanding Computer Components and Operations
(continued)
- Input a means for data to enter the computer
through an input device such as - Mouse
- Keyboard
- Scanner
7Understanding 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
8Understanding Computer Components and Operations
(continued)
- Output a means for data to be viewed, printed,
interpreted, or stored, using devices such as - Printer
- Monitor
- Speakers
9Understanding 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)
10Understanding 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
11Understanding 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
12Understanding 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
13Understanding 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
14Understanding 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
15Understanding 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
16Understanding 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
17Understanding the Programming Process (continued)
- Steps in writing programs
- Envision and create the objects that are
required, and identify how they relate to each
other (data modeling) - Create the classes (the code to create a general
category, or template, for an object including
its attributes and behaviors) - Code the statements in the program to manipulate
the objects
18Understanding the Programming Process (continued)
- Steps in writing programs (continued)
- Compile the program to obtain machine
instructions - Test the program
- Put the program into production
19Understanding the Programming Process (continued)
20Using 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 isnt
21Using Flowcharts and Pseudocode Statements
(continued)
Example Flowchart
22Creating 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()
23Creating 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
24Creating 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
25Creating an Application Class with a main()
Method (continued)
26Creating an Application Class with a main()
Method (continued)
27Creating an Application Class with a main()
Method (continued)
28Using 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
29Using and Naming Variables (continued)
30Assigning 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
31Understanding Data Types
- Two basic types of datatext 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
32Understanding 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
33Understanding Data Types (continued)
Example Declare the variable, and set the value
afterwards
34Understanding Data Types (continued)
Example Initialize the variable when declaring it
35Understanding Data Types (continued)
Example DoubleNumber class allows the user to
enter a number and see the result when the value
is doubled.
36Summary
- 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
37Summary (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
38Summary (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