You are on page 1of 15

Problem Solving

Problem Solving
2

An Algorithm is a Problem Process of extracting


essential information
finite set of steps
carried out to solve a about a problem is
problem. called abstraction.
Or
A sequence of precise
Abstraction
instructions which A set of instructions
leads to a solution. written in a sequence,
acc. to algorithm, to
Algorithm solve a problem is called
program.

Input Output
Data Computer Solution
Information

11/28/2019
Programming Fundamental-I
For Example
3

 Problem: To develop a software that get two numbers, calculate sum and then displays the result on screen.
 Abstraction
Sum=A+B

 Algorithm
 1. Start
 2. Input A
 3. Input B
 4. Sum=A+B
 5. Display Sum
 6. En
 Computer Program (Code)
 #include<iostream.h>
 void main()
 {
 int A, B, Sum;
 cout<<“Enter the Value of A”;
 cin>>A;
 cout<<“Enter the Value of B”; Compile
 cin>>B; Output
and Run
 Sum-A+B;
 cout<<“The Sum of A and B is: “<<Sum;
 }

Visual Programming 11/28/2019


 All These requirements can be presented
in a Problem Analysis Chart (PAC)

Data Processing Output


given in the List of processing Output
problem or required or requirement.
provided by the procedures.
user
 Example: Payroll Problem
◦ Calculate the salary of an employee who works by
hourly basis. The formula to be used is

Salary = Hour works * Pay rate

Data Processing Output


Hours work, Salary = Hours work * payrate Salary
Pay rate
Write a Problem Analysis Chart (PAC) to convert
the distance in miles to kilometers where 1.609
kilometers per mile.

Data Processing Output


Distance in Kilometers = Distance in
miles 1.609 x miles kilometers
 Write a Problem Analysis Chart (PAC) to find an
area of a circle where area = pi * radius * radius

Data Processing Output


radius area = 3.14 x radius x radius area
 Write a Problem Analysis Chart (PAC) to compute and display
the temperature inside the earth in Celsius and Fahrenheit. The
relevant formulas are
Celsius = 10 x (depth) + 20
Fahrenheit = 1.8 x (Celsius) + 32

Data Processing Output

depth celsius = 10 x (depth) + 20 Display celsius,


fahrenheit = 1.8 x (celsius) + Display
32 fahrenheit
 Write a problem analysis chart (PAC) that asks
a user to enter the distance of a trip in miles,
the miles per gallon estimate for the user’s
car, and the average cost of a gallon of gas.
Calculate and display the number of gallons
of gas needed and the estimated cost of the
trip.
Data Processing Output
distance, gas needed = distance / Display gas needed
miles per gallon, miles per gallon.
cost per gallon Display estimated cost
estimated cost = cost per
gallon x gas needed
What makes a bad program?

 Writing Code without detailed


analysis and design
 Repeating trial and error without
understanding the problem
 Debugging the program line by
line, statement by statement
 Writing tricky and dirty
programs
PROGRAMMER'S
DRINKING SONG!!
100 little bugs in the code,
100 bugs in the code,

fix one bug, compile it again,


101 little bugs in the code.

101 little bugs in the code …


Repeat until BUGS = 0

—The Internet Joke Book


Group Discussions are mandatory for
effective learning!

You might also like