SlideShare a Scribd company logo
1 of 45
INTRODUCTION TO PROBLEM
        SOLVING




                          1
Introduction
• Algorithm
  – A sequence of precise instructions that
    leads to a solution

• Program
  – An algorithm expressed in a language the
    computer can understand



                                               2
Introduction (cont.)
Example:




                                  3
Introduction (cont.)
• Programming is a creative process
  – No complete set of rules for creating a program




                                                      4
Programming Process
• Program Design Process
   – Problem Solving Phase
      • Result is an algorithm that solves the problem
   – Implementation Phase
      • Result is the algorithm translated into a programming
        language
• Be certain the task is completely specified
   – What is the input?
   – What information is in the output?
   – How is the output organized?

                                                                5
Programming Process (cont.)
• Develop the algorithm before implementation
  – Experience shows this saves time in getting your
    program to run.
  – Test the algorithm for correctness




                                                       6
Programming Process (cont.)
Implementation Phase
• Translate the algorithm into a programming
  language
• Compile the source code
   – Locates errors in using the programming language

• Run the program on sample data
   – Verify correctness of results

• Results may require modification of
  the algorithm and program
                                                        7
Programming Process (cont.)




                              8
Programming Process (cont.)
Example:
• STEP 1: PROBLEM ANALYSIS
   – Purpose:
     • To describe in details a solution to a problem by providing the
       needed information for the problem.
  – How?
     • First, understand & study the problem.
  – Identify:
     • The input to the problem.
     • The required output.
     • The relevant process. For example, scientific formula or
       appropriate theories if any.


                                                                         9
Programming Process (cont.)
Problem : Write a program that get 3 numbers
  as input from user. Find the average and
  display the numbers and the average.
Problem Analysis:
      Input:    3 numbers.
      Process: 1. Add the numbers
                2. Divide the total with 3
      Output: The 3 numbers and average

                                               10
Programming Process (cont.)

INPUT      PROCESS     OUTPUT




                                11
Programming Process - Representation
                 Method
•    STEP 2: PROGRAM DESIGN
•    Definition: It defines the framework or the flow or the
     problem solution
1. Algorithm
    – Algorithm is a sequence of instructions to solve a
        problem written in human language and problem
        can be solved if follow the correct procedure
    – A programmer writes the solution in the form of an
        algorithm before coding it into computer language.


                                                           12
Programming Process - Representation
            Method (cont.)
Example of algorithm to calculate the average
  of 3 numbers:
  1. Set Total=0, average=0;
  2. Input 3 numbers
  3. Total up the 3 numbers
           Total= total of 3 numbers
  4. Calculate average
           average=Total/3
  5. Display 3 numbers and the average
                                                13
Programming Process - Representation
            Method (cont.)
2. Flowchart
• A graphical representation of data,
  information and process or an orderly step-
  by-step solution to a problem.




                                                14
Programming Process - Representation
            Method (cont.)
                      Start
Example:
                    Input a, b, c



                  Total = a + b + c



                 average = Total / 3



                  Display a, b, c
                  Display average



                       End




                                         15
Programming Process - Representation
            Method (cont.)
3. Pseudocode
• Steps in problem solving written in certain of
  programming code and certain in human
  language.
• For example, some part use C++ language
  code and some part use English-like phrases.



                                                   16
Programming Process - Representation
            Method (cont.)
START
  INPUT a, b, c
  Total = a + b + c
  average = Total / 3
  OUTPUT a, b, c
  OUTPUT average
END

                                         17
Programming Process - Representation
            Method (cont.)
STEPS 3: PROGRAM CODING
• Definition: Write a solution into a specific
  programming language such as C, C++, COBOL
  and etc.
• Solution: Instructions before it is coded into
  programming language.
• Purpose: To produce a program to develop a
  system.
                                               18
Solving Everyday Problems
• First step in solving a problem: analyze it
  – E.g., problem of being hungry
• Next, you plan, review, implement, evaluate,
  and modify (if necessary) the solution
  – E.g., if you are still hungry




                                                 19
Solving Everyday Problems (continued)




                                    20
Solving Everyday Problems (continued)




                                    21
Creating Computer Solutions to
               Problems
• Analysis tools: IPO charts, pseudocode,
  flowcharts
• To desk-check or hand-trace, use pencil,
  paper, and sample data to walk through
  algorithm
