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

Universal turing coastus
Universal turing coastusUniversal turing coastus
Universal turing coastusShiraz316
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codeshermiraguilar
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compilerIffat Anjum
 
Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm designNahid Hasan
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++Nilesh Dalvi
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer Ashim Lamichhane
 
Problem solving using Computer
Problem solving using ComputerProblem solving using Computer
Problem solving using ComputerDavid Livingston J
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithmsGanesh Solanke
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithmsDr Geetha Mohan
 
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
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsMohamed Loey
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception HandlingMegha V
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction toolsAkhil Kaushik
 

What's hot (20)

Universal turing coastus
Universal turing coastusUniversal turing coastus
Universal turing coastus
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codes
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm design
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer
 
COCOMO MODEL 1 And 2
COCOMO MODEL 1 And 2COCOMO MODEL 1 And 2
COCOMO MODEL 1 And 2
 
C++ ppt
C++ pptC++ ppt
C++ ppt
 
Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
 
COCOMO model
COCOMO modelCOCOMO model
COCOMO model
 
Cyclomatic complexity
Cyclomatic complexityCyclomatic complexity
Cyclomatic complexity
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Problem solving using Computer
Problem solving using ComputerProblem solving using Computer
Problem solving using Computer
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
 
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
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception Handling
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction tools
 

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
 
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 (18)

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
 
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

Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 

Recently uploaded (20)

Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 

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