Chapter 1

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 46

Chapter one

Computer Programming (ECEG1052)

05/22/2023 1
What is a Computer? 

♦It is a machine that can store and process information.


♦Most computers rely on a binary system that uses two
variables, 0 and 1, to complete tasks such as
Storing data,
Executing algorithms, and
Displaying information.

05/22/2023 2
Cont..

05/22/2023 3
Basic components of a computer system

♦Five basic components of computer system


 Input Unit.
 Output Unit.
 Storage Unit.
 Central Processing Unit (CPU)
 Arithmetic and Logic Unit (ALU)
 Control Unit.

05/22/2023 4
Cont..
♦Input unit: Obtains information (data and computer progr
ams) from input devices .
♦Output unit: This takes information that the computer has
 processed
♦Memory:
 Stores computer programs while they are being executed. 
♦Central  processing  unit  (CPU):  This  coordinates and
supervises  the  operation  of  the  other  section.
♦Arithmetic and logic unit (ALU): This unit is responsibl
e for performing calculations.
♦ Control Unit: Controls the operation of CPU, hence the
computer.
05/22/2023 5
What is programming?

♦Programming is the process of telling a computer to


do certain function by giving instructions.
♦The instructions are block of codes or programs.
♦A person who writes instruction is computer
programmer (coder or specialist in one area of
computer).
♦He has the ability to create computer software
05/22/2023 6
Why do we need to learn computer programming?

♦To know how the computer performs a task.


♦To use the available applications on the computer.
♦To develop program of computer applications .
♦Improve your efficiency, Start your own business.
♦Improve your understanding of the world.
♦Develop problem solving skills.

05/22/2023 7
What is programming language?

♦It is a set of instruction used to produce various outputs.


♦It is compiled together to perform a specific task by CPU.
♦Are used to create programs  that implement specific
algorithms.

♦Used to express algorithms in computer understandable


form.

05/22/2023 8
What skills do we need to be a programmer?

♦Programming Language Skill: knowing one or more


programming language to talk with the computer and instruct
the machine to perform a task.

♦Problem Solving Skill: skills on how to solve real world


problem and represent the solution in understandable format.

♦Algorithm Development skill: skill of coming up with


sequence of simple and human understandable set of
instructions showing the step of solving the problem.
05/22/2023 9
Generations of programming language

♦ Programming languages can be: low level or high level


languages.

 Low level languages are machine specific or


dependent.

 High level languages like COBOL, BASIC are


machine independent and can run on variety of
computers.

05/22/2023 10
Generations of programming language

Programming Language

Low Level High Level

3rd
1 Generation
st 2 nd
Generation 5th Generation
Generation

4th Generation

05/22/2023 11
.
1 First Generation (Machine languages, 1940’s )

♦Difficult to write applications


♦This is the computer’s native language
♦Used language that the computer really understand only
♦Machine dependent
♦Difficult to program and to modify
♦They used vacuum tubes for the circuitry.
♦For the purpose of memory, they used magnetic drums.

05/22/2023 12
2.Second Generation (Assembly languages, early 1950’s)

♦ Advanced from vacuum tubes to transistors


♦ Use symbolic names for acronym and storage locations. (ADD, DELETE,
UPDATE…)

♦ Are not portable


♦ Computers smaller, faster and more energy efficient
♦ Advanced from binary to assembly languages(assembler).
♦ Highly used in system software development
♦ Difficult to learn than higher levels.
♦ Knowledge of hard ware is required

05/22/2023 13
3. 3rd Generation (High level languages, 1950-
1970)
♦Use English like instruction and includes human language &
mathematical notations
♦ Have different syntax rules and take considerable time to
learn.
♦ Compilers and interpreters are needed for translation
♦They have (common words) which make them easier to learn
♦ Are procedural (It contains a systematic order of statements,
functions and commands to complete a computational task or
program).
♦It  specifies a series of well-structured steps and procedures
within its program.
Example- C, C++, C# , Java and Pascal
05/22/2023 14
4.Fourth Generation (since late 1970’s)
♦Use English like syntax rules, but they are non
procedural (like ordering a meal).
♦Users concentrate on defining the input and output
rather than the program steps required
♦Less control over tasks (you don’t know how each task
is performed)
♦ They need more processing speed.
♦The difference is not that mach form the third
Example: Query languages e.g. SQL

05/22/2023 15
5.Fifth Generation (1990’s)

♦Used in artificial intelligence (AI) and expert systems


♦Used for accessing databases.
♦Resemble more like human speech.
♦Concentrate more on outcome than the process.
♦Example PROLOG, LISP

05/22/2023 16
Problem Solving Using Computers

♦Problems:
 The gap between the existing and the desired situation

 True problem situations, either real or predicted, that


require corrective action.

05/22/2023 17
Problem- Solving

♦Is the process of transforming the description of a problem


into the solution of that problem by using our knowledge.

♦Basic logical process that has been developed and


systemized for the various challenges people face.

05/22/2023 18
There are two approaches of problem solving:
Top-down design:
♦In Top-down Model, the focus is on breaking the bigger problem into
smaller one and then repeat the process with each problem

♦The basic task of a top-down approach is to divide the problem into


tasks and then divide tasks into smaller sub-tasks

♦C programming language  supports this approach for developing


projects.

♦It is always good idea that decomposing solution into modules in


a hierarchal manner.
05/22/2023 19
Top-down Approach

05/22/2023 20
Advantages of Top-Down Approach

♦In this approach, first, we develop and test most important


module.

♦This approach is easy to see the progress of the project by


developer or customer

♦Testing and debugging is easier and efficient.


♦This approach is good for detecting and correcting time
delays
05/22/2023 21
Bottom Up Design

