You are on page 1of 16

Chapter One: Introduction

Define the Term Computer


A computer is an electronic machine, operating under the control of
instructions stored in its own memory that can accept data, manipulate the data
according to specified rules, produce results, and store the results for future use.
Computers process data to create information. Data is a collection of raw
unprocessed facts, figures, and symbols. Information is data that is organized,
meaningful, and useful. To process data into information, a computer uses
hardware and software. Hardware is the electric, electronic, and mechanical
equipment that makes up a computer. Software is the series of instructions that
tells the hardware how to perform tasks.

Is an electronic device which operates on data, analysis the data and then applies
the instruction to this data in order to perform a particular task.

Computers are automatic, electronic machines that


 accept data & instructions from a user (INPUT)
 store the data & instructions (STORAGE)
 manipulate the data according to the instructions (PROCESSING)
 store &/or output the results to the user (OUTPUT)
Categories of Computers

The six major categories of computers are personal computers, handheld


computers, Internet appliances, mid-range servers, mainframes, and
supercomputers. These categories are based on differences in size, speed,
processing capabilities, and price. A personal computer can perform all of its
input, processing, output, and storage activities by itself. Personal computers
include desktop computers and notebook computers. A desktop computer is
designed so the system unit, input devices, output devices, and any other devices
fit entirely on or under a desk or table. Variations of desktop computers
include tower models (computers with tall and narrow system units that can sit
vertically on the floor), all-in-one computers (less expensive computers that
combine the monitor and system unit into a single device),
and workstations (more expensive and powerful computers designed for work
that requires intense calculation and graphics capabilities).
A notebook computer is a portable personal computer small enough fit on
your lap. Notebook and desktop computers are used at home or in the office to
perform application software-related tasks or to access the Internet. A handheld
computer is a small computer that fits in your hand. Handheld computers can
perform specific, industry-related functions, or can be general-purpose.
A PDA (personal digital assistant) is a handheld computer that provides
personal organizer functions, such as a calendar, appointment book, and notepad.
An Internet appliance is a computer with limited functionality whose main
purpose is to connect to the Internet from home. A mid-range server is more
powerful and larger than a workstation computer. Users typically access a mid-
range server through a personal computer or aterminal, which is a device with a
monitor and a keyboard that usually has no stand-alone processing power.

A mainframe is a large, expensive, very powerful computer that can handle


hundreds or thousands of connected users simultaneously. A supercomputer is
the fastest, most powerful, and most expensive category of computer.
Hardware of Computer

The term hardware refers to the physical components of your computer such as
the system unit, mouse, keyboard, monitor etc.

Computer hardware components include input devices, output devices, a


system unit, storage devices, and communications devices. An input device is any
hardware component that allows a user to enter data and instructions into a
computer. Examples of input devices are the keyboard, mouse, microphone,
scanner, digital camera, and PC camera. An output device is any hardware
component that can convey information to a user. Three commonly used output
devices are a printer, a monitor, and speakers.
The system unit is a box-like case made from metal or plastic that protects
the internal electronic components of the computer from damage. The system
unit contains the central processing unit and memory. The central processing
unit (CPU) is the electronic device that interprets and carries out the basic
instructions that operate the computer and it has ALU(Arithmetic Logic Unit)
where all calculation are performed and operations like comparing takes place
and the Control Unit which controls and directs the operation of the entire
system. It acts like the central nervous system for all the components though, it
does not process any data. Memory is a temporary holding place for data and
instructions.
A storage device records and retrieves data to and from a storage medium.
Six common storage devices are a floppy disk drive, a Zip® drive, a hard disk drive,
a CD-ROM drive, a CD-RW drive, a DVD-ROM drive, and a DVD+RW drive.
A communications device enables computer users to communicate and exchange
items such as data, instructions, and information with another computer.
A modem is a communications device that enables computers to communicate
usually via telephone lines or cable.
Software of Computer
The software is the instructions that make the computer work. Software is held
either on your computer’s hard disk, CD-ROM, DVD or on a diskette (floppy disk)
and is loaded (i.e. copied) from the disk into the computers RAM (Random Access
Memory), as and when required.

There are two categories of computer software: system software and


application software. System software consists of the programs that control the
operations of a computer and its devices. Two types of system software are the
operating system and utility programs. An operating system (OS) coordinates all
activities among hardware devices and contains instructions that allow you to run
application software. A utility program performs specific tasks, usually related to
managing a computer, its devices, or its programs. You interact with software
through its user interface.
Application software consists of programs that perform specific tasks for
users. Popular application software includes word processing software,
spreadsheet software, database software, and presentation graphics software.
Application software can be packaged software (copyrighted software that meets
the needs of a variety of users), custom software (tailor-made software
developed at a user’s request), freeware (copyrighted software provided at no
cost), public-domain software (software donated for public use with no copyright
restrictions), or shareware (copyrighted software distributed free for a trial
period).

