0% found this document useful (0 votes)
43 views

Programming Fundamentals (750113) : Ch1. Problem Solving

The document discusses the problem solving process for programming. It explains that programming involves solving problems through algorithms. The problem solving process has three phases: (1) analyzing the problem by outlining requirements, designing an algorithm using tools like flowcharts and pseudocode, and testing the algorithm; (2) implementing the algorithm by coding it in a programming language; and (3) maintaining the program if requirements change. The document provides details on analyzing problems, designing algorithms, coding in C++, compiling, executing programs, and debugging logic errors.

Uploaded by

Hani Hamad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Programming Fundamentals (750113) : Ch1. Problem Solving

The document discusses the problem solving process for programming. It explains that programming involves solving problems through algorithms. The problem solving process has three phases: (1) analyzing the problem by outlining requirements, designing an algorithm using tools like flowcharts and pseudocode, and testing the algorithm; (2) implementing the algorithm by coding it in a programming language; and (3) maintaining the program if requirements change. The document provides details on analyzing problems, designing algorithms, coding in C++, compiling, executing programs, and debugging logic errors.

Uploaded by

Hani Hamad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 20

Programming Fundamentals

(750113)

Ch1. Problem Solving

Programming Fundamentals --> Ch1. 1


Problem solving
Problem Solving

• Programming is a process of problem


solving (Problem Solution by computer)

• Algorithm ?
 Step-by-step problem-solving process
 Solution achieved in finite amount of time

Programming Fundamentals --> Ch1. 2


Problem solving
Problem Solving Process

• Phase 1 - Analyze the problem


 Outline the problem and its requirements
 Design (algorithm) to solve the problem ( Flow chart, pseudo code)
 Algorithm tracing

• Phase 2 - Implement the algorithm


 Implement the algorithm in code (in Programming Language 
Program)
 Verify that the algorithm works

• Phase 3 - Maintenance
 Use and modify the program if the requirements changes

Programming Fundamentals --> Ch1. 3


Problem solving
Analyze the Problem (1)
Outline the problem and its requirements

• Understand the problem


• Understand problem requirements
 Does program require user interaction?
 Does program manipulate data?
 What is the output?
 are all possible circumstances handled?
• If the problem is complex, divide it into
subproblems
 Analyze each subproblem as above

Programming Fundamentals --> Ch1. 4


Problem solving
Analyze the Problem (1)
Design Algorithm
1. Flowcharts
2. pseudo-code

Programming Fundamentals --> Ch1. 5


Problem solving
• A Flowchart is
 An algorithm graphical representation.
 Written as a combination of the following graphical
notations:
Flow Chart Symbols

Start and End Selection Data


Flow

Input / output Calculation

Programming Fundamentals --> Ch1. 6


Problem solving
• Pseudo-code:
<Algorithm name>
// input ? The comment lines “//”
// function?
// Output?
Begin
<data definition>
<actions>
End

Programming Fundamentals --> Ch1. 7


Problem solving
Analyze the Problem (1)
Algorithm Tracing
 Draw flowchart
 Find all possible paths
 Check each path with appropriate input data
 Observed Outputs not conform to the expected ones 
error in the algorithm.

Programming Fundamentals --> Ch1. 8


Problem solving
Analyze the Problem (2)
Problem Example.
Convert a student mark from decimal mode to ABC mode.

Understand problem requirements


 Does program require user interaction? Input the mark
 Does program manipulate data?  covert mark Control
Requirements (IF statement)
 What is the output? The mark converted to A or B or C or
error
 Is there subproblem? No

Programming Fundamentals --> Ch1. 9


Problem solving
Analyze the Problem (2)
Efficiency:
- an algorithm may work correctly but be inefficient – by taking
more time and using more resources than required to
solve the problem.
- becomes more important for larger programs.

Programming Fundamentals --> Ch1. 10


Problem solving
Implement the algorithm (Coding)
•After testing your algorithm, you can code it
in any programming language.

•In our lab, we are going to use C++


language.

Programming Fundamentals --> Ch1. 11


Problem solving
C++ Language Elements
• The general form of a C++ program
// File: filename
// Program description
# include compiler directives
void main ( )
{
declarations section
executable statement section
} Programming Fundamentals --> Ch1. 12
Problem solving
 Computer Stage: after completing the
program, the computer must do the
following:
- Compilation:
- Execution:

Programming Fundamentals --> Ch1. 13


Problem solving
Stages of Compilation
o Performed by a program called the compiler
o Translates the preprocessor-modified source code
into object code (machine code)
o Checks for syntax errors and warnings
o Saves the object code to a disk file
o If any compiler errors are received, no object code file
will be generated.
o An object code file will be generated if only warnings,
not errors, are received.

Programming Fundamentals --> Ch1. 14


Problem solving
Compiler converts
human readable
language to a
language which is
understandable by
the operating
system/hardware
Execution
• when the program become don’t has errors,
the computer execute it to produce the ……
output.

Programming Fundamentals --> Ch1. 16


Problem solving
Implement the algorithm
Verify that the algorithm works  source of
errors
• Many errors made in:
- analyzing the problem,
- developing an algorithm, and/or
- coding the algorithm

Programming Fundamentals --> Ch1. 17


Problem solving
Implement the algorithm

• Errors are of three types:


. syntax errors
. run-time errors
. logic errors
• Syntax errors: detected by the C compiler
. source code does not conform to one or more of C’s
grammar rules
. examples of syntax errors: undeclared variable, …
• Often one mistake leads to multiple error messages –
can be confusing

Programming Fundamentals --> Ch1. 18


Problem solving
Implement the algorithm
• Run-time errors. detected and displayed by computer during
execution.
- Occur when program directs computer to perform illegal
operation. Example: int x=y/0;
- will stop program execution and display message
• Logic errors.
- caused by faulty algorithm
- sign of error: incorrect program output
- cure: thorough testing and comparison with expected
results
A logic error is referred to as a bug, so finding logic errors is
called debugging.
Programming Fundamentals --> Ch1. 19
Problem solving
Conclusions (Cont’d)

Programming Fundamentals --> Ch1. 20


Problem solving

You might also like