♦Is the reverse process where the lowest level components


are built first

♦The system builds up from the bottom until the whole


process is finally completed

♦This approach is good for reusability of code.


♦C++ used the bottom-up approach for project development

05/22/2023 22
Cont..

05/22/2023 23
Basic Program Development Tips

♦Quality programming is necessary for the economic and


correct solution of problems.

♦The program design should be :


 Reliable: the program should always do what it is
expected to do and handle all types of exceptions.

05/22/2023 24
Cont..
Maintainable: the program should be in a way that it
could be modified and upgraded
Portable: it needs to be possible to adept the software
written for one type of computer to another with
minimum modification
 Efficient: the program should be designed to make
optimal use of time, space and other resources.

05/22/2023 25
Software Engineering

♦Software engineering: provides techniques to facilitate the


development of computer programs.

♦Is the profession that creates and maintains software


applications by applying technologies

05/22/2023 26
Software development method

♦ Preliminary Investigation: is a process of examining


research.
 Defining the problem: (examines documents, work
papers, and procedures, observe system operations,
interview key users of the system). Suggesting a
solution (often improving an existing one or
building a new information system).
 Feasibility study: (determine whether the solution
is possible).

05/22/2023 27
Software development method

 Technical feasibility: whether implementation is


possible with the available or affordable hardware,
software and other technical resources
 Economic feasibility: whether the benefits of the
proposed solution balance the costs
 Operational feasibility: whether the proposed
solution is needed within the existing managerial
and organizational framework.

05/22/2023 28
Software development method

♦Analysis(Requirement Gathering): defines information


requirements like who needs what information, where,
when, and how.
 We identify inputs to the problem, outputs expected from the
solution and Constraints (what are the limits on the data).

♦Design: based on the requirements specified in the analysis


phase algorithms are developed at this stage.

05/22/2023 29
Software development method

♦Implementation: is a process of moving an idea from concept


to reality.
♦Testing: the act of conducting a test.

♦ Maintenance: actions performed to keep some machine or


system in service.
 To correct errors, meet new requirements, or improve processing
efficiency

♦Documentation: that explain the operation of a particular


software program.
05/22/2023 30
Algorithms

♦Is a step by step description of how to arrive at the solution


of the given problem

♦Is the logic of a program


♦A programmer can not write program unless she/he knows
how to solve the problem manually

♦Programs must be planned before they are written


♦Is a step-by-step way to solve a problem
05/22/2023 31
Structure Of Algorithm

♦The algorithm and flowchart have three basic types of


control structures.
Sequence: statements are placed one after the other and
the execution starts from the top.
Branching (Selection) : depending on a condition,
decision of either TRUE or FALSE is achieved.
Loop (Repetition): allows a statement(s) to be
executed repeatedly.
05/22/2023 32
How to Write Algorithms

♦For developing good programs, we should follow the


following procedures.
Identify the input of your algorithm
Define the variables to reserve a space
Outline the algorithm's operations
Output the results of your algorithm's operations

05/22/2023 33
Characteristics of good algorithm
♦Efficient in time and memory
♦Precise and unambiguous
♦Finiteness : An algorithm must always terminate
♦Definiteness : Each step of an algorithm must be precisely
defined.

♦Effectiveness: it should not contain unnecessary steps.


♦ Input Specified: zero or more input required
♦Output Specified: should have at least one output
05/22/2023 34
An algorithm can be expressed in many ways

♦Narrative
♦Structured English
♦Pseudo Code
♦Flow chart
♦Program

05/22/2023 35
Narrative

Can be understood by any user who may not have any


knowledge of computer programming.

Example1: write an algorithm that used to add two


numbers.

Solution : First you must get two numbers to be added ,


then call the first number one & the second number two
then add number one on number two or vice versa & then
print out the result.
05/22/2023 36
Structured English

Get two numbers


Add them up
Print the output

05/22/2023 37
Pseudo code

♦Much similar to real code.


♦We use verbs to write pseudo code.
♦Capitalize important words that show actions

Read num 1, num2


Sum num1, num 2
Print Sum

05/22/2023 38
Flow chart

♦Is a pictorial representation of an algorithm


♦It acts like a roadmap for a programmer

05/22/2023 39
Flow chart symbols

05/22/2023 40
Cont..

05/22/2023 41
Cont..

05/22/2023 42
Program (in C++)

#include<iostream> //for dev++ IDE


using namespace std;
main()
{
int num 1, num 2 , sum=0;
cout << “ enter your first number”;
cin >> num1;
cout << “enter your number 2”;
cin >> num 2;
sum=num1+num2;
cout << sum;
}
05/22/2023 43
Home work
1. Develop flow chart used to find multiplication of two
numbers.
2. Develop flowchart used to find area of circle.
3. Develop flow chart that used to Find the average of two
numbers given by the user.
4. Develop flow chart that check weather the number is even
or not.
5. Find the largest among three different numbers entered by
the user.
6. Develop a flowchart to display the numbers from 1-100.
7. Develop a flow chart that used to find the sum of N
numbers.
05/22/2023 44
! ! !
OU
K Y
A N
T H

05/22/2023 45
Individual Assignment one_10%
1. Develop flowchart used to find the maximum number of
the three numbers.
2. Develop a flow chart that used to find the sum of even
numbers.
3. Take an integer from the user and display the factorial of
that number
4. Draw a flowchart for check a given number is prime or
not.
5. Draw a flowchart to Print Hello World 10 times.
6. Draw a flowchart to log in to Facebook account.
7. Find all the roots of a quadratic equation ax2+bx+c=0
8. Find the Fibonacci series till term≤1000.
05/22/2023 46

You might also like