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

Chapter 1 - Basic Concepts of Programming

Uploaded by

Ahmed Yassin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Chapter 1 - Basic Concepts of Programming

Uploaded by

Ahmed Yassin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Fundamentals of

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.

 Programming makes things easier for you


 A simple computer program is capable of turning things around as you want.
 For example, if you're using a Smartphone to chat app or switch on/off your
electrical appliances, if you're unlocking your car with the push of a button, then
you must know that all these things are using some kind of program

 Coding develops structured and creative or logical thinking

 Learning to program teaches you persistence

 You’ll learn how to learn and become more detail-oriented


4
Chapter 1
Program Development Life Cycle (1/2)
 Also referred as Software development procedure
 It is a conceptual model that describes the stages involved in a
software development project from an initial phase (planning)
through maintenance of the completed application
 It is scientific method approach and systems approach that used in
science and engineering, and in quantitative analysis respectively

5
Chapter 1
Program Development Life Cycle (2/2)

 Why SDLC? --- reading assignment


6
Chapter 1
Problem Analysis
What is/are Problem(s)?

 Literally It is an undesirable situation that prevents the organization/individuals from fully


achieving its purpose, goals, and objectives.

 Also, can be defined as the gap between the existing and the desired situation where problem-
solving will try to fill this gap

 In a computing world it is called a computational problem which may be solved by an algorithm.

 E.g. a decision problem


– it is a computational problem where the answer for every instance is either yes or
no {"Given a positive integer n, determine if n is prime.“}

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.

 Whereas programming is a process of problem-solving.

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)

2- What is the method or


set of processes that lead
to get the results from the 3-What are the required
available data? (process) results or Output of the
program? (output)

10
Cont’d

GOAL (Why problem analysis?)

 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

 It is independent of any programming language

 Can be described either graphically or in natural language

12
Cont’d
Why ALGORITHM?

 A computer is an “algorithm-responding” machine; it’s not a “heuristic-responding” machine


 You can’t tell a computer do things directly.
 Computer require a detailed, step-by-step set of instructions to perform any activities that collectively
form an algorithm

Algorithm representation?
 The most commonly used are;
 Narrative (Pseudocode),
 Flowcharts

13
Cont’d
Characteristics of an Algorithm

Each instruction should be Must terminate after finite


clear and unambiguous.
number of steps.

Can have fine


number of inputs Should has at least one
(zero or more) well defined output
that matches the
desired result.
Each instruction must be basic
enough to be carried out
(feasible/do able)

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

 Output: Print perimeter


Area, Perimeter

End

20
Problem 2 solution: start
Flowchart

Analysis Read Salary


Read Overtime
 Input:
Salary, Overtime

 Processing Total_Sal
Total_Salary = Salary +Overtime = Salary +Overtime

 Output: Print Total_Sal


Total_Salary
End

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

 Input:  a counter from 2 to 30

No input  the sum.


 Initialize the counter to 2 and the sum to zero.
 Loop While the counter is less-than-or-equal to 30
 Processing
• Sum = 2+4+6+……+28+30  Add the counter to the sum
 add two to the counter.
 Output:  repeat until the counter reach 30

sum  Print the sum.


 End of program

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.

 Generations of Programming Languages

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)

 Brief summary of programming paradigms


No Paradigms Descriptions Example
1 Imperative Programs as statements Program C, C++,
(Procedural) that directly change = algorithms + data Java, PHP,
Programming computed state (datafields) - good for decomposition Python,
Ruby
2 Logical Defines program logic, but Program Prolog,
(Declarative) not detailed control flow = facts + rules SQL, CSS
Programming - good for searching

3 Functional Treats computation as the Program C++, Lisp,


Programming evaluation of mathematical = functions . functions Python,
functions avoiding state - good for reasoning JavaScript
4 Object- Treats data fields as objects Program C++, C#.,
Oriented manipulated through = objects + messages Java, PHP,
Programming predefined methods only - good for modelling Python
30
Chapter 1
More Exercises

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.

Zakat =(2.5/100) * amount.

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

 Constructing flowchart and

 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;

 Chapter 2 & 3: An Introduction to Programming with


C++ (8th Edition), 2016 Cengage Learning; Diane Zak

 Chapter 2: C++ how to program, 10th edition, Global


Edition (2017); P. Deitel , H. Deitel

33

You might also like