• A coded algorithm is called a program


                                             22
Creating Computer Solutions to
    Problems (continued)




                                 23
Analyzing the Problem
• Analyze a problem to:
  – Determine the goal of solving it
     • Output
  – Determine the items needed to achieve that goal
     • Input
• Always search first for the output




                                                      24
Analyzing the Problem (continued)




                                25
IPO Charts
• Use an IPO chart to organize and summarize
  the results of a problem analysis
  – IPO: Input, Processing, and Output




                                               26
IPO Charts (continued)




                         27
IPO Charts (continued)




                         28
Analyzing the Problem (continued)
• First, reduce the amount of information you
  need to consider in your analysis:




                                                29
Analyzing the Problem (continued)
• Worse than having too much information is
  not having enough information to solve
  problem:




                                              30
Analyzing the Problem (continued)
• Distinguish between information that is
  missing and information that is implied:




                                             31
Planning the Algorithm
• Algorithm: set of instructions that will
  transform the problem’s input into its output
  – Record it in the Processing column of the IPO
    chart
• Processing item: intermediate value used by
  algorithm when processing input into output
• Pseudocode is a tool programmers use to help
  them plan an algorithm
  – Short English statements

                                                    32
Planning the Algorithm (continued)




                                 33
Planning the Algorithm (continued)
• Flowcharts are also used to plan an algorithm
  – Use standardized symbols
  – Symbols connected with flowlines
  – Oval: start/stop symbol
  – Rectangle: process symbol
     • Represents tasks such as calculations
  – Parallelogram: input/output symbol
     • Represents I/O tasks


                                               34
Planning the Algorithm (continued)




                                 35
Planning the Algorithm (continued)
• A problem can have more than one solution:




                                               36
Hints for Writing Algorithms


This problem specification is almost identical to the one shown
earlier in Figure 2-4




                                                                  37
Hints for Writing Algorithms
              (continued)
You may use a portion of a previous solution to solve current problem




                                                                        38
Desk-Checking the Algorithm




                              39
Desk-Checking the Algorithm
       (continued)




                              40
Desk-Checking the Algorithm
             (continued)
• Valid data is data that the programmer is
  expecting the user to enter
• Invalid data is data that he or she is not
  expecting the user to enter
• You should test an algorithm with invalid data
  – Users may make mistakes when entering data




                                                 41
The Gas Mileage Problem




                          42
The Gas Mileage Problem (continued)
• After planning the algorithm, you desk-check
  it:




                                                 43
Summary
• Problem-solving typically involves analyzing the
  problem, and then planning, reviewing,
  implementing, evaluating, and modifying (if
  necessary) the solution
• Programmers use tools (IPO charts, pseudocode,
  flowcharts) to help them analyze problems and
  develop algorithms
  – During analysis, you determine the output and input
  – During planning, you write the steps that will transform
    the input into the output

                                                          44
Summary (continued)
• After the analysis and planning, you desk-
  check the algorithm
   – Follow each of the steps in algorithm by hand
• Coding refers to translating the algorithm
   into a language that the computer can
   understand
• Before writing an algorithm, consider
 Source: An Introductionhave already solved a similar
   whether you to Programming with C++, Fifth Edition
   problem
                                                        45

More Related Content

What's hot

What's hot (20)

Files in c++
Files in c++Files in c++
Files in c++
 
File handling in c
File handling in cFile handling in c
File handling in c
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Structure
StructureStructure
Structure
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
structured programming
structured programmingstructured programming
structured programming
 
Introduction of c programming
Introduction of c programmingIntroduction of c programming
Introduction of c programming
 
Algorithm Introduction
Algorithm IntroductionAlgorithm Introduction
Algorithm Introduction
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
 

Viewers also liked

2.1 Understand problem solving concept
2.1 Understand problem solving concept2.1 Understand problem solving concept
2.1 Understand problem solving conceptFrankie Jones
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving TechniquesAshesh R
 
1 introduction to problem solving and programming
1 introduction to problem solving and programming1 introduction to problem solving and programming
1 introduction to problem solving and programmingRheigh Henley Calderon
 
Stages of problem solving presentation
Stages of problem solving presentationStages of problem solving presentation
Stages of problem solving presentationbbaugh
 
