0% found this document useful (0 votes)
50 views

Lecture 3

This document provides an overview of programming fundamentals and problem solving concepts. It discusses algorithms, flowcharts, the problem solving process, and examples of writing algorithms and flowcharts to solve problems. Key points covered include defining an algorithm, the advantages of algorithms, flowchart symbols and their uses, comparing algorithms and flowcharts, and the six steps of problem solving - specifying the problem, analyzing it, designing a solution, implementing it, testing it, and maintaining it. Practice problems are provided to write algorithms and flowcharts for problems like finding averages, sums, and areas using these concepts.

Uploaded by

Muneeb Ashraf
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Lecture 3

This document provides an overview of programming fundamentals and problem solving concepts. It discusses algorithms, flowcharts, the problem solving process, and examples of writing algorithms and flowcharts to solve problems. Key points covered include defining an algorithm, the advantages of algorithms, flowchart symbols and their uses, comparing algorithms and flowcharts, and the six steps of problem solving - specifying the problem, analyzing it, designing a solution, implementing it, testing it, and maintaining it. Practice problems are provided to write algorithms and flowcharts for problems like finding averages, sums, and areas using these concepts.

Uploaded by

Muneeb Ashraf
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Programming Fundamentals

Maryam Imtiaz Malik


[email protected]
Example

Problem: Write an algorithm to calculate the sum of first seventy natural numbers.
Solution:
1 Start
2 Sum = 0
3 Num = 0
4 Repeat Step 5 and 6 until (Num < = 70)
5 Sum = Sum + Num
6 Num = Num + 1
7 Display Sum
8 End
Example: Daily Life problems

 Write an algorithm for sending a message to your friend


 Write an algorithm for going to home/hostel from university
Advantages of Algorithm

 Reduced Complexity

 Simplifies the overall task

 Increased Flexibility

 Algorithm can be transformed into any language

 Ease of Understanding

 It is written in an English like manner so easy to understand


Practice Problems

 Write an algorithm to play cricket on Saturday.


Solution:
1. Start
2. Input day
3. if day = “Saturday”
Print “Play Cricket”
4. End
Problem 2

 Write an algorithm to find the average of three numbers.


Solution:
1 Start
2 Enter num1
3 Enter num2
4 Enter num3
5 sum = num1 + num2 + num3
6 avg = sum / 3
7 Display avg
8 End
Problem 3

 Write an algorithm to find square and cube of a number.


Solution:
1 Start
2 Input num
3 square = num * num
4 cube = num * num* num
5 Display square
6 Display cube
7 End
Flowchart

 Flowchart is combination of two words

 flow

 chart

 Graphical representation of an algorithm


Uses of Flowchart

 Used to represent an algorithm in simple graphical manner.


 Used to show the steps of an algorithm in an easy way.
 Used to understand the flow of the program.
Flowchart Symbols
Example: Add two numbers

Start

Enter number1

Enter number2

Result =number1 + number 2

Display Result

End
Example: Calculate distance covered by a car moving at an
average speed of V m/s in time T

Start

Input velocity

Input time

Distance = velocity*time

Display Distance

End
Example: Calculate the sum of first seventy natural numbers

Start

Sum = 0

Num = 0

Num = Num +1

Sum = Sum + Num

NO
IS Num = 70?
YES

Display Sum

End
Algorithm vs Flowchart

Algorithm Flowchart
Simple English is used to write algorithm Standard Symbols are used to design flowchart
Step by step procedure to solve a problem Graphical representation of solution
Less time consuming More time consuming
Easy to modify Difficult to modify
Example: Daily Life problems

 Draw a flow Chart for sending a message to your friend.


 Draw a flow Chart for going to home/hostel from university.
Practice Problems: (Flowchart)

 Play cricket on Saturday


 Find the average of three numbers
 Find sum and cube of a number
Problem Solving Steps

 Programming is a problem-solving activity.


 Software Development Method
1. Specify the problem requirements.
2. Analyze the problem.
3. Design the solutions to solve the problem(develop algorithms).
4. Implement the algorithm(code).
5. Test and verify the completed program.
6. Documentation, maintenance and updating.

If any of these six steps are not completed well, the results may be less than desired.
1. Problem

 State the problem clearly and unambiguously


 Gain a clear understanding of what is required for its solution.
 Eliminate unimportant aspects.
2. Analysis

 Identifying the problem:


 Inputs
 Outputs
 Any additional requirements or constraints

 Determine the required format in which the results should be displayed.


 Develop a list of formulas that specify relationships between them.
 If steps 1 and 2 are not done properly, you will solve the wrong problem.
3. Design

 Design an algorithm

 Top down design


 Breaking a problem into its major sub problems and then solving the sub problems

 Stepwise Refinement
 Development of a detailed list of steps to solve a particular step in the original algorithm
4. Implementation

 Convert each algorithm step into one or more statements in a programming language.
5.Testing

 Detection of errors in the software by providing different values as input and then check
the output.
6. Maintenance

 Modifying a program to remove previously undetected errors and to keep it up-to-date as


government regulations or company policies change.
 Bug Fixing
 Capability Enhancement
 Removal of Outdated Functions
 Performance Improvement
Complete the six problem-solving steps to solve the problems.

 Find the area of rectangle. (lxb)


 Find the area of triangle. √s(s-a)(s-b)(s-c)
Task

 Write algorithms to solve any two problems of your choice.


References

 Gary j. Bronson, A first book of C++, Garry Bronson, 4th edition (Section 1.1 of Chapter 1)
 Maureen Sprankle et al, Problem Solving and Programming Concepts, 9 th Ed. Prentice Hall,
2011. (Chapter 1 + All the related topics of Flowchart and algorithms in book)

You might also like