Operating System
The operating system is a special type of program that loads automatically when
you start your computer. It allows you to use the advanced features of a modern
computer without having to learn all the details of how the hardware works.
Examples: Windows, Linux, Unix and Mac OS, etc.,
An operating system performs basic tasks such as,

 controlling and allocating memory,

 prioritizing system requests,

 controlling input and output devices,

 facilitating networking and

 Managing file systems.


What is programming?
 Programming is a skill that can be acquired by a computer professional that
gives him/her the knowledge of making the computer perform the
required operation or task.

Why do we need to learn computer programming?


 Computer Programming is critical if one wants to know how to make
the computer perform a task. Most users of a computer only use the
available applications on the computer. These applications are
produced by computer programmers. Thus if someone is interested to
make such kind of applications, he/she needs to learn how to talk to
the computer, which is learning computer programming.

What is programming language?


 Programming Language: is a set different category of written symbols that
instruct computer hardware to perform specified operations
required by the designer.

In every programming Language there are sets of rules that govern the symbols
used in a programming language. These set of rules determine how
the programmer can make the computer hardware to perform a specific
operation. These sets of rules are called syntax.

1.1. Generations of programming languages


 Programming languages are categorized into five generations: (1st, 2nd, 3rd,
4th and 5th generation languages)
 These programming languages can also be categorized into two broad
categories: low level and 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.
From the five categories of programming languages, first and second generation
 Languages are low level languages and the rest are high level programming
languages.
 The higher the level of a language, the easier it is to understand and use by
programmers.
 Languages after the fourth generation are referred to as very high level
languages.

