You are on page 1of 8

12/14/2021

Lecture Outline
SWE1301: Introduction to Problem
Solving and Software Development • Solution Organization Tools
• Problem analysis chart
• Pseudocode
• Algorithm
• Structure of Algorithms
• Flow chart
• UML diagrams
Lecture 03: Solution Planning
Venue : CIT Theatre
Presented by: M. I. Mukhtar

12/14/2021 SWE1301-Problem Solving and Software Development- MIM 2

Function Type of Functions


• Mathematical functions: used in mathematical
• Functions are small sets of instructions that calculations such things as square root, absolute
perform specific tasks and return values. value, or a random

• Functions are used for basic tasks that are used • String functions: used to manipulate string
repeatedly in the problem solving process. variables. For example, joining strings together,
• Each language has a set of functions within it. finding the length of strings.

• The format of a function is : • Conversion functions: used to convert data from


FunctionName (data) one data type to another. For example, converting a
string value to a numeric value.
• The data is listed as part of the function and
are called parameters. • Statistical functions: used to calculate things such
as maximum values and minimum values.
12/14/2021 SWE1301: Problem Solving and Software Development - MIM 3 12/14/2021 SWE1301: Problem Solving and Software Development - MIM 4

1
12/14/2021

Function Example Function Example


Function Definition Example Result
Function Definition Example Result
Mathematical/ Statistical Functions
String Functions
abs(n) Returns absolute value of abs(-4) 4 Length(s) Returns the number Length(‘’Maryam’’) 6
(N) of character in a
sqrt(n) Returns square root of (n) sqrt(4) 2 string
Capitalize() Converts the first Capitalize(“maryaM”) Marya
round(N,n1) Returns the rounded value Round(3.7245, 3.72 character of a string m
of N to the n1 place. 2) to upper case and
lower case to all
max(n1,n2,..) Returns the maximum Max(3,2,10) 10 others
number in the list Conversion Functions
Pow(N, n1) Returns the value of N Pow(4, 2) 16
float(n) Converts an integer (n) float(2) 2.0
raise to the power of n1
to real number
ceil(n) Return the largest integer Ceil (3.22) 4
int(n) Converts a real int(3.55) 3
greater than n
number (n) to integer
12/14/2021 SWE1301: Problem Solving and Software Development - MIM 5 12/14/2021 SWE1301: Problem Solving and Software Development - MIM 6

Expression & Equation Expression & Equation..


• A knowledge of constants and variables, data types, • An equation stores the resultant of an
and of operators is not very valuable until you can use expression in a memory location in the
these concepts to create expressions and equations. computer through the equal sign (=).

• The expression Length * width would be used


• An expression processes the operands, through the as part of an instruction in the equation:
use of operators. Example:
Length * width
Area = Length * width
• An equation stores the resultant of an expression in a
memory location in the computer through the equal • The resultant of the expression Length * width
sign (=). Example: would then be stored in a memory location
Area = Length * width called Area
SWE1301: Problem Solving and Software
Development - MIM

12/14/2021 7 12/14/2021 SWE1301: Problem Solving and Software Development - MIM 8

2
12/14/2021

Computer Expression Examples


• Sometimes a programmer has to modify an • Convert the following expression into computer
expression into a format supported by form
computer. Examples:

Numeric Expression
Computer Expression

Relational expression X is less than Y + 5


Computer Expression X < (Y + 5)

12/14/2021 SWE1301: Problem Solving and Software Development - MIM 9 12/14/2021 SWE1301: Problem Solving and Software Development - MIM 10

Solution Planning Solution Organization Tools


• The efficiency of the computer relies on the • Certain tools will help you learn to give
effectiveness of the programmer. instructions and solve problems on the computer.
• The computer must be told what to do.
• They include; Problem Analysis Chart (PAC),
• The solution will be most effective if the pseudocode, Algorithms, flowcharts, structure
programmer follows certain steps and rules that chart or interactivity chart, Coupling Diagram,
have been developed over the years. UML diagrams

• This course will cover the first four.


• There are certain tools that aid programmers in
following those steps and rules. • The remaining e-g will be covered in SWE2301
& SWE2315

12/14/2021 SWE1301-Problem Solving and Software Development- MIM 11 12/14/2021 SWE1301-Problem Solving and Software Development- MIM 12

3
12/14/2021

Mapping tools to problem Solving Steps Problem Analysis Chart (PAC)


• The problem analysis chart is an aid to clear
Step 1, 2,3,4: thinking because it helps the problem solver to
• Identify problem. PAC, identify the essential data and information in a
• Understand problem. Pseudocode, problem and to disregard the nonessentials.
Flowchart
• Identify alternatives ways.
• Choose best way. • A problem is analyzed using the PAC by
separating it into four parts:
• The given data
• The required results
Step 5: • The processing required
Algorithm,
• List the instruction Flowchart • The alternatives

12/14/2021 SWE1301-Problem Solving and Software Development- MIM 13 12/14/2021 SWE1301-Problem Solving and Software Development- MIM 14

Problem Analysis Chart.. Pseudocode


• Pseudocode is an informal high-level description
of a computer program.

• Example Pseudocode for calculating area of a circle:


• Enter the radius and PI
• Calculate Area
• Display Area

• Pseudocode is similar to the algorithm without


