[go: up one dir, main page]

0% found this document useful (0 votes)
11 views12 pages

Programming Chapter 1 Part1

The document provides an introduction to computer programming, covering the basics of computers, programming languages, and the roles of hardware and software. It explains the different levels of programming languages (machine, assembly, and high-level), the process of program translation, and the Software Development Life Cycle (SDLC). Additionally, it discusses algorithm development, representation methods like pseudo-code and flowcharts, and basic control structures in programming.

Uploaded by

somsonengda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views12 pages

Programming Chapter 1 Part1

The document provides an introduction to computer programming, covering the basics of computers, programming languages, and the roles of hardware and software. It explains the different levels of programming languages (machine, assembly, and high-level), the process of program translation, and the Software Development Life Cycle (SDLC). Additionally, it discusses algorithm development, representation methods like pseudo-code and flowcharts, and basic control structures in programming.

Uploaded by

somsonengda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Fundamental of Computer Programming YEAR 2024

Chapter One: Introduction to Programming


1.1. General introduction to computer and programming
Computer is a machine that performs a variety of tasks according to specific instructions. It is a
data processing machine which accepts data via an input device and its processor manipulates the
data according to a program. The computer has two major components. The first one is the
hardware which is the tangible part of the computer. It is composed of electronic and mechanical
parts. The second major component is the software which is the intangible part of a computer. It
consists of data and the computer programs. Computers do what we tell them to do NOT what
we want them to do.

Computer Programming involves writing instructions and giving them to the computer to
complete a task. A computer program or software is a set of instructions written in a
computer language in order to be executed by a computer to perform a useful task.
Ex: Application software packages, such as word processors, spreadsheets and databases are
all computer programs
Computer Programmer is a person who translates the task you want a computer to do into
a form that a computer can understand.
Programming language refers to a series of specifically defined commands designed by human
programmers to give directions to digital computers. It is a means of communication between a
human being (programmer) and a computer. A programmer uses this means of communication in
order to give the computer instructions. A programming language is an artificial language that
can be used to control the behavior of a machine, particularly a computer. Programming
languages, like human languages, are defined through the use of syntactic and semantic rules, to
determine structure and meaning respectively. Programming languages differ from natural
languages in that natural languages are only used for interaction between people, while
programming languages also allow humans to communicate instructions to machines.

All programming language instructions must be expressed in binary code before the computer
can perform them.

Page 1 of 12
Fundamental of Computer Programming YEAR 2024

Chapter One: Introduction to Programming


1.2. Levels of programming languages
A programming language is used by a human programmer to direct a computer to accomplish a
specific set of steps which lead to a desired outcome. Programming languages can be divided
into three major groups. They are: machine, assembly, and high-level.
1. Machine language: - is the lowest level programming language in which all instructions and
data are written in a binary machine code, i.e. 0s and 1s.
Characteristics:
 It is fast
 It is not easy to learn
 It is machine dependent
2. Assembly language: - is a low level programming language that uses abbreviations rather than
binary code. It is English-like abbreviations representing elementary computer operations
(ADD, MUL…).
Characteristics:
 It is faster to write instruction than machine language
 It is slower than machine language, because it needs language translator program
(assembler).
 It is not easy to remember (learn).
3. High level programming language: - allow programmer to write a program in a familiar
notation (English like statement). It is also called procedural language, i.e. programmer set
the precise procedures or sets of instruction. Example: FORTRAN, Basic, C++, Pascal, Java
.PHP etc. Characteristics:
 It is not machine dependent
 It is easy to understand
 It is slow

Page 2 of 12
Fundamental of Computer Programming YEAR 2024

Chapter One: Introduction to Programming


1.3. Program translation
All programs must be translated before their instructions can be executed. Computer translation
languages can be grouped according to which translation process is used to convert the
instructions into binary code:
 Assemblers
 Interpreters
 Compilers

Assembler: a program used to translate Assembly language programs into machine language. It
produces one line of binary code per original program statement. The entire program is
assembled before the program is sent to the computer for execution.

Program in
Program in
Assembly Assembler Machine
language language

Interpreter: A program used to translate high-level programs into machine understandable


form. It translates one line of the program into binary code at a time.

Compiler: a program used to translate high-level programs. It translates the entire program into
binary code before anything is sent to the CPU for execution.

Program in
High level Program in
language Compiler Machine
language

1.4. SDLC (Software Development Life Cycle)


As with most undertakings, planning is an important factor in determining the success or failure
of any software project. Most professional software developers plan a software project using a