1.1.1. First Generation (Machine languages, 1940's):


 Difficult to write applications with.
 Dependent on machine languages of the specific computer being used.
 Machine languages allow the programmer to interact directly with the
hardware, and it can be executed by the computer without the need for a
translator.
 Is more powerful in utilizing resources of the computer.
 Gives power to the programmer.
 They execute very quickly and use memory very efficiently.

1.1.2. Second Generation (Assembly languages, early 1950's):


 Uses symbolic names for operations and storage locations.
 A system program called an assembler translates a program written in
assembly language to machine language.
 Programs written in assembly language are not portable. i.e., different
computer architectures have their own machine and assembly languages.
 They are highly used in system software development.

1.1.3. Third Generation (High level languages, 1950’s to 1970’s):


 Uses English like instructions and mathematicians were able to define
variables with statements such as Z = A + B
 Such languages are much easier to use than assembly language.
 Programs written in high level languages need to be translated into machine
language in order to be executed.
1.1.4. Fourth Generation (since late 1970’s):
 Have a simple, English like syntax rules; commonly used to access databases.
 Fourth generation languages are non-procedural languages.
 The non-procedural method is easier to write, but you have less control over
how each task is actually performed.
 In non-procedural languages the programmer is not required to write
traditional programming logic. Programmers concentrate on defining the
input and output rather than the program steps required.
 For example, a command, such as LIST, might display all the records in
a file on screen, separating fields with a blank space. In a procedural
language, all the logic for inputting each record, testing for end of file
and formatting each column on screen has to be explicitly
programmed.
 Fourth generation languages have a minimum number of syntax rules. This
saves time and free professional programmers for more complex tasks.
 Some examples of 4GL are structured query languages (SQL), report
generators, application generators and graphics languages.

1.1.5. Fifth Generation (1990’s):


 These are used in artificial intelligence (AI) and expert systems; also used for
accessing databases.
 5GLs are “natural” languages whose instruction closely resembles human
speech.
 5GLs require very powerful hardware and software because of the
complexity involved in interpreting commands in human language.
Programming and Problem Solving

1.1. Programming Languages

Programming Language is a set of rules, symbols, and special words used to construct a
computer program. Programming language rules consists of:
 Rules of Syntax which specify how valid instructions are written in the language.
 Rules of Semantics which determine the meaning of the instructions (what the
computer will do).
Computer Programs vary in size from very small to extremely large. Programming
languages are categorized into three main types, these are:
 Machine languages
 Assembly languages
 High level languages(HLL)
1. Machine Language: is a low level language in which its instructions are string of binary
representation that a computer's hardware can perform.
e.g. 00000000 100101 0100 1000 0100 1001
2. Assembly Language: it is also a low-level programming language in which a mnemonic or
a symbol is used to represent each of the machine language instructions for a specific
computer. Assembly language programs also allow the user to use text names for data
rather than having to remember their memory addresses. The Assembly language is
translated into the machine language through an Assembler.

Table 1.1: Examples of Machine language and Assembly language


3. High Level Language: The codes in HLL are similar to everyday English, closer to standard
notations and it uses mathematical notations. e.g. C++, Basic, Fortran, Cobol. The High Level
Language is translated to Machine language through Compilers.

Table 1.2 Examples of Assembly language and High level language

1.2. Program Development

Program Development involves creating and executing a program. To create and


execute a program, three environments need to be invoked:
 The Editor environment, to create the program source code
 The Compilation environment, to convert a source program into a machine language
 The Execution environment, to run the program
A program consists of a set of instructions written by the programmer. Normally a high
level language (such as C, C++, Pascal, FORTRAN,…) is used to create a plain-text source code.

1.3. Problem Solving Approach

Problem Solving with a computer involves developing computer programs which are
very complex and creating large programs may include making millions of individual
decisions. Therefore problem solving with computers involves several steps
1. Clearly define the problem.
2. Analyze the problem and formulate a method to solve it
3. Describe the solution in the form of an algorithm.
4. Draw a flowchart of the algorithm.
5. Write the computer program.
6. Compile and run the program (debugging).
7. Test the program (debugging)
8. Interpretation of results.
1.4. Verification and Validation

If the program has an important application, for example to calculate student grades or
guide a rocket, then it is important to test the program to make sure it does what the
programmer intends it to do and that it is actually a valid solution to the problem. The tests are
commonly divided as follows:
Verification: verify that program does what you intended it to do; steps 7(8) above
attempt to do this.
Validation: does the program actual solve the original problem i.e. is it valid? This goes
back to steps 1 and 2 - if you get these steps wrong then your program is not a valid
solution.
1.5. Algorithm

An algorithm is a procedure for solving a problem in terms of the actions to be executed


and the order in which those actions are to be executed. An algorithm is merely the sequence of
steps taken to solve a problem. There are two commonly used tools to help to document an
algorithm. These are flowcharts and Pseudocode. We will use both methods here. Generally,
flowcharts work well for small problems but Pseudocode is used for larger problems.

1. Psedocode

Pseudocode is an artificial and informal language that helps programmers develop


algorithms. Pseudocode is very similar to everyday English therefore a person with the English
language knowledge should understand your Pseudocode.
Example 1: Write an algorithm, in psedocode, form that take two numbers and output
the sum of the two numbers.

Algorithm
Step 1: Input two numbers say N1 and N2
Step 2: Calculate the sum N1 + N2
Step 3: out put the sum
Psedocode
Input N1 and N2
Add N1 and N2
Output N1 and N2
Example 2: Write an algorithm to determine a student’s final mark and indicate
whether it is passing or failing. The final mark is calculated as the average of six marks
Algorithm
Step 1: Input the six marks M1, M2, M3, M4, M5, M6
Step 2: Calculate the average of the six marks
Average=( M1, M2, M3, M4, M5, M6 )/ 6
Step 3: Check if the Average is greater than 50.
Step 4: if the average is greater than 50 then print (Output) Pass else i.e. if it is below 50
then print Fail.
Psedocode
Input M1, M2, M3, M4, M5, M6
Calculate Average= (M1, M2, M3, M4, M5, M6)/ 6
If average is below 50
Print “FAIL”
Else
Print “PASS”
Exercise: Write an algorithm and psedocode for the following problems
a. Take a number and calculate the factorial of that number
b. Take a number and prints “odd” if the number is odd otherwise prints “even”
c. Calculate the CGPA of a student. (The student should enter grade for the five
subjects along with the respective credit hour).

2. Flowcharts
A flow chart is the logical flow of the solution in a diagrammatic form, and provides a
plan from which the computer program can be written. The logical flow of an algorithm can
be seen by tracing through the flowchart. Some standard symbols used in the formation of flow
charts are given below.
Flow Chart Symbols

An oval is used to indicate the beginning and end of an algorithm

A parallelogram indicates the input or output of information.


A rectangle indicates a computation, with the result of the
computation assigned to a variable.

A diamond indicates a point where a decision is made.

An arrow indicates the direction of flow of the algorithm. Circles with


arrows connect the flowchart.

Example 1: Write an algorithm, in flow chart form that take two numbers and output
the sum of the two numbers.

Algorithm
Step 1: Input two numbers say N1 and N2
Step 2: Calculate the sum N1 + N2
Step 3: out put the sum
Flow chart
Start

Input N1
Input N2
Psedocode
Input N1 and N2
Add N1 and N2
Sum=N1+N2 Output N1 and N2

Display Sum

End
Example 2: Write an algorithm in flow chart form to determine a student’s final mark
and indicate whether it is passing or failing. The final mark is calculated as the average
of six marks.
Flow chart
Start

Input N1, N2… N6

Average = (N1+N2+N3+N4+N5+N6)/6

No
Is Average >=50

Yes

Output “PASS” Output “PASS”


Psedocode
Input M1, M2, M3, M4, M5, M6
Calculate
Average= (M1, M2, M3, M4, M5, M6)/ 6
If average is below 50
Print “FAIL”
Else
Print “PASS”

End
E.g.3. To take out the sum of even numbers among the numbers from 1 up to a given
number

Start

Ctr=1 Sum=0

Input Num

False Print
Ctr<=Num
Sum

True
End
False
Ctr%2==0
Tru

Ctr=Ctr+1

Sum=Sum+Ctr
Exercise

Write the algorithm in both flowchart and psedocode form

1. Write an algorithm to find the maximum of three numbers a, b, and c ?


2. Write an algorithm that takes a positive integer number and calculates the factorial of
that number?
3. Write an algorithm that adds the number from 1 to 100?

You might also like