PG Computer Notes 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

Subject – Computer Application & Programming

Prepared by: Moklesa Laskar, Aliah University,

Unit-1: Fundamentals of Computer:-


 Introduction:
Let us begin with the word ‘compute’, which means ‘to calculate’. We all are familiar with
calculations in our day to day life. We apply mathematical operations like addition, subtraction,
Multiplication, etc. and many other formulae for calculations. Simpler calculations take less
time but Complex calculations take much longer time. Another factor is accuracy in
calculations. So man explored the idea to develop a machine which can perform this type of
arithmetic calculation faster and with full accuracy. This gave birth to a device or machine
called “Computer”.

 Definition of Computer:
"A computer is an electronic machine that operates under the control of instructions, that
accepts the input data, processes or manipulates the given data according to predefined
instructions and stores the result for future use"
It performs the following three operations in sequence.
1. It receives data & instructions from the input device.
2. Processes the data as per instructions.
3. Provides the result (output) in a desired form.

Data : It is the collection of raw facts, figures & symbols.


Ex : Names of students and their marks in different subjects listed in random order.
Information : It is the data that is processed & presented in an organized manner.
Ex : When the names of students are arranged in alphabetical order, total and average marks
are calculated & presented in a tabular form, it is information.
Program : Set of instructions that enables a computer to perform a given task.
 Advantages of computers :

1. High speed: Computers have the ability to perform routine tasks at a greater speed than
human beings. They can perform millions of calculations in seconds.
2. Accuracy: Computers are used to perform tasks in a way that ensures accuracy.
3. Storage: Computers can store large amount of information. Any item of data or any
instruction stored in the memory can be retrieved by the computer at lightning speeds.
4. Automation: Computers can be instructed to perform complex tasks automatically (which
increases the productivity).
5. Diligence: Computers can perform the same task repeatedly & with the same accuracy
without getting tired.
6. Versatility: Computers are flexible to perform both simple and complex tasks.
7. Cost effectiveness: Computers reduce the amount of paper work and human effort, thereby
reducing costs.

 Limitations of computers:

1. Computers need clear & complete instructions to perform a task accurately. If the
instructions are not clear & complete, the computer will not produce the required result.
2. Computers cannot think.
3. Computers cannot learn by experience.

 CLASSIFICATION OF COMPUTERS

Computers are broadly classified into two categories depending upon the logic used in their
design as:
1. Analog computers:
In analog computers, data is recognized as a continuous measurement of a physical property
like voltage, speed, pressure etc. Readings on a dial or graphs are obtained as the output, ex.
Voltage, temperature; pressure can be measured in this way.

2. Digital Computers:
These are high speed electronic devices. These devices are programmable. They process data
by way of mathematical calculations, comparison, sorting etc. They accept input and produce
output as discrete signals representing high (on) or low (off) voltage state of electricity.
Numbers, alphabets, symbols are all represented as a series of 1s and 0 s.
Digital Computers are further classified as General Purpose Digital Computers and Special
Purpose Digital Computers. General Purpose computers can be used for any applications like
accounts, payroll, data processing etc. Special purpose computers are used for a specific job
like those used in automobiles, microwaves etc.

3. Hybrid Computers:
Hybrid Computers are a combination of Analog and Digital computers. They combine the
speed of analog computers and accuracy of digital computers. They are mostly used in
specialized applications where the input data is in an analog form i.e. measurement. This is
converted into digital form for further processing. The computers accept data from sensors and
produce output using conventional input/output devices. Another classification of digital
computers is done on the basis of their capacity to access memory and size like:

Computers are classified into four categories depending upon the size, memory capacity and
speed as:
1. Microcomputers:
Microcomputers are generally referred to as Personal Computers (PCs). They have smallest
memory and less power. They are widely used in day to day applications like office automation,
and professional applications, ex. PCAT, Pentium , Note Book and Laptop Computers etc.
2. Mini Computers: Mini computers are more powerful than the microcomputers. They
have higher memory capacity and more storage capacity with higher speeds. These
computers are mainly used in process control systems. They are mainly used in
applications like payrolls, financial accounting, Computer aided design etc. ex. VAX,
PDP-11

3. Mainframe Computers: Main frame computers are very large computers which
process data at very high speeds of the order of several million instructions per second.
They can be linked into a network with smaller computers, microcomputers and with
each other. They are typically used in large organizations, government departments etc.
ex. IBM4381, CDC.
4. Super Computers: A super computer is the fastest, most powerful and most expensive
computer which is used for complex tasks that require a lot of computational power.
Super computers have multiple processors which process multiple instructions at the
same time. This is known as parallel processing. These computers are widely used in
very advanced applications like weather forecasting, processing geological data etc. ex.
CRAY-2, NEC - 500, PARAM.

 Generation of Computer:
1. First Generation Computers
 The first-generation computers that were in use from 1946 to 1959 used vacuum tubes
and magnetic drums as the basic components of the CPU and memory.
 They were very massive in size and had a large amount of energy loss in the form of