Page 3 of 12
Fundamental of Computer Programming YEAR 2024

Chapter One: Introduction to Programming


series of steps generally referred to as the software development life cycle (SDLC). SDLC of a
given system usually involves:
 Problem investigation/identification
 System analysis
 System design
 System implementation and
 System Maintenance
You should realize, however, that all of the activities involved are highly related and interdependent.
Therefore, in actual practice, several developmental activities can occur at the same time.

The table below (table 1.1) shows the detail of activities performed in each of the above mentioned steps.

Step Jobs to be done Product

 Determine whether a business problem


or opportunity exists
 Conduct a feasibility study to determine
System/problem Investigation whether a new or improved information Feasibility study report
system is a feasible solution
 Develop a project management plan and
get management approval.

 Analyze the information needs of end


users, the organizational environment,
Functional
and any system presently used.
Requirement report
System Analysis  Develop the functional requirement of a
system that can meet the needs of the
end users.
 Develop specifications for the hardware,
software, people, network and data
System specification
resources, and the information products
System Design that will satisfy the functional
requirements of the proposed plan

Page 4 of 12
Fundamental of Computer Programming YEAR 2024

Chapter One: Introduction to Programming


 Acquire (develop) hardware and
software
 Test the system and train people to
System Implementation operate and use it Operational system
 Convert to the new system
 Provide ongoing support
 Use a post implementation review to
System Maintenance Improved and/or fully
monitor, evaluate, and modify the
functional system
system as needed.

Table 1.1 Steps in SDLC

There are two levels of programming.


Low –Level and High-level programming

• Low level language is a language which operators based on 0s and 1s.


• Computers only understand one language and that is binary language or the language of 1s and 0s
• Although the computer easily understood these programs, it proved too difficult for a normal
human being to remember all the instructions in the form of 0s and 1s.
• Examples of low-level programming assembly and machine code

Page 5 of 12
Fundamental of Computer Programming YEAR 2024

Chapter One: Introduction to Programming


High-level languages are more English-like and, therefore, make it easier for programmers to "think" in
the programming language.

• High-level languages also require translation to machine language before execution.


• This translation is accomplished by either a compiler or an interpreter.
• Example, C++, Java, C#, Php
Programming paradigms
• Programming paradigms are a way to classify programming languages based on their features.
There are two main programming paradigms such as procedural and Object-oriented
• Procedural programming specifies a list of operations that the program must complete to reach the
desired state
• Procedures, also known as functions, subroutines, or methods, are small sections of code that
perform a particular function.
• Object-oriented programming is one the newest and most powerful paradigms.
• Everything represents in the form of class and object.
• A program thus becomes a collection of cooperating objects, rather than a list of instructions.
• Objects can store state information and interact with other objects
• OOP principles/concepts

Page 6 of 12
Fundamental of Computer Programming YEAR 2024

Chapter One: Introduction to Programming


1.5. Algorithm development and representation (problem solving)
What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a
problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time.
 It is a list of instructions specifying a precise description of a step by step process
that terminates after a finite number of steps for solving a problem, producing the
correct answer in the end.
 It is a recipe for solving problems.
 A finite set of an instruction that specifies a sequence of operation to be carried out
in order to solve a specific problem.
 An unambiguous procedure specifying a finite number of steps to be taken.
 It is precise and independent of specific programming languages.
 Is a procedure or formula for solving a problem.
Methods of Specifying Algorithm
 Finiteness: - there is an exact number of step to be taken and has an end.
 Correctness: - it must be correct and must solve the problem for which it is
designed.
 Absence of Ambiguity:- means that every instruction is precisely described and
clearly specified.
 Every step in an algorithm must be clear as to what it is to do and how many times
it is expected to be executed.

 Generality:- i.e. it should have to be general.


 Sequence of Execution - instructions are performed from top to bottom.
 Input and Output - defined the unknowns of the problem is specified and with the
expected outcome.
 Effectiveness - the solution prescribed is guaranteed to give a correct answer and
that the specified process is faithfully carried out.
 Scope Definition - applies to a specific problem or class of problem.
 Algorithms are usually represented in pseudo code or by a flow chart.

Page 7 of 12
Fundamental of Computer Programming YEAR 2024

Chapter One: Introduction to Programming


Pseudo code: is English like language for representing the solution to a problem. Pseudo code
is independent of any programming language. Pseudo code (or a flow chart) is the first step in
the process of planning the solution to a problem (also called developing an algorithm).
Flow chart: is a graphical way of representing the solution to a problem. The symbols used in
flow charts are shown in table 1.2 below.

