SlideShare a Scribd company logo
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

PPTX
Applications of IOT (internet of things)
PPT
Program design and problem solving techniques
PPTX
Algorithm Introduction
PPTX
LISP: Introduction to lisp
PPTX
waveguides-ppt
PPTX
M6 com320 mass_commtheories
PPTX
Algorithm
PPTX
6.essentials of effective communication
Applications of IOT (internet of things)
Program design and problem solving techniques
Algorithm Introduction
LISP: Introduction to lisp
waveguides-ppt
M6 com320 mass_commtheories
Algorithm
6.essentials of effective communication

What's hot (20)

PPTX
Java exception handling
PPT
Functions in C++
PPT
Function overloading(c++)
PPT
Expression evaluation
PPT
Introduction to Compiler design
PPTX
Exception Handling in C++
PPT
Operator Overloading
PPTX
Intro to c++
PDF
Introduction to algorithms
PPT
C by balaguruswami - e.balagurusamy
PPT
Artificial Intelligence 1 Planning In The Real World
PDF
Planning Agent
PPT
Basics of c++ Programming Language
PPTX
Applets in java
PPT
Lecture 5 - Structured Programming Language
PPT
Chapter 2 Representation Of Algorithms 2
PDF
Computer graphics curves and surfaces (1)
PPT
1. over view and history of c
PPTX
Java Notes by C. Sreedhar, GPREC
PDF
Operator Overloading in C++
Java exception handling
Functions in C++
Function overloading(c++)
Expression evaluation
Introduction to Compiler design
Exception Handling in C++
Operator Overloading
Intro to c++
Introduction to algorithms
C by balaguruswami - e.balagurusamy
Artificial Intelligence 1 Planning In The Real World
Planning Agent
Basics of c++ Programming Language
Applets in java
Lecture 5 - Structured Programming Language
Chapter 2 Representation Of Algorithms 2
Computer graphics curves and surfaces (1)
1. over view and history of c
Java Notes by C. Sreedhar, GPREC
Operator Overloading in C++
Ad

Viewers also liked (18)

PPTX
2.1 Understand problem solving concept
PPT
Problem Solving Techniques
PPTX
Problem Solving
PPTX
Introduction to problem solving in C
PDF
1 introduction to problem solving and programming
PPT
Stages of problem solving presentation
PPTX
Problem solving
PDF
11 Tips On Problem Solving Skills – Overcome Difficulties
PPTX
Problem solving method
PPT
The statement of the problem
PPTX
Problem solving & decision making at the workplace
PPT
Problem solving ppt
PPT
Problem Solving and Decision Making
PPSX
Problem solving
PPT
Problem Solving PowerPoint PPT Content Modern Sample
PPT
PROBLEM SOLVING POWERPOINT
PDF
How to write a statement problem
2.1 Understand problem solving concept
Problem Solving Techniques
Problem Solving
Introduction to problem solving in C
1 introduction to problem solving and programming
Stages of problem solving presentation
Problem solving
11 Tips On Problem Solving Skills – Overcome Difficulties
Problem solving method
The statement of the problem
Problem solving & decision making at the workplace
Problem solving ppt
Problem Solving and Decision Making
Problem solving
Problem Solving PowerPoint PPT Content Modern Sample
PROBLEM SOLVING POWERPOINT
How to write a statement problem
Ad

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

PPT
Programs_Problem_Solving_Algorithms.ppt
PPT
part_1 (1).ppt
PDF
Algorithm.pdf
PPT
Ch02
PPT
C programming for Computing Techniques
PPTX
Pj01 1-computer and programming fundamentals
PPTX
PPS_Unit 1.pptx
PPT
Itc lec5-24+sep+2012
PDF
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PPTX
Programming in C - Problem Solving using C
PPT
01SoftwEng.pptInnovation technology pptInnovation technology ppt
PPT
Programing Fundamental
DOCX
Lecture1
PPTX
Programming_Lecture_1.pptx
PPT
C++ programming program design including data structures
PPTX
Data Structures_Introduction to algorithms.pptx
PDF
Lecture one for introducing to c programming for first Year
PPTX
3 Program Development Life Cycle.aaaaapptx
PPTX
Algo_Lecture01.pptx
Programs_Problem_Solving_Algorithms.ppt
part_1 (1).ppt
Algorithm.pdf
Ch02
C programming for Computing Techniques
Pj01 1-computer and programming fundamentals
PPS_Unit 1.pptx
Itc lec5-24+sep+2012
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
Programming in C - Problem Solving using C
01SoftwEng.pptInnovation technology pptInnovation technology ppt
Programing Fundamental
Lecture1
Programming_Lecture_1.pptx
C++ programming program design including data structures
Data Structures_Introduction to algorithms.pptx
Lecture one for introducing to c programming for first Year
3 Program Development Life Cycle.aaaaapptx
Algo_Lecture01.pptx

More from Online (20)

PPT
Philosophy of early childhood education 3
PPT
Philosophy of early childhood education 2
PPT
Philosophy of early childhood education 1
PPT
Philosophy of early childhood education 4
PPT
Operation and expression in c++
PPT
Functions
PPT
Formatted input and output
PPT
Control structures selection
PPT
Control structures repetition
PPT
Optical transmission technique
PPT
Multi protocol label switching (mpls)
PPT
Lan technologies
PPT
Introduction to internet technology
PPT
Internet standard routing protocols
PPT
Internet protocol
PPT
Application protocols
PPT
Addressing
PPT
Transport protocols
PPT
Leadership
PPT
Introduction to management
Philosophy of early childhood education 3
Philosophy of early childhood education 2
Philosophy of early childhood education 1
Philosophy of early childhood education 4
Operation and expression in c++
Functions
Formatted input and output
Control structures selection
Control structures repetition
Optical transmission technique
Multi protocol label switching (mpls)
Lan technologies
Introduction to internet technology
Internet standard routing protocols
Internet protocol
Application protocols
Addressing
Transport protocols
Leadership
Introduction to management

Recently uploaded (20)

PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
O5-L3 Freight Transport Ops (International) V1.pdf
Pharma ospi slides which help in ospi learning
Abdominal Access Techniques with Prof. Dr. R K Mishra
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Cell Structure & Organelles in detailed.
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
2.FourierTransform-ShortQuestionswithAnswers.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Insiders guide to clinical Medicine.pdf
Microbial diseases, their pathogenesis and prophylaxis
O7-L3 Supply Chain Operations - ICLT Program
Microbial disease of the cardiovascular and lymphatic systems
Supply Chain Operations Speaking Notes -ICLT Program
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf

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