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

1

Computer Programming

1
INTRODUCTION
Programming? 2
 Programming is a profession
 that involves a skill to convert problem solutions into instructions for the computer.
 Hence, programming involves:
• Problem solving,
• analysis,
• generating algorithms,
• profiling algorithms' accuracy and resource consumption,
• and the implementation of algorithms (referred to as coding).
 Therefore, programming requires:
 knowledge in mathematics and computer science for solving problems, design a solution to a
problem, analyzing solutions and implementing it
A computer 3
 A program is set of instructions for a computer to
execute for solving a specific problem.
 Set of related programs together will make a software.
 In order to write a program (or solve problems
computationally),
 one must understood basic configuration of a
computer.
 A computer has five major components as shown in
the figure below: quite
… 4
 An input device:
 allows a person to communicate information to the computer.
 The primary input devices are likely to be a keyboard and a mouse.
 An output device:
 allows the computer to communicate information to you.
 The most common output device is a display screen, referred to as a monitor.
 Memory:
 computers are provided with memory to store inputs. The program that the computer executes is
also stored in this memory.
 A computer has two forms of memory,
• main memory- provides a random access
• and secondary memory- provides a sequential access.
… 5
 Main memory:
 consists of a long list of numbered locations called memory locations.
 Each memory locations, referred to as bytes can store 8 bits,
 A bit is a smaller unit of memory that can store either 0 or 1.
 Memory locations are identified uniquely using their addresses.
 Memory addresses are expressed using hexa-decimal numbers.
 Secondary memory:
 used for keeping a permanent record of information after (and before) the computer is used.
 Information in secondary storage is kept in units called files.
 Some examples are CDs, DVDs, hard disks and etc.
… 6
 The processor (or CPU) is the “brain” of the computer.
 The processor follows the instructions in a program and performs the calculations specified by the
program.
 The program to a computer:
 must be written in the language that a computer would understand, that language is called
programming language.
 There are three classes of programming languages:
1. High-level programming languages
2. Low-level programming language
3. And assembly programming language.
High-level programming languages 7
 High-level languages resemble human languages in many ways.
 They have vocabulary, grammar and meaning just like human languages.
 High-level languages are designed to be easy for human beings
 to write programs in
 and to be easy for human beings to read.
 A high-level language, such as C++,
 instructions are much more complicated than the simple instructions a computer’s processor
(CPU) is capable of following.
 Therefore, the instructions must be compiled into low-level equivalent instructions by the
compiler.
 A compiler, itself a program,
 translates source codes written in high-level language into equivalent low-level representation called
machine code.
Low-level programming languages 8
 A computer can understand is called a low-level language.
 The exact details of low-level languages differ from one kind of computer to another.
 A typical low-level instruction might be the following:
ADD X Y Z ---- assembly languages.
 The above sample instruction is written in what is called assembly language.
 Although assembly language is almost the same as the language understood by the
computer,
 it must undergo one simple translation before the computer can understand it.
 Programs written in the form of 0s and 1s are said to be written in machine language,
because that is the version of the program that the computer (the machine) actually reads and
follow
0110 1001 1010 1011 ---- low-level languages
Problem solving 9
 The most difficult part of solving a problem on a computer is discovering the method of
solution.
 After you come up with a method of solution,
 it is routine to translate your method into the required language, be it C++ or some other
programming language.
 It is therefore helpful
 to temporarily ignore the programming language
 to concentrate instead on formulating the steps of the solution
 and writing them down in plain English, as if the instructions were to be given to a human being
rather than a computer.
 A sequence of instructions expressed in this way is frequently referred to as an algorithm.
Algorithms 10
 A sequence of precise instructions which leads to a solution is called an algorithm.
 Instructions may be expressed in a programming language or a human language.
 Our algorithms will be expressed in English and in the programming language C++.
 A computer program is simply an algorithm expressed in a language that a computer can understand.
 Thus, the term algorithm is more general than the term program.
 However, when we say that a sequence of instructions is an algorithm, we usually mean that the
instructions are expressed in English.
 Generally, algorithms can be expressed in either:
 Pseudocode- English like statements
 Or Flowchart- diagrammatical descriptions.
Pseudocodes 11
 Pseudocodes are ways of expressing algorithms.
 Pseudocodes uses English like statements to show sequence of instructions for solving a specific
problem.
 Mostly, pseudocode are code like statements
 which cannot be compiled and executed by any computer as it is,
 instead shows the set and order of instructions to be applied in solving a problem.
 Example:
Flowcharts 12
 Uses graphical representation to express algorithms. The commonly used symbols are:

Start/
Process Input/ Output
End

Decision

data flow
… 13
 Example: algorithm to determine whether a number is even or odd integer.
Properties of algorithms 14
 Some properties of algorithms:
 Clear and Unambiguous:
 Each of its steps should be clear in all aspects and must lead to only one meaning.
 Well-Defined Inputs:
 If an algorithm says to take inputs, it should be well-defined inputs. It may or may not take input.
 Well-Defined Outputs:
 It should produce at least 1 output.
 Finite-ness:
 it must have finite number of instructions and it should terminate after a finite time.
 Language Independent:
 it must be just plain instructions that can be implemented in any language, and yet the output will be the
same, as expected.
… 15
 Some properties of algorithms:
 Effectiveness:
 It must produce expected results.
 Efficiency:
 It must require the lowest possible computational resources.

You might also like