1.5.1. Flow charts


A flowchart is a schematic representation of an algorithm or a process. The advantage of
flowchart is it doesn’t depend on any particular programming language, so that it can used, to
translate an algorithm to more than one programming language. Flowchart uses different
symbols (geometrical shapes) to represent different processes. The following table shows some
of the common symbols.

Symbol Name Meaning


Indicates where the flowchart begins and ends. It shows the
Terminal entry point of your flowchart and the exit point. It is useful to
represent an end result of a flow process.
Indicates an input or output operation
Input/output

Indicates computation or data manipulation. It shows


Process something that has to be done or an action that has to be taken.
The text in the rectangle almost always includes a verb.
Used to connect the flowchart symbols and indicate the logic
Flow lines
flow. The lines with arrows determine the flow through the
chart.
Indicate a program branch point. A decision asks a question.
The answer to the question determines which arrow you
Decision follow out of the decision shape. Decisions can take place at
points where results need to be evaluated before the process
may continue.
Indicates an entry to, or exit from, another part of the flow
Connector
chart

Table 1.2 Symbols used in flow charts


1.5.2. Pseudo-code
Pseudo-code is an alternative to flow charts which uses plain(ish) language, to describe an
Page 8 of 12
Fundamental of Computer Programming YEAR 2024

Chapter One: Introduction to Programming


algorithm. Unlike flow charts, there are no real rules as to how to write pseudo-code, other than
that you need to clearly indent (or bracket) sections of code that belong inside a conditional
statement or loop, and you need to be consistent about the wording you use. No standard for
pseudo code syntax exists, as a program in pseudo code is not an executable program.

The purpose of using pseudo code is that it may be easier for humans to read than conventional
programming languages, and that it may be a compact and environment-independent generic
description of the key principles of an algorithm. Writing pseudo code will save you time later
during the construction & testing phase of a program's development.

Example 1: -Adding two numbers

When you are asked to add numbers, what you know for sure is that addition operation involves
two operands at a given time. The first step is to have the two-operand values. Then we add these

operands and store the result to another operand. This is just a description. To check if this works
lets assume the following.

 Input; - x, y
 Process: Compute the arithmetic sum of the two numbers, put result on variable
 Output: display the sum of two numbers
Flowchart Pseudo code

1. Begin
Start
2. Read X, Y

Read X,Y 3. Calculate Sum

3.1. Formula:
Sum= X+Y Sum=X+Y

4. Display Sum
Display Sum
5. End

Stop
Page 9 of 12
Fundamental of Computer Programming YEAR 2024

Chapter One: Introduction to Programming


Basic Control Structures

In general speaking, the problems in programming can have either of these structures: sequence,
selection and repetition.

 A sequence is a series of statements that execute one after another


 Selection (branch) is used to execute different statements depending on certain conditions.
 Repetition (looping) is used to repeat statements while certain conditions are met.

Page 10 of 12
Fundamental of Computer Programming YEAR 2024

Chapter One: Introduction to Programming


Example 2: Average of three numbers
Flowchart Pseudo code

Start
1. Begin

2. Input a, b, c
Input a,b, c
3. Calculate Sum

Sum= a+b+c 3.1. Formula:

Sum=a+b+c
Average= Sum/3 4. Calculate Average

4.1. Formula:
Display Average
Average=Sum/3

5. Display Average
Stop
6. End

Example 3: larger of two numbers


Flowchart Pseudo code

Start 1. Begin

2. Read a,b
Read a,b
3. If a>b
No Print a
Is a>b
4. Else
Yes
Print b
Print a Print b
5. End

Stop

Page 11 of 12
Fundamental of Computer Programming YEAR 2024

Chapter One: Introduction to Programming

Example 4: sum of the first 10 natural numbers

Flowchart Pseudo code


1. Begin

2. Set Sum=0, N=0


Start
3. Increment N by 1
N=0
4. Calculate sum
Sum=0
Sum= Sum + N
N=N+1
5. While N<10 goto step3

6. Print Sum
Sum=Sum + N
7. End

Yes Exercise
Is N<10
Problem 1: Develop an algorithm to calculate the area of a circle
and display the result.
No
Problem 2: Draw a flowchart to find the smallest of three
numbers A, B and C.
Print Sum
Problem 3: Draw a flow chart to converts the input Fahrenheit
degree into its Celsius degree equivalent. Use the
formula: C= (5/9)*F-32.
Stop
Page 12 of 12

You might also like