11 Tips On Problem Solving Skills – Overcome Difficulties
11 Tips On Problem Solving Skills – Overcome Difficulties11 Tips On Problem Solving Skills – Overcome Difficulties
11 Tips On Problem Solving Skills – Overcome DifficultiesVKool Magazine - VKool.com
 
Problem solving method
Problem solving methodProblem solving method
Problem solving methodBSEPhySci14
 
The statement of the problem
The statement of the problemThe statement of the problem
The statement of the problemedac4co
 
Problem Solving Method
Problem Solving MethodProblem Solving Method
Problem Solving MethodRoxanne Deang
 
Problem solving & decision making at the workplace
Problem solving & decision making at the workplaceProblem solving & decision making at the workplace
Problem solving & decision making at the workplaceFaakor Agyekum
 
Problem solving ppt
Problem solving pptProblem solving ppt
Problem solving pptIka Rose
 
Problem Solving and Decision Making
Problem Solving and Decision MakingProblem Solving and Decision Making
Problem Solving and Decision MakingIbrahim M. Morsy
 
Problem Solving PowerPoint PPT Content Modern Sample
Problem Solving PowerPoint PPT Content Modern SampleProblem Solving PowerPoint PPT Content Modern Sample
Problem Solving PowerPoint PPT Content Modern SampleAndrew Schwartz
 
PROBLEM SOLVING POWERPOINT
PROBLEM SOLVING POWERPOINT PROBLEM SOLVING POWERPOINT
PROBLEM SOLVING POWERPOINT Andrew Schwartz
 

Viewers also liked (19)

2.1 Understand problem solving concept
2.1 Understand problem solving concept2.1 Understand problem solving concept
2.1 Understand problem solving concept
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
Problem Solving
Problem SolvingProblem Solving
Problem Solving
 
Introduction to problem solving in C
Introduction to problem solving in CIntroduction to problem solving in C
Introduction to problem solving in C
 
1 introduction to problem solving and programming
1 introduction to problem solving and programming1 introduction to problem solving and programming
1 introduction to problem solving and programming
 
Stages of problem solving presentation
Stages of problem solving presentationStages of problem solving presentation
Stages of problem solving presentation
 
Problem solving
Problem solvingProblem solving
Problem solving
 
11 Tips On Problem Solving Skills – Overcome Difficulties
11 Tips On Problem Solving Skills – Overcome Difficulties11 Tips On Problem Solving Skills – Overcome Difficulties
11 Tips On Problem Solving Skills – Overcome Difficulties
 
Problem solving& Decision Making
Problem solving& Decision MakingProblem solving& Decision Making
Problem solving& Decision Making
 
Problem solving method
Problem solving methodProblem solving method
Problem solving method
 
The statement of the problem
The statement of the problemThe statement of the problem
The statement of the problem
 
Problem Solving Method
Problem Solving MethodProblem Solving Method
Problem Solving Method
 
Problem solving & decision making at the workplace
Problem solving & decision making at the workplaceProblem solving & decision making at the workplace
Problem solving & decision making at the workplace
 
Problem solving ppt
Problem solving pptProblem solving ppt
Problem solving ppt
 
Problem Solving and Decision Making
Problem Solving and Decision MakingProblem Solving and Decision Making
Problem Solving and Decision Making
 
Problem solving
Problem solvingProblem solving
Problem solving
 
Problem Solving PowerPoint PPT Content Modern Sample
Problem Solving PowerPoint PPT Content Modern SampleProblem Solving PowerPoint PPT Content Modern Sample
Problem Solving PowerPoint PPT Content Modern Sample
 
PROBLEM SOLVING POWERPOINT
PROBLEM SOLVING POWERPOINT PROBLEM SOLVING POWERPOINT
PROBLEM SOLVING POWERPOINT
 
How to write a statement problem
How to write a statement problemHow to write a statement problem
How to write a statement problem
 

Similar to Introduction to problem solving in c++

Programs_Problem_Solving_Algorithms.ppt
Programs_Problem_Solving_Algorithms.pptPrograms_Problem_Solving_Algorithms.ppt
Programs_Problem_Solving_Algorithms.pptmalik681299
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing TechniquesAppili Vamsi Krishna
 
Pj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentalsPj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentalsSasidharaRaoMarrapu
 
Itc lec5-24+sep+2012
Itc lec5-24+sep+2012Itc lec5-24+sep+2012
Itc lec5-24+sep+2012Rehan Qadri
 
