SlideShare a Scribd company logo
1 of 24
Programming Fundamentals -->
Ch1. Problem solving
1
Algorithms and Problem Solving
Programming Fundamentals -->
Ch1. Problem solving
2
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. Problem solving
3
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. Problem solving
4
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. Problem solving
5
Analyze the Problem (1)
Design Algorithm
1. Flowcharts
2. pseudo-code
Programming Fundamentals -->
Ch1. Problem solving
6
Flow Chart Symbols
Start and End
Input / output
Selection
Calculation
Data
Flow
• A Flowchart is
 An algorithm graphical representation.
 Written as a combination of the following graphical
notations:
Programming Fundamentals -->
Ch1. Problem solving
7
• Pseudo-code:
<Algorithm name>
// input ? The comment lines “//”
// function?
// Output?
Begin
<data definition>
<actions>
End
Programming Fundamentals -->
Ch1. Problem solving
8
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. Problem solving
9
Analyze the Problem (2)
Problem Example.
Convert a student mark from decimal mode to ABC mode.
Understand problem requirements
 Is the problem statement complete and unambiguous?
 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. Problem solving
10
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. Problem solving
11
Analyze the Problem (3)
Design Algorithm  Algorithm Discovery
• To discover an algorithm is to solve the problem!
1. Working backwards (modification of an old solution)
Example: Min of a and b is known. Deduce Max a and b.
2. Look for a related problem that has been solved before (similar
solutions reuse)
The precedent algorithm of mark conversion is for single student. It
may be generalized to many students
3. Stepwise Refinement (new solution)
 Break the problem into several sub-problems
 Solve each subproblem separately
 Produces a modular structure
Programming Fundamentals -->
Ch1. Problem solving
12
Analyze the Problem (3)
•Example. Making tea. Suppose we have a robot
which carries out household tasks. We wish to
program the robot to make a cup of tea. An initial
attempt at an algorithm might be:
1. Put tea leaves in pot
2. Boil water
3. Add water to pot
4. Wait 5 minutes
5. Pour tea into cup
Design Algorithm  Algorithm Discovery Strategies  Stepwise
Refinement
Programming Fundamentals -->
Ch1. Problem solving
14
Analyze the Problem(3)
•the designer must know when to stop refining.
•In this example the instruction Switch on kettle is
directly executable by the robot, but that Fill kettle
with water is not.
•Experience will tell us when a step is directly
implementable or not.
•The above algorithm consists of a sequence of
steps, executed exactly once and in order
Programming Fundamentals -->
Ch1. Problem solving
15
Analyze the Problem(3)
•Control requirements: while
Another common requirement is the need for
iteration.
— Example. Repeat the mark conversion for a
class room of 30 students. Each student having a
unique student number from 1 to 30.
Programming Fundamentals -->
Ch1. Problem solving
16
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.
C Language Elements
• The general form of a C program
// File: filename.c
// Program description
# include compiler directives
void main ( )
{
declarations section
executable statement section
} Programming Fundamentals -->
Ch1. Problem solving
17
Programming Fundamentals -->
Ch1. Problem solving
18
 Computer Stage: after completing the
program, the computer must do the
following:
- Compilation:
- Execution:
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. Problem solving
19
Stages of Compilation
Execution
• when the program become don’t has errors, the
computer execute it to produce the ……output.
Programming Fundamentals -->
Ch1. Problem solving
21
Programming Fundamentals -->
Ch1. Problem solving
22
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. Problem solving
23
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. Problem solving
24
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.

More Related Content

Similar to Programs_Problem_Solving_Algorithms.ppt

C++ programming program design including data structures
C++ programming program design including data structures C++ programming program design including data structures
C++ programming program design including data structures Ahmad Idrees
 
Unit 1 program development cycle
Unit 1 program development cycleUnit 1 program development cycle
Unit 1 program development cycleDhana malar
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfMMRF2
 
Program design and problem solving techniques
Program design and problem solving techniquesProgram design and problem solving techniques
Program design and problem solving techniquesDokka Srinivasu
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem slovingMani Kandan
 
01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptxssuser586772
 
COM1407: Structured Program Development
COM1407: Structured Program Development COM1407: Structured Program Development
COM1407: Structured Program Development Hemantha Kulathilake
 
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHESC LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHESHarshJha34
 
Week1 programming challenges
Week1 programming challengesWeek1 programming challenges
Week1 programming challengesDhanu Srikar
 
Algorithms and flow charts
Algorithms and flow chartsAlgorithms and flow charts
Algorithms and flow chartsChinnu Edwin
 
Algorithm and C code related to data structure
Algorithm and C code related to data structureAlgorithm and C code related to data structure
Algorithm and C code related to data structureSelf-Employed
 
Chapter 2(1)
Chapter 2(1)Chapter 2(1)
Chapter 2(1)TejaswiB4
 

Similar to Programs_Problem_Solving_Algorithms.ppt (20)

C++ programming program design including data structures
C++ programming program design including data structures C++ programming program design including data structures
C++ programming program design including data structures
 
Programing Fundamental
Programing FundamentalPrograming Fundamental
Programing Fundamental
 
Chapter 01.PPT
Chapter 01.PPTChapter 01.PPT
Chapter 01.PPT
 
Lecture1
Lecture1Lecture1
Lecture1
 
