Introduction to
Programming &
Problem-Solving
Week 1 & 2 Slides
Felix Kwabena Offei
Principles of Programming (Level 300)
Course
Overview &
Expectations
❑ Understanding the core Principles of structured and Objected-
Oriented Programming
❑ Write clean, efficient and error-free code using best practices
❑ Solve real-world problems using algorithms and Data
Structures
❑ Debug, test and optimize programs effectively
❑ Work on group projects and collaborate using version control
systems like Git
Agenda
➢ Course Overview & Expectations
➢ History of Programming: How We got Here
➢ Understanding Algorithms & Flowcharts
➢ Pseudocode: Writing Before Coding
➢ Introduction to a Programming Language
(Python, Java, or C++, depending on university
preference)
History of
Programming
❑ How We Got Here!
❑ Can you think of a day in your life which
goes without problem solving?
Examples of Problem Solving
• Example1: If you are watching a news channel on your TV
and you want to change it to a sports channel, you need to
do something i.e. move to that channel by pressing that
channel number on your remote. This is a kind of problem
solving.
• Example 2: One Monday morning, a student is ready to go
to school but yet he/she has not picked up those books
and copies which are required as per timetable. So here
picking up books and copies as per timetable is a kind of
problem solving.
• Example 3: If someone asks to you, what is time now? So
seeing time in your watch and telling him is also a kind of
problem solving.
• Example 4: Some students in a class plan to go on picnic
and decide to share the expenses among them. So
calculating total expenses and the amount an individual
have to give for picnic is also a kind of problem solving.
Understanding Algorithms & Flowcharts
• Algorithm can be defined as: “A sequence of activities to be
processed for getting desired output from a given input.”
• Webopedia defines an algorithm as: “A formula or set of
steps for solving a particular problem. To be an algorithm, a
set of rules must be unambiguous and have a clear
stopping point”.
• A sequence of activities to be processed for getting desired
output from a given input.
Examples of Algorithms
• Problem 1: Find the area of a Circle of radius r.
Inputs to the algorithm: Radius r of the Circle.
Expected output: Area of the Circle
• Algorithm Solution:
Step1: Read\input the Radius r of the Circle
Step2: Area PI*r*r // calculation of area
Step3: Print Area One
Examples of Algorithms
• Problem 2: Write an algorithm to read two numbers and
find their sum
Inputs to the algorithm: First num1 & Second num2
Expected output: Sum of the two numbers.
• Algorithm Solution:
Step1: Start
Step2: Read\input the first num1.
Step3: Read\input the second num2.
Step4: Sum(num1+num2) // calculation of sum
Step5: Print Sum
Step6: End
Examples of Algorithms
• Problem 3: Convert temperature Fahrenheit to Celsius
Inputs to the algorithm: Temperature in Fahrenheit
Expected output: Temperature in Celsius
• Algorithm Solution:
Step1: Start
Step 2: Read Temperature in Fahrenheit F
Step 3: C 5/9*(F32)
Step 4: Print Temperature in Celsius: C
Step5: End
Types of Algorithms (Control Structures)
• Sequence: exemplified by sequence of statements
place one after the other – the one above or before
another gets executed first.
• Branching (Selection): binary decision based on some
condition. If the condition is true, one of the two
branches is explored; if the condition is false, the
other alternative is taken.
• Loop (Repetition): allows a statement or a sequence
of statements to be repeatedly executed based on
some loop condition. It is represented by the ‘while’
and ‘for’ constructs in most programming languages,
for unbounded loops and bounded loops respectively.
Properties of
algorithm
Donald Ervin Knuth has given a list of
five properties for an algorithm
Properties of Algorithms
• Finiteness: Must terminate after a finite number of
steps
• Definiteness: Each step of an algorithm must be
precisely defined
• Input: Any operation you perform need some
beginning value/quantities associated with different
activities in the operation
• Output: Expects output/result (value/quantities)
• Effectiveness: Any developed/written using basic
operations
Flowchart
Is a diagram which visually presents the flow
of data through processing systems
operations performed and the sequence of
these operations in a system
Flowchart Symbols There are 6 basic symbols commonly used
in flowcharting of assembly language
Programs:
• Terminal,
• Process,
• Input/output,
• Decision,
• Connector
• Predefined Process.
This is not a complete list of all the
possible flowcharting symbols, it is the
ones used most often in the structure of
Assembly language programming
General Rules for flowcharting
1. All boxes of the flowchart are connected with Arrows.
(Not lines)
2. 2. Flowchart symbols have an entry point on the top
of the symbol with no other entry points. The exit
point for all flowchart symbols is on the bottom
except for the Decision symbol.
3. 3. The Decision symbol has two exit points; these
can be on the sides or the bottom and one side.
4. 4. Generally, a flowchart will flow from top to bottom. 6. Subroutines and Interrupt programs have their
However, an upward flow can be shown as long as it own and independent flowcharts.
does not exceed 3 symbols. 7. All flow charts start with a Terminal or
5. 5. Connectors are used to connect breaks in the Predefined Process (for interrupt programs or
flowchart. Examples are: • From one page to subroutines) symbol.
another page. • From the bottom of the page to the 8. All flowcharts end with a terminal or a
top of the same page. • An upward flow of more contentious loop.
then 3 symbols
Examples of Flowcharts
Problem1: Find the Problem 2: Convert Problem3: Flowchart for an
area of a circle of temperature Fahrenheit to algorithm which gets two
radius r. Celsius. numbers and prints sum of
their value
Advantages of using Flowcharts
1) Communication: A Flowchart can be used as a better way of communication of the logic
of a system and steps involve in the solution, to all concerned particularly to the client of
system.
2) Effective analysis: A flowchart of a problem can be used for effective analysis of the
problem.
3) Documentation of Program/System: Program flowcharts are a vital part of a good
program documentation. Program document is used for various purposes like knowing
the components in the program, complexity of the program etc.
4) Efficient Program Maintenance: Once a program is developed and becomes operational
it needs time to time maintenance. With help of flowchart maintenance become easier.
5) Coding of the Program: Any design of solution of a problem is finally converted into
computer program. Writing code referring the flowchart of the solution become easy.
Assignment #01
1) What is an algorithm and Explain need of an
algorithm?
2) Write an algorithm to find average age of a group of
10 players? Explain steps involve in drawing of a
flowchart.
3) What is a Flowchart and explain uses of Flowchart.
4) Draw a flowchart to find the sum of first 100 natural
numbers.
5) Draw a flowchart to find the largest of three numbers
x, y and z.
6) Draw flowchart for the problem of determining prime
number?
Thank you