heat.
 The frequent fusing of the installations made them very expensive.
 ENIAC (Electronic Numerical Integrator and Calculator), EDVAC, UNIVAC, IBM-
701, IBM-650, etc., were some first-generation computers.
2. Second Generation Computers
 In the second generation of computers, cheaper, low-power-consuming, compact-sized,
reliable, and faster transistors were used as the building blocks of the CPU.
 These computers that were in use from 1959 to 1965 used magnetic cores, tapes, and
discs as storage devices.
 The use of batch processing, multiprogramming operating systems, and high-level
programming languages like FORTRAN and COBOL were some of the features of
second-generation computers like IBM 1620, IBM 7094, CDC 1604, CDC 3600,
UNIVAC 1108, etc.
3. Third-Generation Computers
 The third generation computers that were in use from 1965 to 1971 used Integrated
Chips (IC's) invented by Jack Kilby as the basic component of the CPU.
 The use of IC's helped to invent more reliable, efficient, and smaller-sized computers
like the IBM-360 series, Honeywell-6000 series, PDP (Personal Data Processor), IBM-
370/168, etc.
 Use of remote sensing, time-sharing, and high-level programming languages like
FORTRAN - II to IV, COBOL, PASCAL PL/1, BASIC, ALGOL-68, etc. were the
salient features of third-generation computers.
4. Fourth Generation Computers
 The fourth generation computers that were in use from 1971 to 1980 used Very Large
Scale Integrated (VLSI) circuits in the CPU.
 The powerful, compact, reliable, and affordable fourth-generation computers like
Micral, IBM 5100, Altair 8800, etc., led to the beginning of the Personal Computer era.
 The use of real-time networks, distributed operating systems, and high-level
programming languages like C, C++, DBASE, etc. were some of the features of fourth-
generation computers.
5. Fifth Generation Computers
 The fifth generation computers that have been in use from 1980 to date use
microprocessors that work on Ultra Large Scale Integration (ULSI) technology.
 Artificial Intelligence software and parallel processing hardware are the peculiarities of
fifth-generation computers like PDP-8, PDP-11, ICL 2900, IBM 360, IBM 370, etc.
 All high-level languages, such as C, C++, Java,.Net, and others, are used in today's
computers.

Generation Component used


First Generation Vacuum tubes
(1946-1954 )
Second Generation Transistors
(1955-1965)
Third Generation Integrated Circuits (IC)
(1968-1975 )
Fourth Generation Very Large Scale Integrated Circuits
( 1976-1980) (VLSI)
Fifth Generation Ultra Scale Integrated Circuits (ULSI)
(1980 – till today ) Micro Processor (SILICON CHIP)

 Computer Hardware:
Computer hardware is a physical device of computers that we can see and touch. For e.g.
Monitor, Central Processing Unit, Mouse, Joystick, etc. Using these devices, we can control
computer operations like input and output.
Computer Hardware Parts-
These hardware components are further divided into the following categories, which are:
 Input Devices
 Output Devices
 Storage Devices
 Processor unit
1. Input Devices: Devices used to provide data and instructions to the computer are called
Input devices. Some important input devices are:-
Key board, Mouse, Scanner, MICR, Web camera, Microphone etc.
1. Keyboard: The Key board is used for typing text into the computer. It is also
known as standard Input device. A computer keyboard is similar to that of a type
writer with additional keys. The most commonly available computer keyboard
has 104 keys.
There are different types of keys on the keyboard. The keys are categorized as :

 Alphanumeric keys , including letters & numbers.

 Punctuation keys, such as colon (:), semicolon (;) Question mark (?),
Single & doublequotes (‗,‖)
 Special keys such as arrow keys, control keys, function keys (F1 to F12), HOME,
END etc.

ASCII – American Standard Code for Information Interchange.


This code has given alphabets like some numbers which can be converted to Binary form.
A- 65 …….Z – 90 and a – 97................z – 121
By using these codes the alphabets can be converted to digital & hence to Binary form.

2. Mouse: It is a device that controls the movement of the cursor on a monitor. A mouse
will have 2 buttons on its top. The left button is the most frequently used button. There
will be a wheel between the left and right buttons. This wheel enables us to smoothly
scroll through screens of information. As we move the mouse, the pointer on the monitor
moves in the same direction. Optical mouse is another advanced pointing device that
uses a light emitting component instead of the mouse ball. Mouse cannot be used for
entering the data. It is only useful to select the options on the screen.
3. Scanner: : It is an input device that can read text or illustrations printed on paper
and translate intodigital form. The main advantage of these scanners is that the data
need not be entered separately resulting in saving lot of time.

Scanners are of two types: i) optical scanners ii) MICR