Unit 1 program development cycle
Unit 1 program development cycleUnit 1 program development cycle
Unit 1 program development cycle
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
 
Program design and problem solving techniques
Program design and problem solving techniquesProgram design and problem solving techniques
Program design and problem solving techniques
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem sloving
 
01CHAP_1.PPT
01CHAP_1.PPT01CHAP_1.PPT
01CHAP_1.PPT
 
L1
L1L1
L1
 
Module 1 python.pptx
Module 1 python.pptxModule 1 python.pptx
Module 1 python.pptx
 
01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx
 
COM1407: Structured Program Development
COM1407: Structured Program Development COM1407: Structured Program Development
COM1407: Structured Program Development
 
Week10 final
Week10 finalWeek10 final
Week10 final
 
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHESC LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
 
UNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.pptUNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.ppt
 
Week1 programming challenges
Week1 programming challengesWeek1 programming challenges
Week1 programming challenges
 
Algorithms and flow charts
Algorithms and flow chartsAlgorithms and flow charts
Algorithms and flow charts
 
Algorithm and C code related to data structure
Algorithm and C code related to data structureAlgorithm and C code related to data structure
Algorithm and C code related to data structure
 
Chapter 2(1)
Chapter 2(1)Chapter 2(1)
Chapter 2(1)
 

Recently uploaded

APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Recently uploaded (20)

APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Programs_Problem_Solving_Algorithms.ppt

  • 1. Programming Fundamentals --> Ch1. Problem solving 1 Algorithms and Problem Solving
  • 2. Programming Fundamentals --> Ch1. Problem solving 2 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
  • 3. Programming Fundamentals --> Ch1. Problem solving 3 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
  • 4. Programming Fundamentals --> Ch1. Problem solving 4 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
  • 5. Programming Fundamentals --> Ch1. Problem solving 5 Analyze the Problem (1) Design Algorithm 1. Flowcharts 2. pseudo-code
  • 6. Programming Fundamentals --> Ch1. Problem solving 6 Flow Chart Symbols Start and End Input / output Selection Calculation Data Flow • A Flowchart is  An algorithm graphical representation.  Written as a combination of the following graphical notations:
  • 7. Programming Fundamentals --> Ch1. Problem solving 7 • Pseudo-code: <Algorithm name> // input ? The comment lines “//” // function? // Output? Begin <data definition> <actions> End
  • 8. Programming Fundamentals --> Ch1. Problem solving 8 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.
  • 9. Programming Fundamentals --> Ch1. Problem solving 9 Analyze the Problem (2) Problem Example. Convert a student mark from decimal mode to ABC mode. Understand problem requirements  Is the problem statement complete and unambiguous?  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
  • 10. Programming Fundamentals --> Ch1. Problem solving 10 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.
  • 11. Programming Fundamentals --> Ch1. Problem solving 11 Analyze the Problem (3) Design Algorithm  Algorithm Discovery • To discover an algorithm is to solve the problem! 1. Working backwards (modification of an old solution) Example: Min of a and b is known. Deduce Max a and b. 2. Look for a related problem that has been solved before (similar solutions reuse) The precedent algorithm of mark conversion is for single student. It may be generalized to many students 3. Stepwise Refinement (new solution)  Break the problem into several sub-problems  Solve each subproblem separately  Produces a modular structure
  • 12. Programming Fundamentals --> Ch1. Problem solving 12 Analyze the Problem (3) •Example. Making tea. Suppose we have a robot which carries out household tasks. We wish to program the robot to make a cup of tea. An initial attempt at an algorithm might be: 1. Put tea leaves in pot 2. Boil water 3. Add water to pot 4. Wait 5 minutes 5. Pour tea into cup
  • 13. Design Algorithm  Algorithm Discovery Strategies  Stepwise Refinement
  • 14. Programming Fundamentals --> Ch1. Problem solving 14 Analyze the Problem(3) •the designer must know when to stop refining. •In this example the instruction Switch on kettle is directly executable by the robot, but that Fill kettle with water is not. •Experience will tell us when a step is directly implementable or not. •The above algorithm consists of a sequence of steps, executed exactly once and in order
  • 15. Programming Fundamentals --> Ch1. Problem solving 15 Analyze the Problem(3) •Control requirements: while Another common requirement is the need for iteration. — Example. Repeat the mark conversion for a class room of 30 students. Each student having a unique student number from 1 to 30.
  • 16. Programming Fundamentals --> Ch1. Problem solving 16 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.
  • 17. C Language Elements • The general form of a C program // File: filename.c // Program description # include compiler directives void main ( ) { declarations section executable statement section } Programming Fundamentals --> Ch1. Problem solving 17
  • 18. Programming Fundamentals --> Ch1. Problem solving 18  Computer Stage: after completing the program, the computer must do the following: - Compilation: - Execution:
  • 19. 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. Problem solving 19
  • 21. Execution • when the program become don’t has errors, the computer execute it to produce the ……output. Programming Fundamentals --> Ch1. Problem solving 21
  • 22. Programming Fundamentals --> Ch1. Problem solving 22 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
  • 23. Programming Fundamentals --> Ch1. Problem solving 23 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
  • 24. Programming Fundamentals --> Ch1. Problem solving 24 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.

Editor's Notes

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 7
  7. 8
  8. 9
  9. 10
  10. 11
  11. 12
  12. 14
  13. 15
  14. 16
  15. 22
  16. 23
  17. 24