Programming_Lecture_1.pptx
Programming_Lecture_1.pptxProgramming_Lecture_1.pptx
Programming_Lecture_1.pptxshoaibkhan716300
 
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
 
Algo_Lecture01.pptx
Algo_Lecture01.pptxAlgo_Lecture01.pptx
Algo_Lecture01.pptxShaistaRiaz4
 
Unit 1 program development cycle
Unit 1 program development cycleUnit 1 program development cycle
Unit 1 program development cycleDhana malar
 
Part 1.ppt
Part 1.pptPart 1.ppt
Part 1.pptRAJESH S
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)praveena p
 
2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life CycleFrankie Jones
 
Program design and problem solving techniques
Program design and problem solving techniquesProgram design and problem solving techniques
Program design and problem solving techniquesDokka Srinivasu
 

Similar to Introduction to problem solving in c++ (20)

Programs_Problem_Solving_Algorithms.ppt
Programs_Problem_Solving_Algorithms.pptPrograms_Problem_Solving_Algorithms.ppt
Programs_Problem_Solving_Algorithms.ppt
 
part_1 (1).ppt
part_1 (1).pptpart_1 (1).ppt
part_1 (1).ppt
 
Algorithm.pdf
Algorithm.pdfAlgorithm.pdf
Algorithm.pdf
 
Ch02
Ch02Ch02
Ch02
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
 
L1
L1L1
L1
 
Pj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentalsPj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentals
 
PPS_Unit 1.pptx
PPS_Unit 1.pptxPPS_Unit 1.pptx
PPS_Unit 1.pptx
 
Itc lec5-24+sep+2012
Itc lec5-24+sep+2012Itc lec5-24+sep+2012
Itc lec5-24+sep+2012
 
Programing Fundamental
Programing FundamentalPrograming Fundamental
Programing Fundamental
 
Lecture1
Lecture1Lecture1
Lecture1
 
Programming_Lecture_1.pptx
Programming_Lecture_1.pptxProgramming_Lecture_1.pptx
Programming_Lecture_1.pptx
 
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
 
Algo_Lecture01.pptx
Algo_Lecture01.pptxAlgo_Lecture01.pptx
Algo_Lecture01.pptx
 
Unit 1 program development cycle
Unit 1 program development cycleUnit 1 program development cycle
Unit 1 program development cycle
 
Part 1.ppt
Part 1.pptPart 1.ppt
Part 1.ppt
 
Unit no_1.pptx
Unit no_1.pptxUnit no_1.pptx
Unit no_1.pptx
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)
 
2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle
 
Program design and problem solving techniques
Program design and problem solving techniquesProgram design and problem solving techniques
Program design and problem solving techniques
 

More from Online

Philosophy of early childhood education 3
Philosophy of early childhood education 3Philosophy of early childhood education 3
Philosophy of early childhood education 3Online
 
Philosophy of early childhood education 2
Philosophy of early childhood education 2Philosophy of early childhood education 2
Philosophy of early childhood education 2Online
 
Philosophy of early childhood education 1
Philosophy of early childhood education 1Philosophy of early childhood education 1
Philosophy of early childhood education 1Online
 
Philosophy of early childhood education 4
Philosophy of early childhood education 4Philosophy of early childhood education 4
Philosophy of early childhood education 4Online
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++Online
 
Functions
FunctionsFunctions
FunctionsOnline
 
Formatted input and output
Formatted input and outputFormatted input and output
Formatted input and outputOnline
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selectionOnline
 
Control structures repetition
Control structures   repetitionControl structures   repetition
Control structures repetitionOnline
 
Optical transmission technique
Optical transmission techniqueOptical transmission technique
Optical transmission techniqueOnline
 
Multi protocol label switching (mpls)
Multi protocol label switching (mpls)Multi protocol label switching (mpls)
Multi protocol label switching (mpls)Online
 
Lan technologies
Lan technologiesLan technologies
Lan technologiesOnline
 
Introduction to internet technology
Introduction to internet technologyIntroduction to internet technology
Introduction to internet technologyOnline
 
Internet standard routing protocols
Internet standard routing protocolsInternet standard routing protocols
Internet standard routing protocolsOnline
 
Internet protocol
Internet protocolInternet protocol
Internet protocolOnline
 
Application protocols
Application protocolsApplication protocols
Application protocolsOnline
 
Addressing
AddressingAddressing
AddressingOnline
 