the numbers and somewhat condensed.
• algorithm will be treated in the next few slides

12/14/2021 SWE1301-Problem Solving and Software Development- MIM 15 12/14/2021 SWE1301-Problem Solving and Software Development- MIM 16

4
12/14/2021

Algorithms Algorithms…
• Algorithms are sets of instructions for the • Writing incorrect instructions to the computer
computer. will lead to either of the following:
• an error message,
• An Instruction is an order given to a computer • wrong answer,
processor by a computer program. • no answer at all.
• Computer programs are written by a computer
programmer.

• Although a set of instructions must be in a


• The differences between an instruction in one correct order to lead to the correct result, there
computer language or application and another is may be several “correct’’ order.
in the Syntax.
• Syntax refers to the rules governing the computer
operating system, the language, and the application.

12/14/2021 SWE1301-Problem Solving and Software Development- MIM 17 12/14/2021 SWE1301-Problem Solving and Software Development- MIM 18

Algorithms… Algorithms…
• Algorithm is defined as an unambiguous and • Setting up the algorithms is probably the
precise set of steps for solving a problem (or hardest part of problem solving on the computer
sub-problem) in a predetermined amount of because;
time using a finite amount of data.
• Algorithm refers to the sequence of • The instructions cannot assume anything,
instructions that must be followed to solve a cannot skip steps, must be in the correct
problem. order, must be executable one step at a
time, and must be complete.
• Algorithms are generally created independent of
underlying languages: • If the instructions are not properly ordered,
• an algorithm can be implemented in more the computer will, nevertheless, execute
than one programming language. them in the order given, and the result will
• For each problem or class of problems, there be wrong.
may be many different algorithms.
12/14/2021 SWE1301-Problem Solving and Software Development- MIM 19 12/14/2021 SWE1301-Problem Solving and Software Development- MIM 20

5
12/14/2021

Properties of Algorithms… Good Algorithms…


• Input: A number of quantities are provided to an • A good algorithm should be:
algorithm initially before the algorithm begins.
• Simple: An algorithm should not have no
• Definiteness: Each step must be clear and Unnecessary steps and no unnecessary
unambiguous. complexity

• Effectiveness: Each step must be carried out in • Complete account for all inputs & cases
finite time.
• Precise: An algorithm should provide only one
• Output: An algorithm must have output. way to interpret the instruction.

• Correctness: Correct set of output values must


be produced from the each set of inputs.
12/14/2021 SWE1301-Problem Solving and Software Development- MIM 21 12/14/2021 SWE1301-Problem Solving and Software Development- MIM 22

Structures of Algorithms Flowchart


• From the algorithms the programmer develops
• The sequential structure executes instructions
the flowcharts
one after another in a sequence.
• Flowcharts are graphic representations of the
algorithms.
• The decision structure branches to execute one • flowchart shows the flow of the processing
of two possible sets of instructions. from the beginning to the end of a solution.
• Each block in a flowchart represents one
• The loop structure executes a set of instruction from an algorithm.
instructions many times. • A flowchart will show errors in logic not
readily visible in the other charts.
• There are flowchart symbols for use with
various types of processing.

12/14/2021 SWE1301-Problem Solving and Software Development- MIM 23 12/14/2021 SWE1301-Problem Solving and Software Development- MIM 24

6
12/14/2021

Flowchart Symbols Flowchart Symbols

12/14/2021 SWE1301-Problem Solving and Software Development- MIM 25 12/14/2021 SWE1301-Problem Solving and Software Development- MIM 26

Flowchart Symbols Algorithm & Flowchart


• The algorithms and the flowcharts are the final
steps in organizing a solution to a problem.

• Using them :
• the programmer can test the solution for bugs
(desk checking).
• the programmer can go on to code the problem
into a computer language for entry into the
computer.
• The programmer is ready to move to step 6 of the
problem solving step.
Step 6: Coding
• Evaluate the solution &
Testing

12/14/2021 SWE1301-Problem Solving and Software Development- MIM 27 12/14/2021 SWE1301-Problem Solving and Software Development- MIM 28

7
12/14/2021

Coding Testing
• Coding is the act of writing the solution of the • When a solution is complete, it is important to
problem into a computer solution. test it to make sure no errors in logic or in the
setup of the expressions and equations.
• If the programmer follows the proper steps in • This can be carried out manually before
developing the solution, there should be few coding—Desk Checking
logic errors in the program, and the testing and
coding should go quickly. • To test a solution, the programmer selects test
data, a set of values for the input data, and
• Most syntax errors can be from works them through every step in the solution.
misunderstanding of the original problem.
• It is important to select test data carefully, so
the correctness of the results can be checked
with as much accuracy as possible.
12/14/2021 SWE1301-Problem Solving and Software Development- MIM 29 12/14/2021 SWE1301-Problem Solving and Software Development- MIM 30

Lecture Summary
• The efficiency of the computer relies on the
effectiveness of the programmer or the user.

• The programmer must write solutions that are


clear, organized, and correct.

• Certain organizational tools help programmers


Questions??
to learn how to solve problems on the computer.

12/14/2021 SWE1301-Problem Solving and Software Development- MIM 31 12/14/2021 SWE1301-Problem Solving and Software Development- MIM 32

You might also like