i) Optical scanners:
a. Optical character Recognition (OCR): In this, characters are read with the help
of a light. This isused in office atomization, documentation in library etc.
b. Optical mark recognition (OMR): It is a technology where an OMR device
senses the presence orabsence of a mark such as a pencil mark. OMR is used in tests
such as aptitude tests.
c. Optical barcode recognition (OBCR): Barcode readers are photoelectric scanners
that read the bar codes or vertical zebra striped marks printed on product containers.
This is used in super markets, bookshops etc.
ii. MICR: This is widely used in banks to process the cheques. This allows the
computer to recognizecharacters printed using magnetic ink.

2. Output Devices
These are the devices that are used to display the output of any task given to the computer in
human-readable form. For example Monitor, printer, plotter, speaker etc.

3. Storage Devices
Memory or storage unit is one of the important components of a computer. It is also known as
the primary storage or main memory. It stores data, program instructions, internal results and
final output temporarily before it is sent to an appropriate output device. It consists of
thousands of cells called ―storage locations‖. These cells activate with ―off-on‖ or binary
digits (0,1) mechanism. Thus a character either a letter or numerical digit is stored as a string
of (0,1) Binary digits ( BITS). These bits are used to store instructions and data by their
combinations.
Any storage unit of a computer system is classified on the basis of the following criteria:
Access time: This is the time required to locate and retrieve stored data from the storage unit
in response to program instructions.
Storage capacity: It is the amount of data that can be stored in the storage unit.
Cost per bit of storage.
Units of memory: The computer stores a character in the storage cells with binary (0,1)
mechanism. Thus the basic unit of memory is a bit (binary digit – 0,1). To store a character, a
computer requires 8 bits or 1 byte. This is called the ― word length‖ of the storage unit. Hence
the storage capacity of the computer is measured in the number of words it can store and is
expressed in terms of bytes. The different units of measurement are
Conversion :
8 bits = 1 Byte
210 (or) 1024 Bytes = 1 Kilo Byte (KB)
210 (or) 1024 KB = 1 Mega Byte (MB)
210 (or) 1024 MB = 1 Gega Byte (GB)
210 (or) 1024 GB = 1 Tera Byte (TB)
210 (or) 1024 TB = 1 Peta Byte (PB)

Types of Memory : A computer memory is of two types


Primary Memory ( Internal storage) 2. Secondary Memory ( External storage)
Primary Memory : Primary memory is also called internal memory and is an important part
of a computer. It is the main area in a computer where the data is stored. The stored data can
be recalled instantly and correctly whenever desired. This memory can be quickly accessed by
the CPU for reading or storing information. Primary memory is further classified into two
types:
i. Random Access Memory (RAM) and
ii. Read- Only Memory (ROM )
RAM: RAM is also known as read/write memory as information can be read from and written
onto it. RAM is a place in a computer that holds instructions for the computer, its programs
and the data. The CPU can directly access the data from RAM almost immediately. However,
the storage of data and instructions in RAM is temporary, till the time the computer is running.
It disappears from RAM as soon as the power to the computer is switched off. i.e it is volatile
memory.
ROM: It is called Read-only memory as information can only be read from and not written or
changed onto ROM. ROM is the ‗built-in‘ memory of a computer. It stores some basic input
– output instructions put by the manufacturer to operate the computer. The storage of data and
instructions in ROM is permanent. It does not depend on the power supply. i.e it is non-volatile
memory.
Secondary memory: The primary memory which is faster (and hence expensive) is generally
not sufficient for large storage of data. As a result, additional memory, called the ―auxiliary‖
or ―secondary memory‖ is used. It is also referred as ―backup storage‖ as it is used to store
large volume of data on a permanent basis which can be transferred to the primary memory
whenever required for processing. Data are stored in secondary storage in the same binary
codes as in the main (primary memory) storage. Some of the devices of secondary storages are
Floppy Disk, Hard Disk, CD-ROM, DVD and Flash drive.
Floppy Disk: It is also referred as ―Diskette: and is made of flexible Vinyl material. It has
a small hole on one side called ―Right protect notch‖, Which protects accidental
writing/deleting the information from the disk. There is a hole in the centre through which the
spindle of drive unit rotates the disk. The disks are available in two sizes of 5.25 and 3.5 inches
and these could be either low- density or high-density floppies. Storage capacity of floppies
are measured in kilobytes (KB) and megabytes (MB). The details about the storage capacities
of the floppies are presented below:
Floppy Disk Storage Capacity Size (Diameter)
Low Density 360 KB 5.25 inches
High Density 1.2 MB 5.25 inches
High Density 1.44 MB 3.5 inches
Extended 2.8 MB 3.5 inches

