CP Unit 1
CP Unit 1
com
COMPUTER PROGRAMMING UNIT-1
Computer
Computer can be defined on an electronic device that accept data, process then
at a high speed according to a set of instructions provide to it and produces the desired
output. So computer is a programmable machine.
Generation of computer
Generation means variation between different hardware technologies
st
1 generation: (1946-1956)
First generation computers are made with the use of vacuum tubes. These
computers used machine language for programming.
Disadvantages:
1. Occupied lot of space
2. Consumed lot of power
3. Produced lot of heat
4. Costly system
Example: ENIAC(Electronic numeric integrator and computer)
UNIVAC(Universal Accounting company)
4. Motherboard – A circuit board that allows the CPU to interact with other
parts of the computer.
Because a VGA (analog) connector does not support the use of digital
monitors, the Digital Video Interface (DVI) standard was developed.
LCD monitors work in a digital mode and support the DVI format. At one
time, a digital signal offered better image quality compared to analog
technology. However, analog signal processing technology has improved
over the years and the difference in quality is now minimal.
d. USB Port – Universal Serial Bus. Now used to connect almost all
peripheral devices to the computer. USB 1.1 transmits data at 1.5 Mb/s
at low speed, 12 Mb/s at full speed. USB 2.0 transmits data at 480
Mb/s.
g. Ethernet Port – This port is used for networking and fast internet
connections. Data moves through them at speeds of either 10 megabits
or 100 megabits or 1 gigabit (1,000 megabits) depending on what
speed the network card in the computer supports. Little monitor lights
on these devices flicker when in use.
11. Fan – Keeps your computer cool. If the inside of your computer becomes too
hot, then the computer can overheat and damage parts.
12. Heatsink – Used to disperse the heat that is produced inside the computer by
the CPU and other parts by increasing surface area.
13. The little parts – Capacitors – store energy, Resistors – allows a current
through, Transistors – a valve which allows currents to be turned on or off.
14. Case – (Tower if standing upright.) What your motherboard, CPU, etc is
contained in.
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1
0 0 0 0 0 0 1 0 2
0 0 0 0 0 0 1 1 3
0 0 0 0 0 1 0 0 4
0 0 0 0 0 1 0 1 5
0 0 0 0 0 1 1 0 6
0 0 0 0 0 1 1 1 7
0 0 0 0 1 0 0 0 8
0 0 0 0 1 0 0 1 9
Machine Language:
Only computer can directly understand only its own machine language. Machine
language is the natural language of a particular computer. It is defined by the hardware
design of that computer. This is considered to be the First Generation Language (1GL).
Advantages:
The CPU directly understands machine instructions and hence no translation is
required. Therefore, the computer directly starts execute the machine language
instructions, and it takes less execution time.
Disadvantages:
Difficult to use
Machine dependent
Error prone
Difficult to debug and modify
Assembly Language:
When symbols as letters, digits, or special characters are employed for the
operation, operand and other parts of instruction code. The representation is called an
assembly language instruction. Such representations are known as mnemonic codes; they
are used instead of binary codes. A program written with mnemonic codes forms an
assembly language program. This is considered to be a Second Generation Language
(2GL).
Advantages:
Changes could be made easier and faster.
Easier to read and write.
Error checking is provided.
Disadvantages:
Machine dependent.
Programming is difficult and time consuming.
The programmer should know all about the logical structure of the computer.
b) High-Level Languages:
Since a computer prefers machine language while a person wants to use a natural language
special “high level computer languages have been developed to bridge this communication gap. A
high level language like C, uses English words plus symbols and numbers. Very first two high level
languages are FORTRAN and COBOL. This is considered to be a Third Generation Language
(3GL).
Advantages:
Readability Programs written in these languages are more readable than those written in
assembly and machine languages.
Portability High-level programming languages can be run on different machines with little
or no change.
Easy debugging error can be easily detected and removed.
Ease in the development of Software Since commands of these programming languages
are closer to the English language, software can be developed with ease.
Translation of high level language to machine language.
High level language sum=0
for(i=1;i<10;i++)
sum=sum+i;
Assembly language mov sum,0
sub AX,AX
mov CX,10
top: add AX,CX
loop top
mov sum,AX
Michine language C70600000000
2 BC 0
B90A00
03C1
E2F9
A30000
i) Procedural Languages:
Algorithmic Languages:
These are high-level languages designed for forming convenient expression of procedures,
used in the solution of wide class of problems. In this language, the programmer must specify the
steps the computer has to follow while executing a program. Some of languages that fall in the
category are C, COBOL, and FORTRAN.
Object-oriented language:
The basic philosophy of object-oriented programming is to deal with objects rather than
functions or subroutines as in strictly algorithmic languages. Objects are self-contained modules that
contain data as well as the functions needed to manipulate the data within the same module. The
difference affects the way a programmer goes about writing a program as well as how information is
represented and activated in the computer. The most important object-oriented programming
features are
abstraction
encapsulation and data hiding
polymorphism
inheritance
reusable code
C++, JAVA, SMALLTALK, etc. are examples of object-oriented languages.
Scripting Languages: These languages assume that a collection of useful programs, each
performing a task, already exists. It has facilities to combine these components to performing a
complex task. A scripting language may thus be thought of as a glue language, which sticks a
variety of components together. One of the earliest scripting languages is the UNIX shell. Now
there are several scripting languages such as VB script and Perl.
Software:
A set of computer programs are called software. Computer program is a
series of instructions telling the computer what to do.
Types of software:
1. System software
2. Application software
1. System software:
System software exists in the functioning of a computer system and includes the
operating system, assembler, interpreter, compiler, linker and loader.
Operating system is the interface between user applications and system hardware.
Assembler is a translator that converse assembly language code into machine
language.
Interpreter converts source language program into executable code at once.
Linker performs the important task of linking together several objects modules.
The task of loading the linked object modules is performed by the loader.
2. Application software:
Examples:
Database Management Software
Spreadsheet Software
Word processing, Desktop Publishing (DTP), and Presentation Software
Multimedia Software
Data Communication Software
Statistical and operational research Software
Algorithms:
Computer Scientist „Niklaus Wirth‟ stated that
An algorithm is a part of the plan for the computer program; an algorithm is „an
effective procedure for solving problem in a finite number of steps‟.
Algorithm is first step of the solution process, after the analysis of problem,
programmer writes the algorithm of that problem.
Flowchart:
A flowchart is a pictorial representation of on algorithm. It shows the logic of the
algorithm and the flow of control. The flowchart uses symbols to represent specific actions
and arrows to indicate the flow of control.
Flowchart symbols are
Flow of control
Start or stop
Input or output
Process / action
Secondary storage