Chapter 1 - Basic Concepts of Programming
Chapter 1 - Basic Concepts of Programming
Computer Programming
Chapter One
Basic Concepts of Programming
Outline
Basics of Program Development
What is computer programming?
Reasons to study programming
Introduction to Program Development Life Cycle
Problem Analysis
Algorithm Design
Pseudo code
Flowchart
An Overview of Programming Languages and Paradigms
2
Chapter 1
1. Basics of Program Development
Computer Program
Self-contained set of explicit and unambiguous instructions that
tells the computer to perform certain specific tasks.
It tells what to do and How to do it (the driver is a program)
HOW the computer program should determine the operations
to be carried out by the machine in order to solve a particular
problem and produce a specific result.
Computer Programming
Also shortened as Programming/Coding
Skills acquired to design and develop computer programs
The process of writing, testing, debugging, troubleshooting, and
maintaining the source code of computer programs.
Software Development Life Cycle
The overall process of software development
3
Chapter 1
Some of the reasons to study
Cont. . . Computer Programming
The job prospects are great
We are currently living in a world where computers are found nearly everywhere
and most objects are now connected to them
We are living in the digital age and the growth of technology does not seem to be
coming to a stop.
5
Chapter 1
Program Development Life Cycle (2/2)
Also, can be defined as the gap between the existing and the desired situation where problem-
solving will try to fill this gap
7
How to Transform Problems into Solution(s)?
- By means of problem-solving
8
PROBLEM SOLVING AND ANALYSIS
PROBLEM SOLVING
The process of transforming the description of a problem into a solution by using our knowledge of the
problem domain and by relying on our ability to select and use appropriate problem-solving strategies,
techniques, and tools.
Problem analysis
Problem solving
techniques Algorithm design
Coding
9
Cont’d
PROBLEM ANALSYSIS
It is the process of defining a problem and decomposing the
overall system into smaller parts to identify possible inputs,
processes, and outputs associated with the problem. 1- What are the
available data or data
The problem can be easily defined in three questions that represent the input
of the problem? (input)
10
Cont’d
To gain a better understanding of the real-world problem and user needs, and
To propose abstract solutions and also validate it before jumping to the development.
11
ALGORITM DESIGN
What is an algorithm?
It is a set of a well-defined, step-by-step finite set of instructions that specifies a sequence of operations
(procedures) to be carried out in order to solve a specific problem or class of problems
12
Cont’d
Why ALGORITHM?
Algorithm representation?
The most commonly used are;
Narrative (Pseudocode),
Flowcharts
13
Cont’d
Characteristics of an Algorithm
14
Pseudo code and Flowcharts
15
ALGORTIGM REPRESENTATION
A detailed description of
what a computer program
must do, It is a type of diagram that
represents an algorithm,
Expressed in an natural showing the steps as boxes of
language like English and various kinds [ex: rectangles,
mathematical symbols diamonds, ovals], and their
rather than in a order by connecting these with
programming language arrow
16
Flowchart symbols and
usage
17
2.3 Problem-Solving
[Flowchart and Pseudocode]
18
Exercises
Purpose:
- To practice algorithm design using flowcharts and pseudo code.
Outcome:
- Able to demonstrate algorithm design.
Problems:
1. Draw a flowchart for a program that calculates and print the area and the perimeter of a rectangle.
2. Draw the flow chart for a program that calculates the total salary for an employee using the equation: Total_Sal = Salary
+Overtime
3. Draw a flowchart for a program that calculates and prints the sum of the even integers from 2 to 30.
Problem 1 solution: start
Flowchart
Read L, W
Analysis
Input: area = L * W
Length, Width
perimeter = 2 (L+W)
Processing
• Area = length*width
• Perimeter = 2*( length + width) Print area
End
20
Problem 2 solution: start
Flowchart
Processing Total_Sal
Total_Salary = Salary +Overtime = Salary +Overtime
21
• Write a pseudo code and draw a flow chart where
you’ll be required to read a value from the user (e.g.
n) and display the sum of the numbers from 1 upto
n.
• E.g. If n = 5, your output should be 15
• i.e. 1+2+3+4+5 =15
22
Chapter 1
Problem 3 solution:
Pseudo code:
Start the program
Analysis Create a variable to hold
23
Problem 3 solution:
Flowchart
24
Programming Languages and Paradigms
Programming Languages
An artificial language that can be used to control the behavior of a
machine, particularly a computer.
Like natural language (such as Amharic), are defined by syntactic and
semantic rules which describe their structure and meaning respectively.
More specifically programming languages
A set of different category of written symbols that instruct computer
hardware to perform specified operations required by the designer.
It provides a linguistic framework for describing computations.
A set of rules for communicating an algorithm with computer systems
(i.e. it provides a way of telling a computer what operations to perform).
A tool for developing executable models for a class of problem domains.
25
Chapter 1
Programming Languages and Paradigms (cont’d)
Types of Programming Languages
Basically there are two types of programming language.
26
Chapter 1
Programming Languages and Paradigms (cont’d)
27
Chapter 1
Programming Languages and Paradigms (cont’d)
28
Chapter 1
Programming Languages and Paradigms (cont’d)
Programming Paradigms
A style, or “way,” of programming
Describes the way in which a particular computer program should be
written.
Doesn’t refer to specific programming language
Different programming languages are designed to follow a particular
paradigm or may be multiple paradigms.
The major programming paradigms include the following
1. Imperative (Procedural) Programming
2. Logical / Declarative Programming
3. Functional Programming
4. Object-Oriented Programming
• https://www.cs.ucf.edu/~leavens/ComS541Fall97/hw-pages/paradigms/major.html
• https://www.cs.bham.ac.uk/research/projects/poplog/paradigms_lectures/lecture1.html
• https://hackr.io/blog/programming-paradigms
29
Chapter 1
Programming Languages and Paradigms (cont’d)
1. Draw a flowchart for a program that accepts a person’s initial bank balance followed by a sequence
of numbers representing transactions. A positive number represents a credit entry in the account
and a negative number represents a debit entry. The input is terminated by a zero entry. The
program should print the new balance.
2. Draw a flowchart and write a pseudo code for a program that calculates the Zakat, where the user
enter the amount of money then the program show the zakat.
Note: Zakat is not calculated if the amount is less than 1000 S.R
Summary
In this session, we learned and practiced how to transform given computational
problems into solutions. Specifically, mastered;
Analyzing problems
Writing a pseudocode
32
Reading Resources/Materials
Chapter 1, 2 & 3: Problem Solving With C++ [10th
edition, University of California, San Diego, 2018;
Walter Savitch;
33