Hard Disk: The hard disk can hold more information than the floppy disk and the retrieval
of information from hard disk is faster when compared to floppies or tapes. A hard disk is fixed
inside the CPU and its capacity ranges from 20 MB onwards. The hard disk is made up of a
collection of discs (one below the other) known as platters on which the data is recorded. These
platters are coated with magnetic material. It is less sensitive to external environmental
disorders and hence the storage in hard disk is safe. A small hard disk might be as much as 25
times larger than a floppy disk. Storage Capacity of hard disks varies from 20 MB to several
Gega bytes like 80GB, 160GB.
CD-ROM: CD-ROM stands for Compact Disk–Read Only Memory. It is used to store a wide
variety of information. Its main advantage is that it is portable and can hold a large amount of
data.. The storage capacity of most CD-ROMs is approximately 650 MB or 700 MB.
DVD: DVD stands for Digital Versatile Disc. It is similar to a CD-ROM, except that it can
store larger amounts of data. The storage capacity of a DVD is at least 4.7MB. DVDs that can
store up to 17GBs are also available. Because of their capacity, DVDs are generally used to
store a very large multimedia presentations and movies that combine high quality sound and
graphics.
Flash Drive: It is a small, portable device that can be used to store, access and transfer data.
Due to its small size, it is commonly called Pen drive. It is also called USB drive. We can read,
write, copy, delete, and move data from computer to pen drive or pen drive to computer. It
comes in various storage capacities of 2GB, 4GB, 8GB etc. It is popular because it is easy to
use and small enough to be carried in a pocket. This device is plugged into the USB port of the
computer and the computer automatically detects this device.
Central Processing Unit: It is the part of the computer that carries out the instructions of a
computer program. It is the unit that reads and executes program instructions. Hence it is known
as the brain‖ of the computer. The CPU consists internal Registers, Arithmetic Logic Unit
(ALU) and control unit.

 Basic Von-Neumann Architecture and its Operation:

Von-Neumann computer architecture design was proposed in 1945.It was later known as Von-
Neumann architecture. Historically there have been 2 types of Computers:
Fixed Program Computers – Their function is very specific and they couldn’t be
reprogrammed, e.g. Calculators.
Stored Program Computers – These can be programmed to carry out many different tasks,
applications are stored on them, hence the name.
Von Neumann architecture is based on the stored-program computer concept, where instruction
data and program data are stored in the same memory. This design is still used in most
computers produced today.
A Von Neumann-based computer:
 Uses a single processor
 Uses one memory for both instructions and data.
 Executes programs following the fetch-decode-execute cycle