Transport protocols
Transport protocolsTransport protocols
Transport protocolsOnline
 
Leadership
LeadershipLeadership
LeadershipOnline
 
Introduction to management
Introduction to managementIntroduction to management
Introduction to managementOnline
 

More from Online (20)

Philosophy of early childhood education 3
Philosophy of early childhood education 3Philosophy of early childhood education 3
Philosophy of early childhood education 3
 
Philosophy of early childhood education 2
Philosophy of early childhood education 2Philosophy of early childhood education 2
Philosophy of early childhood education 2
 
Philosophy of early childhood education 1
Philosophy of early childhood education 1Philosophy of early childhood education 1
Philosophy of early childhood education 1
 
Philosophy of early childhood education 4
Philosophy of early childhood education 4Philosophy of early childhood education 4
Philosophy of early childhood education 4
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++
 
Functions
FunctionsFunctions
Functions
 
Formatted input and output
Formatted input and outputFormatted input and output
Formatted input and output
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selection
 
Control structures repetition
Control structures   repetitionControl structures   repetition
Control structures repetition
 
Optical transmission technique
Optical transmission techniqueOptical transmission technique
Optical transmission technique
 
Multi protocol label switching (mpls)
Multi protocol label switching (mpls)Multi protocol label switching (mpls)
Multi protocol label switching (mpls)
 
Lan technologies
Lan technologiesLan technologies
Lan technologies
 
Introduction to internet technology
Introduction to internet technologyIntroduction to internet technology
Introduction to internet technology
 
Internet standard routing protocols
Internet standard routing protocolsInternet standard routing protocols
Internet standard routing protocols
 
Internet protocol
Internet protocolInternet protocol
Internet protocol
 
Application protocols
Application protocolsApplication protocols
Application protocols
 
Addressing
AddressingAddressing
Addressing
 
Transport protocols
Transport protocolsTransport protocols
Transport protocols
 
Leadership
LeadershipLeadership
Leadership
 
Introduction to management
Introduction to managementIntroduction to management
Introduction to management
 

Recently uploaded

Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Celine George
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptxmary850239
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptxmary850239
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 

Recently uploaded (20)

Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 

