3. Step 1 - Analyze the problem
Outline the problem and its requirements
Design steps (algorithm) to solve the problem
Step 2 - Implement the algorithm
Implement the algorithm in code
Verify that the algorithm works
Step 3 - Maintenance
Use and modify the program if the problem domain
changes
Problem Solving Process
(revisit)
C++ Programming: From Problem Analysis to Program
Design, Third Edition
3
4.
5. Thoroughly understand the problem
Understand problem requirements
Does program require user interaction?
Does program manipulate data?
What is the output?
If the problem is complex, divide it into sub-
problems
Analyze each sub-problem as above
Analyze the Problem
C++ Programming: From Problem Analysis to Program
Design, Third Edition
5
6. If problem was broken into sub-problems
Design algorithms for each sub-problem
Check the correctness of algorithm
Can test using sample data
Some mathematical analysis might be required
Design an Algorithm
C++ Programming: From Problem Analysis to Program
Design, Third Edition
6
7. Once the algorithm is designed and correctness
verified
Write the equivalent code in high-level language
Type the program using text editor
Write the Code
C++ Programming: From Problem Analysis to Program
Design, Third Edition
7
8. Run code through compiler
If compiler generates errors
Look at code and remove errors
Run code again through compiler
If there are no syntax errors
Compiler generates equivalent machine code
Linker links machine code with system resources
Compiling and Linking
C++ Programming: From Problem Analysis to Program
Design, Third Edition
8
9. Once compiled and linked, loader can place
program into main memory for execution
The final step is to execute the program
Compiler guarantees that the program follows the
rules of the language
Does not guarantee that the program will run
correctly
The Loader and Executing
C++ Programming: From Problem Analysis to Program
Design, Third Edition
9
11. Definition:
A way of conceptualizing what it means to
perform computation and how tasks to be carried
out on the computer should be structured and
organized.
Programming Paradigm
A First Book of C++ 4th Edition 11
12. General types of programming paradigms:
Structural
Imperative
Declarative
Procedural
Object-Oriented
Functional
Domain-Specific
Programming Paradigm
(cont'd.)
A First Book of C++ 4th Edition 12
13. Structured programming (or modular
programming) is a problem solving strategy
and a programming methodology that
includes the following guidelines:
The flow of control in the program should be as
simple as possible.
The construction of a program should embody
top-down design.
Programming Paradigm
(cont'd.)
A First Book of C++ 4th Edition 13
14. Top-down design means:
It repeatedly decomposing a problem into
smaller problems.
Eventually leads to:
a collection of small problems or tasks.
each can be easily coded
Programming Paradigm
(cont'd.)
A First Book of C++ 4th Edition 14
15. Object-oriented programming is a method of
programming based on a hierarchy of classes, and
well-defined and cooperating objects.
A class is a structure that defines the data and the
methods to work on that data.
In simple definition, a class is a programmer defined
data type.
Programming Paradigm
(cont'd.)
A First Book of C++ 4th Edition 15
16. Object-oriented programming (OOP) concepts are:
Programming Paradigm
(cont'd.)
A First Book of C++ 4th Edition 16
Concepts Functions
Data Abstraction specifies behavior
Encapsulation controls visibility of names (data
hiding)
Polymorphism accommodates various
implementations
Inheritance facilitates code reuse
Modularity relates to unit of compilation
17. Structured vs. Object-Oriented
Programming
A First Book of C++ 4th Edition 17
Structured Programming:
MAIN PROGRAM
FUNCTION 3FUNCTION 2
GLOBAL DATA
FUNCTION 5FUNCTION 4
FUNCTION
1
18. Structured Programming:
Using functions.
Function & program is divided into modules.
Every module has its own data and function which
can be called by other modules.
Structured vs. Object-Oriented
Programming
A First Book of C++ 4th Edition 18
19. Structured vs. Object-Oriented
Programming (cont'd.)
A First Book of C++ 4th Edition 19
Object-Oriented Programming:
Object 1
Object 2
Data
Function
Data
Function
Object 3
Data
Function
20. Object-Oriented Programming:
Objects have both data and methods.
Objects of the same class have the same data
elements and methods.
Objects send and receive messages to invoke
actions.
Structured vs. Object-Oriented
Programming
A First Book of C++ 4th Edition 20
21. Data object
Set of values packaged as single unit (e.g., student’s
name & grade)
Class
Set of objects with similar attributes
General concept of object-oriented programming is the
difference between an object and the larger set of which
it is a member (class)
A red Ford is an instance, or object, of a general class
of automobiles or cars
Classes and Objects
A First Book of C++ 4th Edition 21