It is also known as ISA (Instruction set architecture) computer and is having four basic units:
1. The Central Processing Unit (CPU)
2. The Memory Unit
3. The Input and Output Device
4. Buses
1. Central Processing Unit-
The central processing unit is defined as the it is an electric circuit used for the executing the
instruction of computer program.
It has following major components:
i. Control Unit(CU)
ii. Arithmetic and Logic Unit(ALU
iii. variety of Registers

i. Control Unit –
A control unit (CU) handles all processor control signals. It directs all input and output flow,
fetches code for instructions, and controls how data moves around the system.
ii. Arithmetic and Logic Unit (ALU) –
The arithmetic logic unit is that part of the CPU that handles all the calculations the CPU may
need, e.g. Addition, Subtraction, Comparisons. It performs Logical Operations, Bit Shifting
Operations, and Arithmetic operations.

iii. Registers – Registers refer to high-speed storage areas in the CPU. The data processed
by the CPU are fetched from the registers. There are different types of registers used
in architecture :-
Accumulator: Stores the results of calculations made by ALU. It holds the intermediate of
arithmetic and logical operatoins.it act as a temporary storage location or device.
Program Counter (PC): Keeps track of the memory location of the next instructions to be
dealt with. The PC then passes this next address to the Memory Address Register (MAR).
Memory Address Register (MAR): It stores the memory locations of instructions that need
to be fetched from memory or stored in memory.
Memory Data Register (MDR): It stores instructions fetched from memory or any data that
is to be transferred to, and stored in, memory.
Current Instruction Register (CIR): It stores the most recently fetched instructions while it
is waiting to be coded and executed.
Instruction Buffer Register (IBR): The instruction that is not to be executed immediately is
placed in the instruction buffer register IBR.
2. Memory Unit: A memory unit is a collection of storage cells together with associated
circuits needed to transfer information in and out of the storage. The memory stores binary
information in groups of bits called words. The internal structure of a memory unit is specified
by the number of words it contains and the number of bits in each word.
The memory component in Von Neumann Architecture consists of primary and secondary
memory
3. Input and Output Devices – Program or data is read into main memory from the input
device or secondary storage under the control of CPU input instruction. Output devices are
used to output information from a computer. If some results are evaluated by the computer and
it is stored in the computer, then with the help of output devices, we can present them to the
user.
4. Buses – Data is transmitted from one part of a computer to another, connecting all major
internal components to the CPU and memory, by the means of Buses. Types:
Data Bus: It carries data among the memory unit, the I/O devices, and the processor.
Address Bus: It carries the address of data (not the actual data) between memory and processor.
Control Bus: It carries control commands from the CPU (and status signals from other devices)
in order to control and coordinate all the activities within the computer.

 Memory Hierarchy Design :


Memory Hierarchy can be simply illustrated as the organization of the memory for saving
the access time. Because of the nicely written codes or program, memory hierarchy works
well. It takes less time in accessing at the current level.
This Memory Hierarchy Design is divided into 2 main types:
External Memory or Secondary Memory: Comprising of Magnetic Disk, Optical Disk,
and Magnetic Tape i.e. peripheral storage devices which are accessible by the processor via
an I/O Module.
Internal Memory or Primary Memory: Comprising of Main Memory, Cache Memory
& CPU registers. This is directly accessible by the processor.

Characteristics of Memory Hierarchy:


 Capacity: It is the global volume of information the memory can store. As we move from
top to bottom in the Hierarchy, the capacity increases.

 Access Time: It is the time interval between the read/write request and the availability of
the data. As we move from top to bottom in the Hierarchy, the access time increases.

 Performance: Earlier when the computer system was designed without a Memory
Hierarchy design, the speed gap increased between the CPU registers and Main Memory
due to a large difference in access time. This results in lower performance of the system
and thus, enhancement was required. This enhancement was made in the form of Memory
Hierarchy Design because of which the performance of the system increases. One of the
most significant ways to increase system performance is minimizing how far down the
memory hierarchy one has to go to manipulate data.

 Cost per Bit: As we move from bottom to top in the Hierarchy, the cost per bit increases
i.e. Internal Memory is costlier than External Memory.

 Computer Software
Software: Software is a program or set of instructions that causes the Hardware to function
in a desired way. The basic difference between the Hardware and Software is just the same
as that exists between TV and TV studio. Without TV studio (software) from where the
programs are telecast, the TV (Hardware) is a dead machine.
There are five categories of software. They are:
1. Operating System 2. Translators 3. Utility programs 4. Application programs
5. General purpose programs

 Basics of Operating System (OS):


What is an operating system?
The software that manages the resources of a computer system and schedules its operation is
called Operating system. The operating system acts as interface between the hardware and the
user programs and facilitates the execution of programs.

Generally the OS acts as an interface between the user and the Hardware of the
computer. i.e It is a bridge between the user and the Hardware.
The User interface provided by the OS can be character based or graphical.
CUI -- Character user Interface
GUI -- Graphical user Interface
CUI : It is operated with keyboard only. Ex: MS-DOS, UNIX
GUI : The system can be operated with mouse and keyboard. Ex: Windows 95,
Windows XP etc
 Functions of Operating System:
1. Memory Management: It is the management of the main or primary memory. It
 Allocates and deallocates the memory.
 Keeps a record of which part of primary memory is used by whom and how much.
 Distributes the memory while multiprocessing.
 In multiprogramming, the operating system selects which processes acquire memory
when and how much memory they get.
2. Processor Management/Scheduling
When more than one process runs on the system the OS decides how and when a process will
use the CPU. Hence, the name is also CPU Scheduling. The OS:
 Allocates and deallocates processor to the processes.
 Keeps record of CPU status.
3. Device Management
An operating system regulates device connection using drivers. The processes may require
devices for their use. This management is done by the OS. The OS:
 Allocates and deallocates devices to different processes.
 Keeps records of the devices.
 Decides which process can use which device for how much time.
4. File Management
The files on a system are stored in different directories. The OS:
 Keeps records of the status and locations of files.
 Allocates and deallocates resources.
 Decides who gets the resources.
5. Storage Management
Storage management is a procedure that allows users to maximize the utilization of storage
devices while also protecting data integrity on whatever media on which it lives. The OS uses
storage management for:
 Improving the performance of the data storage resources.
 It optimizes the use of various storage devices.
 Assists businesses in storing more data on existing hardware, speeding up the data
retrieval process, preventing data loss, meeting data retention regulations, and lowering
IT costs.
 Types of Operating Systems
There are several types of Operating Systems which are mentioned below.
 Batch Operating System
 Multi-Programming System
 Multi-Processing System
 Multi-Tasking Operating System
 Time-Sharing Operating System
 Distributed Operating System
 Network Operating System
 Real-Time Operating System
1. Batch Operating System
This type of operating system does not interact with the computer directly. There is an operator
which takes similar jobs having the same requirement and groups them into batches. It is the
responsibility of the operator to sort jobs with similar needs.

2. Multi-Programming Operating System


Multiprogramming Operating Systems can be simply illustrated as more than one program is
present in the main memory and any one of them can be kept in execution. This is basically
used for better execution of resources.

3. Multi-Processing Operating System


Multi-Processing Operating System is a type of Operating System in which more than one CPU
is used for the execution of resources. It betters the throughput of the System.
4. Multi-Tasking Operating System
Multitasking Operating System is simply a multiprogramming Operating System with having
facility of a Round-Robin Scheduling Algorithm. It can run multiple programs simultaneously.

5. Time-Sharing Operating Systems


Each task is given some time to execute so that all the tasks work smoothly. Each user gets the
time of the CPU as they use a single system. These systems are also known as Multitasking
Systems. The task can be from a single user or different users also. The time that each task gets
to execute is called quantum. After this time interval is over OS switches over to the next task.
6. Distributed Operating System
These types of operating system is a recent advancement in the world of computer technology
and are being widely accepted all over the world and, that too, at a great pace. Various
autonomous interconnected computers communicate with each other using a shared
communication network. Independent systems possess their own memory unit and CPU. These
are referred to as loosely coupled systems or distributed systems.

7. Network Operating System


These systems run on a server and provide the capability to manage data, users, groups,
security, applications, and other networking functions. These types of operating systems allow
shared access to files, printers, security, applications, and other networking functions over a
small private network.

8. Real-Time Operating System


These types of OSs serve real-time systems. The time interval required to process and respond
to inputs is very small. This time interval is called response time.
Real-time systems are used when there are time requirements that are very strict like missile
systems, air traffic control systems, robots, etc.

Basics of DOS Programming: Separate PDF file created for DOS commands.
 Programming Language Translator:
Compilers, interpreters, translate programs written in high-level languages into machine code
that a computer understands and assemblers translate programs written in low-level or
assembly language into machine code.
The language processors can be any of the following three types:

1. Compiler
The language processor that reads the complete source program written in high-level language
as a whole in one go and translates it into an equivalent program in machine language is called
a Compiler. Example: C, C++, C#.

2. Assembler
The Assembler is used to translate the program written in Assembly language into machine
code. The source program is an input of an assembler that contains assembly language
instructions. The output generated by the assembler is the object code or machine code
understandable by the computer. Assembler is basically the 1st interface that is able to
communicate humans with the machine. We need an assembler to fill the gap between human
and machine so that they can communicate with each other. code written in assembly language
is some sort of mnemonics(instructions) like ADD, MUL, MUX, SUB, DIV, MOV and so on.
and the assembler is basically able to convert these mnemonics in binary code. Here, these
mnemonics also depend upon the architecture of the machine.

3. Interpreter
The translation of a single statement of the source program into machine code is done by a
language processor and executes immediately before moving on to the next line is called an
interpreter. If there is an error in the statement, the interpreter terminates its translating process
at that statement and displays an error message. The interpreter moves on to the next line for
execution only after the removal of the error. An Interpreter directly executes instructions
written in a programming or scripting language without previously converting them to an object
code or machine code. An interpreter translates one line at a time and then executes it.

Example: Perl, Python and Matlab.

 Microsoft Office: Separate PDF file created for MS-office.

 Computer Networks:
What is a Computer Network:-
In a network, two or more computers are connected in a way so that they can share their
resources like printers, CDs, hard disks etc. Such networks can be connected via cable,
telephone line, radio waves, satellite, infrared etc.
 Types of Computer Network
Based on coverage or geographical spread, a network can be divided into the following
types: LAN, MAN, WAN and PAN.
1. Local Area Network (LAN) -When the network of computer is confined to a small or
localised area such as school, office or building, it is known as Local Area Network (LAN).
Computers or users in a local area network can share data, information, software and common
hardware devices such as printer, modem, hard disk, etc.

2. Metropolitan Area Network (MAN)- A metropolitan area network is the network which is
spread over a city. The functions of a MAN is similar to LAN. Like a LAN, computers in a
MAN are also capable of sharing data, information, software and hardware. The difference is
only on the basis of geographical area coverage.

3. Wide Area Network (WAN)- The network of computers which is spread across the countries
probably over the entire world is known as a Wide Area Network (WAN).
A WAN can be a group of several LANs interconnected together.
The largest WAN is the Internet.
The functions of WAN are also similar to a LAN or MAN.
4. Personal Area Network (PAN) -The PAN refers to a computer network, which is used for
communication among computer devices spread over a few meters. PAN may be wired (i.e.
with the use of computer buses such as USB) or wireless using wireless network technologies
such as Bluetooth, wireless USB, Z-wave and ZigBee. Bluetooth personal area network (PAN)
is also called a piconet. It can be composed of up to eight devices in a master-slave relationship.
The first Bluetooth device is master and other devices are acting as slaves. Normally, its range
is up to 10 m.

 Definition of Internet-
The Internet has gained popularity and emerged as an important and efficient means of
communication. The Internet is a worldwide network of networks.
Through the Internet, computers become able to exchange information with each other and find
diverse perspectives on issues from a global audience.
 Applications of Internet
The Internet is used for different purposes by different people. Some uses of the Internet are
listed below:
 E-Commerce (auction, buying, selling products etc.)
 Research (online journals, magazines, information etc.)
 Education (e-learning courses, virtual classroom, distance learning)
 E-Governance (online filing of application (Income Tax), online application forms
etc.)
 Online ticket booking (airplane tickets, rail tickets, cinema hall tickets etc.)
 On-line payments (credit card payments etc.)
 Video conferencing
 Exchange of views, music, files, emails, folders, data, information etc.
 Outsourcing jobs (workflow software)
 Social networking (sites like Facebook, LinkedIn, X)
 E-telephony (sites like skype)

Unit -5 -Introduction to Computer Programming:


What is a Programming Language?
A programming language is a computer language that is used by programmers (developers) to
communicate with computers. It is a set of instructions written in any specific language ( C,
C++, Java, Python) to perform a specific task.
1. Machine Languages: Computers respond only to machine language. This language is
in terms of binary codes (0,1). i.e. all programs should be written with these codes, which is
difficult, time consuming and leading to errors while writing the programs. There is no unique
standard machine language. Rather there are many machine languages. These are machine
dependent. These are referred as the first generation languages.
2. Assembly Languages: It uses mnemonic codes rather than numeric codes (as in
machine languages). Ex. Add or A is used as a symbol for addition. It requires translators to
convert into machine language. Like machine language, writing program in assembly language
is also time consuming. These are also machine dependent.
3. High Level Languages (HLL): igh-level programming language (HLL) is designed
for developing user-friendly software programs and websites. This programming language
requires a compiler or interpreter to translate the program into machine language (execute the
program).
The main advantage of a high-level language is that it is easy to read, write, and maintain.
A high-level language is further divided into three parts -
i. Procedural Oriented programming language: Procedural Oriented Programming (POP)
language is derived from structured programming and based upon the procedure call concept.
It divides a program into small procedures called routines or functions.
Example: C, FORTRAN, Basic, Pascal, etc.
ii. Object-Oriented Programming language
Object-Oriented Programming (OOP) language is based upon the objects. In this programming
language, programs are divided into small parts called objects. It is used to implement real-
world entities like inheritance, polymorphism, abstraction, etc in the program to makes the
program resusable, efficient, and easy-to-use.
Example: C++, Java, Python, C#, etc.
Definition of Algorithm
The word Algorithm means ” A set of finite rules or instructions to be followed in calculations
or other problem-solving operations ”.
What is a Flowchart?
A flowchart is a graphical representation of an algorithm. Programmers often use it as a
program-planning tool to solve a problem.

Basic of C Programming Language:


What is C?
 C is a general-purpose programming language created by Dennis Ritchie at the Bell
Laboratories in 1972.
 It is a very popular language, despite being old. The main reason for its popularity is
because it is a fundamental language in the field of computer science.
 C is strongly associated with UNIX, as it was developed to write the UNIX operating
system.
myfirstprogram.c:

Components of a C Program:
1. Header Files Inclusion – Line 1 [#include <stdio.h>]
What is header files in C ?
The first and foremost component is the inclusion of the Header files in a C program. A header
file is a file with extension .h which contains C function declarations and macro definitions
to be shared between several source files. All lines that start with # are processed by a
preprocessor which is a program invoked by the compiler. In the above example, the
preprocessor copies the preprocessed code of stdio.h to our file. The .h files are called header
files in C.
Some of the C Header files:

stddef.h – Defines several useful types and macros.


stdint.h – Defines exact width integer types.
stdio.h – Defines core input and output functions
stdlib.h – Defines numeric conversion functions, pseudo-random number generator, and
memory allocation
string.h – Defines string handling functions
math.h – Defines common mathematical functions.
2. Main Method Declaration – Line 2 [int main()]
The next part of a C program is to declare the main() function. It is the entry point of a C
program and the execution typically begins with the first line of the main(). The empty brackets
indicate that the main doesn’t take any parameter (See this for more details). The int that was
written before the main indicates the return type of main(). The value returned by the main
indicates the status of program termination. See this post for more details on the return type.

3. Body of Main Method – Line 3 to Line 6 [enclosed in {}]


The body of a function in the C program refers to statements that are a part of that function. It
can be anything like manipulations, searching, sorting, printing, etc. A pair of curly brackets
define the body of a function. All functions must start and end with curly brackets.

4. Statement – Line 4 [printf(“Hello World”);]


Statements are the instructions given to the compiler. In C, a statement is always terminated by
a semicolon (;). In this particular case, we use printf() function to instruct the compiler to
display “Hello World” text on the screen.

5. Return Statement – Line 5 [return 0;]


The last part of any C function is the return statement. The return statement refers to the return
values from a function. This return statement and return value depend upon the return type of
the function. The return statement in our program returns the value from main(). The returned
value may be used by an operating system to know the termination status of your program. The
value 0 typically means successful termination.

How to Execute the Above Program?


In order to execute the above program, we need to first compile it using a compiler and then
we can run the generated executable. There are online IDEs available for free like
GeeksforGeeksIDE, that can be used to start development in C without installing a compiler.

Windows: There are many free IDEs available for developing programs in C like Code Blocks
and Dev-CPP. IDEs provide us with an environment to develop code, compile it and finally
execute it. We strongly recommend Code Blocks.
Linux: GCC compiler comes bundled with Linux which compiles C programs and generates
executables for us to run. Code Blocks can also be used with Linux.
macOS: macOS already has a built-in text editor where you can just simply write the code and
save it with a “.c” extension.

Application of C :
Operating systems: C is widely used for developing operating systems such as Unix, Linux,
and Windows.
Embedded systems: C is a popular language for developing embedded systems such as
microcontrollers, microprocessors, and other electronic devices.
System software: C is used for developing system software such as device drivers, compilers,
and assemblers.
Networking: C is widely used for developing networking applications such as web servers,
network protocols, and network drivers.
Database systems: C is used for developing database systems such as Oracle, MySQL, and
PostgreSQL.
Gaming: C is often used for developing computer games due to its ability to handle low-level
hardware interactions.
Artificial Intelligence: C is used for developing artificial intelligence and machine learning
applications such as neural networks and deep learning algorithms.
Scientific applications: C is used for developing scientific applications such as simulation
software and numerical analysis tools.
Financial applications: C is used for developing financial applications such as stock market
analysis and trading systems.

What is a variable in C?
A variable in C is a memory location with some name that helps store some form of data and
retrieves it when required. We can store different types of data in the variable and reuse the
same variable for storing some other data any number of times.
C Variable Syntax
The syntax to declare a variable in C specifies the name and the type of the variable.

data_type variable_name = value; // defining single variable


or
data_type variable_name1, variable_name2; // defining multiple variable
int var; // integer variable
char a; // character variable
float fff; // float variables
There are 3 aspects of defining a variable:

 Variable Declaration
 Variable Definition
 Variable Initialization
1. C Variable Declaration
Variable declaration in C tells the compiler about the existence of the variable with the given
name and data type.When the variable is declared compiler automatically allocates the memory
for it.

2. C Variable Definition
In the definition of a C variable, the compiler allocates some memory and some value to it. A
defined variable will contain some random garbage value till it is not initialized.
Ex: int var;
char var2;
3. C Variable Initialization
Initialization of a variable is the process where the user assigns some meaningful value to the
variable.
int var; // variable definition
var = 10; // initialization
or
int var = 10;
 Rules for Naming Variables in C
You can assign any name to the variable as long as it follows the following rules:
A variable name must only contain alphabets, digits, and underscore.
A variable name must start with an alphabet or an underscore only. It cannot start with a digit.
No whitespace is allowed within the variable name.
A variable name must not be any reserved word or keyword.
Data Types in C :

Data type Short form Memory size identifier


Integers int 2 to 4 bytes %d
Character ch 1B %c
Float float 4B %f
Double double 8B %lf
Void void 0

 Example of some C program with algorithm and flowchart.

1. Write a c-program to print “Hello World”?

 #include <stdio.h>
 int main() {
 // printf() displays the string inside quotation
 printf("Hello, World!");
 return 0;
 }
 Run Code
Output

 Hello, World!

2. Write Algorithm, Flowchart and C Program to Add Two Integers.


Algorithm
1Input : Two numbers num1 and num2
2Step 1: Start
3Step 2: Declare sum to 0 (This is optional step, during step5 we can add
declaration and assign directly as well)
4Step 3: Read number num1
5Step 4: Read number num2
6Step 5: Add num1 and num2 and assign result to variable sum
7Step 6: Print sum
8Step 7: Stop
9Output: Sum of num1 and num2

Flowchart:

C code:

#include <stdio.h>
int main()
{
int x, y, sum; // Declare variables for two integers and their
sum

// Prompt user for input and store in 'x'


printf("\nInput the first integer: ");
scanf("%d", &x);

// Prompt user for input and store in 'y'


printf("\nInput the second integer: ");
scanf("%d", &y);

sum = x + y; // Calculate the sum of 'x' and 'y'

// Print the sum


printf("\nSum of the above two integers = %d\n", sum);

return 0; // Indicate successful execution


}

Sample Output:
Input the first integer: 25

Input the second integer: 38

Sum of the above two integers = 63

3. Write Algorithm, flowchart and the c-program to calculate sum of five


subjects and find the percentage. And print the message.

Algorithm :
Step 1: Start
Step 2: Get the inputs from the user for five subjects mark
Step 3: Find the Total of the marks
Step 4: Find the percentage using formula (percentage = total of the marks
divided by no. of the subjects)
Step 5: Print sum of the marks and percentage.
Step 6: stop

#include<stdio.h>

#include<conio.h>
void main()
{
int s1,s2,s3,s4,s5,total=500,sum=0;
float percentage;
printf("Enter Marks of 5 Subjects: ");
scanf("%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5);
sum=s1+s2+s3+s4+s5;
printf("Sum of 5 Subjects is: %d\n",sum);
percentage=(sum*100)/total;
printf("Percentage is: %f",per);
}
Copy

OUTPUT:

Enter Marks of 5 Subjects: 80 70 85 83 90


Sum of 5 Subjects is: 408
Percentage is: 81.000000

Flowchart:

Start

Input s1, s2, s3, s4, s5,


total =500, sum=0

sum=s1+s2+s3+s4+s5
Percentage= (sum*100)/total

Print sum, percentage

Stop

You might also like