Introduction to problem solving in c++

  • 2. Introduction • Algorithm – A sequence of precise instructions that leads to a solution • Program – An algorithm expressed in a language the computer can understand 2
  • 4. Introduction (cont.) • Programming is a creative process – No complete set of rules for creating a program 4
  • 5. Programming Process • Program Design Process – Problem Solving Phase • Result is an algorithm that solves the problem – Implementation Phase • Result is the algorithm translated into a programming language • Be certain the task is completely specified – What is the input? – What information is in the output? – How is the output organized? 5
  • 6. Programming Process (cont.) • Develop the algorithm before implementation – Experience shows this saves time in getting your program to run. – Test the algorithm for correctness 6
  • 7. Programming Process (cont.) Implementation Phase • Translate the algorithm into a programming language • Compile the source code – Locates errors in using the programming language • Run the program on sample data – Verify correctness of results • Results may require modification of the algorithm and program 7
  • 9. Programming Process (cont.) Example: • STEP 1: PROBLEM ANALYSIS – Purpose: • To describe in details a solution to a problem by providing the needed information for the problem. – How? • First, understand & study the problem. – Identify: • The input to the problem. • The required output. • The relevant process. For example, scientific formula or appropriate theories if any. 9
  • 10. Programming Process (cont.) Problem : Write a program that get 3 numbers as input from user. Find the average and display the numbers and the average. Problem Analysis: Input: 3 numbers. Process: 1. Add the numbers 2. Divide the total with 3 Output: The 3 numbers and average 10
  • 12. Programming Process - Representation Method • STEP 2: PROGRAM DESIGN • Definition: It defines the framework or the flow or the problem solution 1. Algorithm – Algorithm is a sequence of instructions to solve a problem written in human language and problem can be solved if follow the correct procedure – A programmer writes the solution in the form of an algorithm before coding it into computer language. 12
  • 13. Programming Process - Representation Method (cont.) Example of algorithm to calculate the average of 3 numbers: 1. Set Total=0, average=0; 2. Input 3 numbers 3. Total up the 3 numbers Total= total of 3 numbers 4. Calculate average average=Total/3 5. Display 3 numbers and the average 13
  • 14. Programming Process - Representation Method (cont.) 2. Flowchart • A graphical representation of data, information and process or an orderly step- by-step solution to a problem. 14
  • 15. Programming Process - Representation Method (cont.) Start Example: Input a, b, c Total = a + b + c average = Total / 3 Display a, b, c Display average End 15
  • 16. Programming Process - Representation Method (cont.) 3. Pseudocode • Steps in problem solving written in certain of programming code and certain in human language. • For example, some part use C++ language code and some part use English-like phrases. 16
  • 17. Programming Process - Representation Method (cont.) START INPUT a, b, c Total = a + b + c average = Total / 3 OUTPUT a, b, c OUTPUT average END 17
  • 18. Programming Process - Representation Method (cont.) STEPS 3: PROGRAM CODING • Definition: Write a solution into a specific programming language such as C, C++, COBOL and etc. • Solution: Instructions before it is coded into programming language. • Purpose: To produce a program to develop a system. 18
  • 19. Solving Everyday Problems • First step in solving a problem: analyze it – E.g., problem of being hungry • Next, you plan, review, implement, evaluate, and modify (if necessary) the solution – E.g., if you are still hungry 19
  • 20. Solving Everyday Problems (continued) 20
  • 21. Solving Everyday Problems (continued) 21
  • 22. Creating Computer Solutions to Problems • Analysis tools: IPO charts, pseudocode, flowcharts • To desk-check or hand-trace, use pencil, paper, and sample data to walk through algorithm • A coded algorithm is called a program 22
  • 23. Creating Computer Solutions to Problems (continued) 23
  • 24. Analyzing the Problem • Analyze a problem to: – Determine the goal of solving it • Output – Determine the items needed to achieve that goal • Input • Always search first for the output 24
  • 25. Analyzing the Problem (continued) 25
  • 26. IPO Charts • Use an IPO chart to organize and summarize the results of a problem analysis – IPO: Input, Processing, and Output 26
  • 29. Analyzing the Problem (continued) • First, reduce the amount of information you need to consider in your analysis: 29
  • 30. Analyzing the Problem (continued) • Worse than having too much information is not having enough information to solve problem: 30
  • 31. Analyzing the Problem (continued) • Distinguish between information that is missing and information that is implied: 31
  • 32. Planning the Algorithm • Algorithm: set of instructions that will transform the problem’s input into its output – Record it in the Processing column of the IPO chart • Processing item: intermediate value used by algorithm when processing input into output • Pseudocode is a tool programmers use to help them plan an algorithm – Short English statements 32
  • 33. Planning the Algorithm (continued) 33
  • 34. Planning the Algorithm (continued) • Flowcharts are also used to plan an algorithm – Use standardized symbols – Symbols connected with flowlines – Oval: start/stop symbol – Rectangle: process symbol • Represents tasks such as calculations – Parallelogram: input/output symbol • Represents I/O tasks 34
  • 35. Planning the Algorithm (continued) 35
  • 36. Planning the Algorithm (continued) • A problem can have more than one solution: 36
  • 37. Hints for Writing Algorithms This problem specification is almost identical to the one shown earlier in Figure 2-4 37
  • 38. Hints for Writing Algorithms (continued) You may use a portion of a previous solution to solve current problem 38
  • 40. Desk-Checking the Algorithm (continued) 40
  • 41. Desk-Checking the Algorithm (continued) • Valid data is data that the programmer is expecting the user to enter • Invalid data is data that he or she is not expecting the user to enter • You should test an algorithm with invalid data – Users may make mistakes when entering data 41
  • 42. The Gas Mileage Problem 42
  • 43. The Gas Mileage Problem (continued) • After planning the algorithm, you desk-check it: 43
  • 44. Summary • Problem-solving typically involves analyzing the problem, and then planning, reviewing, implementing, evaluating, and modifying (if necessary) the solution • Programmers use tools (IPO charts, pseudocode, flowcharts) to help them analyze problems and develop algorithms – During analysis, you determine the output and input – During planning, you write the steps that will transform the input into the output 44
  • 45. Summary (continued) • After the analysis and planning, you desk- check the algorithm – Follow each of the steps in algorithm by hand • Coding refers to translating the algorithm into a language that the computer can understand • Before writing an algorithm, consider Source: An Introductionhave already solved a similar whether you to Programming with C++, Fifth Edition problem 45