UNIT-1 computer programming
UNIT-1 computer programming
INTRODUCTION TO COMPUTERS
COMPUTERS : A computer is an electronic device that is designed to process, store, and retrieve
information. It can perform a variety of tasks based on instructions provided by a user or a program.
Computers have become an essential part of our daily lives, and they are used in various fields such as
education, business, entertainment, research, and communication.
Features of Computer
Speed: Computers are very fast. They can analyse large amounts of data at very high speeds..
Accurate: Computers are very accurate. They also include error-correcting methods to ensure
that data is correctly processed and stored.
Reliability: Reliability refers to the ability to execute set of functions without errors or
failures.
Consistency: Consistency refers to a computer’s ability to perform reliably and consistently.
Multiprocessing: Computers are multiprocessing they execute a large number of tasks
concurrently.
Multitasking: Multitasking is one of the important features of computers, it enables users to
run multiple applications simultaneously.
Portability: Portability allows users to carry their computing power wherever they go.
Versatility: Versatility in a computer’s features refers to its ability to accomplish a wide range
of tasks and operations. A versatile computer can run several software applications, process
and manipulate data in a variety of ways, and support a wide range of hardware components
and peripherals.
Generations of Computers
First Generation (1940s-1950s)
Used vacuum tubes for circuitry.
Characteristics:
1.Large, expensive, and consumed a lot of electricity.
2.Programming was done in machine language.
Example: ENIAC, UNIVAC.
Second Generation (1950s-1960s)
Used transistors instead of vacuum tubes.
Characteristics:
1.Smaller, faster, and more reliable than first-generation computers.
2.Programming in assembly language.
Example: IBM 1401, PDP-1.
Third Generation (1960s-1970s)
Used integrated circuits (ICs).
Characteristics:
1.More powerful and compact.
2.High-level programming languages introduced.
Example: IBM 360, UNIVAC 1108.
Fourth Generation (1970s-1980s)
Used microprocessors.
Characteristics:
1.Personal computers (PCs) became common.
2.Introduction of GUIs and operating systems like MS-DOS.
Example: Apple II, IBM PC.
Fifth Generation (1980s-Present)
Based on artificial intelligence and parallel processing.
Characteristics:
1.Use of supercomputers and robotics.
2.Ubiquity of internet-connected devices.
Example: IBM Watson, smartphones.
CLASSIFICATION OF COMPUTERS
Micro Computer:
Size − Microcomputers are small. These are portable.
Example − Some of the popular microcomputers are laptops and desktops, standard PCs,
mobile phones, and notebooks.
microcomputer
Microcomputers have become an important part of modern life. They have had a big impact on
society, companies, education, and related areas.
Uses of Microcomputers − Microcomputers are most widely used in education and learning,
entertainment and media, innovation and creativity, research and science, healthcare and
medicine, home automation, remote work, and e-commerce and online shopping.
Minicomputer:
Size − Its size falls between mainframes and microcomputers. It is larger than mainframe
computers and smaller than microcomputers.
Example − Some of the popular minicomputers are the PDP-11, IBM's AS/400e, Honeywell
200, and TI-990.
Why a Minicomputer: Minicomputers are also known as mini-PCs or small-form-factor
(SFF) computers. These have impressive computing capabilities, high performance,
connectivity options, portability, and versatility features.
Uses of Minicomputers − Minicomputers are most widely used in scientific computations,
engineering, business transaction processing, file handling, and database management.
Mainframe Computer:
Size − Mainframe computers can vary in size; their size generally depends on their
specifications and the specific model being considered.
Example − Some of the popular mainframe computers are IBM iSeries mainframes (BM z14
and IBM z15), Unisys ClearPath, Fujitsu GS21 Series, and Hitachi VOS3.
mainframe computer
The processing capacity of mainframes is frequently measured in MIPS (million instructions per
second) or other units. This enables them to process a large volume of transactions and perform
extensive data processing.
Uses of the Mainframe − Mainframe computers are most widely used in finance,
government, healthcare, and more.
Supercomputer:
Size − Supercomputers can vary in size, from small clusters of computers to massive
installations. A supercomputer may contain 10, 100, 1000, or more computers that all work
together.
Example − Some of the popular supercomputers are Fugaku, Google Sycamore, Baidu's
quantum supercomputer, and Sierra.
Supercomputer
o A supercomputer's processing speed is exceptional and can perform billions of
calculations per second. Multiple processors work in parallel mode to execute tasks,
which makes processing powerful.
o Supercomputers are specially built using specialised hardware like GPUs (Graphics
Processing Units) or TPUs (Tensor Processing Units), which are used in graphics
rendering or machine learning tasks.
o Supercomputers represent the pinnacle of computing power, and these are very
expensive and are employed for specialised applications.
Uses of the Supercomputer − Supercomputers are most widely used in scientific research,
data analysis, weather forecasting, scientific simulations, graphics, fluid dynamic
calculations, nuclear energy research, electronic design, and the analysis of geological data.
Analog Computer
A computer that uses physical means like mechanical or hydraulic components to do the
computation rather than electronic circuits is called an analogue computer. These computers
work with continuous data and can manage physical quantities efficiently. They are
particularly good at solving differential equations and simulating dynamic systems.
ANALOG COMPUTER
Digital Computer
A digital computer is a type of computer that represents and processes data using discrete, distinct
values. In digital computers, data is processed using binary numbers 0 and 1. These computers are
designed to perform arithmetic calculations and complex data processing and manipulation. The main
components of a digital computer are input, processing, and output.
DIGITAL COMPUTER
Hybrid Computer
A hybrid computer is a type of computer system that integrates the features and capabilities of both
analogue and digital computers. This integration allows the hybrid computer to perform various tasks
efficiently by leveraging the strengths of both digital and analogue technologies.
COMPONENTS OF COMPUTER:
There are basically three important components of a computer:
1. Input Unit
2. Central Processing Unit (CPU)
3. Output Unit
1. Input Unit:
The input unit consists of input devices that are attached to the computer. These devices take input
and convert it into binary language that the computer understands. Some of the common input devices
are keyboard, mouse, joystick, scanner etc.
The Input Unit is formed by attaching one or more input devices to a computer.
A user input data and instructions through input devices such as a keyboard, mouse, etc.
The input unit is used to provide data to the processor for further processing.
2. Central Processing Unit:
Once the information is entered into the computer by the input device, the processor processes it. The
CPU is called the brain of the computer because it is the control centre of the computer. It first fetches
instructions from memory and then interprets them to know what is to be done. If required, data is
fetched from memory or input device. Thereafter CPU executes or performs the required computation,
and then either stores the output or displays it on the output device. The CPU has three main
components, which are responsible for different functions: Arithmetic Logic Unit (ALU), Control
Unit (CU) and Memory registers
A. Arithmetic and Logical Unit: The ALU, as its name suggests performs mathematical calculations
and takes logical decisions. Arithmetic calculations include addition, subtraction, multiplication and
division. Logical decisions involve the comparison of two data items to see which one is larger or
smaller or equal.
B. Control Unit: The Control unit coordinates and controls the data flow in and out of the CPU, and
controls all the operations of ALU, memory registers and also input/output units. It is also responsible
for carrying out all the instructions stored in the program. It decodes the fetched instruction, interprets
it and sends control signals to input/output devices until the required operation is done properly by
ALU and memory.
C. Memory Unit: A register is a temporary unit of memory in the CPU. These are used to store the
data, which is directly used by the processor. Registers can be of different sizes (16 bit, 32 bit, 64 bit
and so on) and each register inside the CPU has a specific function, like storing data, storing an
instruction, storing address of a location in memory etc. The user registers can be used by an assembly
language programmer for storing operands, intermediate results etc. Accumulator (ACC) is the main
register in the ALU and contains one of the operands of an operation to be performed in the ALU.
3. Output Unit:
The output unit consists of output devices that are attached to the computer. It converts the binary data
coming from the CPU to human understandable form. The common output devices are monitor,
printer, plotter, etc.
The output unit displays or prints the processed data in a user-friendly format.
The output unit is formed by attaching the output devices of a computer.
The output unit accepts the information from the CPU and displays it in a user-readable form.
INPUT /OUTPUT DEVICES:
INPUT DEVICES:
1. Keyboard
A simple device comprising keys and each key denotes either an alphabet, number or number
commands which can be given to a computer for various actions to be performed
It has a modified version of typewriter keys
The keyboard is an essential input device and computer and laptops both use keyboards to
give commands to the computer
2. Mouse
It is also known as a pointing device
Using mouse we can directly click on the various icons present on the system and open up
various files and programs
A mouse comprises 3 buttons on the top and one trackball at the bottom which helps in
selecting and moving the mouse around, respectively
In case of laptops, the touchpad is given as a replacement of the mouse which helps in the
movement of the mouse pointer
3. Joy Stick
It is a device which comprises a stick which is attached at an angle to the base so that it can be
moved and controlled
Mostly used to control the movement in video games
Apart from a computer system, a joystick is also used in the cockpit of an aeroplane,
wheelchairs, cranes, trucks, etc. to operate them well
4. Light Pen
It is a wand-like looking device which can directly be moved over the device’s screen
It is light-sensitive
Used in conjunction with computer’s cathode ray tube
5. Microphone
Using a microphone, sound can be stored in a device in its digital form
It converts sound into an electrical signal
To record or reproduce a sound created using a microphone, it needs to be connected with an
amplifier
6. Scanner
This device can scan images or text and convert it into a digital signal
When we place any piece of a document on a scanner, it converts it into a digital signal and
displays it on the computer screen
7. Barcode Reader
It is a kind of an optical scanner
It can read bar codes
A source of light is passed through a bar code, and its aspects and details are displayed on the
screen
OUTPUT DEVICES:
1. Monitor
The device which displays all the icons, text, images, etc. over a screen is called the Monitor
When we ask the computer to perform an action, the result of that action is displayed on the
monitor
Various types of monitors have also been developed over the years
2. Printer
A device which makes a copy of the pictorial or textual content, usually over a paper is called
a printer
For example, an author types the entire book on his/her computer and later gets a print out of
it, which is in the form of paper and is later published
Multiple types of printers are also available in the market, which can serve different purposes
3. Speakers
A device through which we can listen to a sound as an outcome of what we command a
computer to do is called a speaker
Speakers are attached with a computer system and also are a hardware device which can be
attached separately
With the advancement in technology, speakers are now available which are wireless and can
be connected using BlueTooth or other applications
4. Projector
An optical device which presents an image or moving images onto a projection screen is
called a projector
Most commonly these projectors are used in auditoriums and movie theatres for the display of
the videos or lighting
If a projector is connected to a computer, then the image/video displayed on the screen is the
same as the one displayed on the computer screen
5. Headphones
They perform the same function as a speaker, the only difference is the frequency of sound
Using speakers, the sound can be heard over a larger area and using headphones, the sound is
only audible to the person using them
Also known as earphones or headset.
MEMORY :
Memory is any physical device, used to store data, information or instruction temporarily or
permanently. It is the collection of storage units that stores binary information in the form of bits. The
memory block is split into a small number of components, called cells. Each cell has a unique address
to store the data in memory, ranging from zero to memory size minus one.
CLASSIFICATION OF MEMORY:
Types of software:
1. System Software
System software manages hardware and basic system operations and serves as a foundation for
application software. It serves as a bridge between hardware and user and ensures that the system
operates efficiently and effectively. This includes Operating Systems, Device Drivers, and Utility
Software.
2. Application Software
Application Software refers to the programs designed to perform specific tasks for end-users such as
web browsing, gaming, word processing, etc. This includes Productivity Software (Microsoft Office,
Google Workspace), Database Software (MySQL, Oracle Database), Communication Software
(Slack, Skype), and Graphics Software (Adobe Photoshop, CorelDraw).
3. Development Software
Development Software includes tools and environments that are used by developers and programmers
to create, debug, and maintain software applications. This includes Integrated Development
Environments (Eclipse, Microsoft Visual Studio), Code Editors (Atom, Visual Studio Code), and
Version Control Software (Git, GitHub).
4. Business Software
Business Software refers to the applications that assist organizations in managing their operations,
improving productivity, and facilitating various business activities. This includes Enterprise Resource
Planning (ERP), Customer Relationship Management (CRM), and Accounting Software
(QuickBooks, Xero).
5. Embedded Software
Embedded software is computer software that is designed to operate hardware and perform specific
tasks within a larger system. It is optimized for particular functions and integrated into the hardware it
controls. This includes Firmware (BIOS in computer) and Control Systems (Software in automotive
control systems).
Operating system: An Operating System can be defined as an interface between user and hardware.
It is responsible for the execution of all the processes, Resource Allocation, CPU management, File
Management and many other tasks.
The purpose of an operating system is to provide an environment in which a user can execute
programs in convenient and efficient manner.
Operating system
Computer Networks & communication: A computer network is a collection of interconnected
devices that share resources and information. These devices can include computers, servers, printers,
and other hardware. Networks allow for the efficient exchange of data, enabling various applications
such as email, file sharing, and internet browsing.
Network: A network is a collection of computers and devices that are connected to enable
communication and data exchange.
Nodes: Nodes are devices that are connected to a network. These can include computers,
Servers, Printers, Routers, Switches, and other devices.
Protocol: A protocol is a set of rules and standards that govern how data is transmitted over a
network. Examples of protocols include TCP/IP, HTTP, and FTP
Topology: Network topology refers to the physical and logical arrangement of nodes on a
network. The common network topologies include bus, star, ring, mesh, and tree.
Service Provider Networks: These types of Networks give permission to take Network
Capacity and Functionality on lease from the Provider. Service Provider Networks include
Wireless Communications, Data Carriers, etc.
IP Address: An IP address is a unique numerical identifier that is assigned to every device on
a network. IP addresses are used to identify devices and enable communication between them.
DNS: The Domain Name System (DNS) is a protocol that is used to translate human-readable
domain names (such as www.google.com) into IP addresses that computers can understand.
Firewall: A firewall is a security device that is used to monitor and control incoming and
outgoing network traffic. Firewalls are used to protect networks from unauthorized access and
other security threats.
Types of Computer Network:.
Difference Between LAN, MAN, and WAN
Full Form LAN is an acronym for Local MAN is an acronym for WAN is an acronym for Wide
Area Network. Metropolitan Area Area Network.
Network.
Definition and LAN is a network that MAN is a comparatively The WAN network spans to
meaning usually connects a small wider network that an even larger locality. It
group of computers in each covers large regions- like has the capacity to connect
geographical area. towns, cities, etc. various countries together.
For example, the Internet is
a WAN.
Network The LAN is private. The MAN can be both The WAN can also be both
Ownership Hospitals, homes, schools, private or public. Many private or public.
offices, etc., may own it. organizations and
telecom operators may
own them.
Maintenance and Very easy to design and Comparatively difficult Very difficult to design and
designing maintain. to design and maintain. maintain.
Speed LAN offers a very high MAN offers a moderate WAN offers a low Internet
Internet speed. Internet speed. speed.
Faulty Tolerance The LAN exhibits a better The MAN exhibits a The WAN also exhibits a
fault tolerance than the rest lesser fault tolerance. lesser fault tolerance.
of the networks.
Communication LAN typically allows a MAN allows multiple A huge group of computers
Allotment single pair of devices to computers to interact can easily interact with each
establish a communication. simultaneously with other using the WAN.
But it may also support each other.
more computers.
Uses Schools, homes, colleges, It basically covers a city, It covers an entire country, a
hospitals, offices, etc., can a small town, or any subcontinent, or an
privately use it. given area with a bigger equivalent area.
radius than the LAN.
Network Topology
The Network Topology is the layout arrangement of the different devices in a network. Some
types of network topologies are:
Bus Topology: In bus topology all devices are connected to a single central cable called a bus.
Data is sent along this cable, and all devices share the same connection. Simple and cheap to
set up but if the main cable fails the whole network goes down.
Star Topology: In star topology all devices are connected to a central node called hub or
switch. The hub controls the flow of data between devices. If one device fails, the rest of the
network is unaffected. But if the central hub fails the whole network stops working.
Ring Topology: In ring topology devices are connected in a circular loop with each device
connected to two others. Data travels in one direction (or sometimes both) passing through
each device until it reaches its destination. A failure in one device can affect the whole
network.
Mesh Topology: In mesh topology every device is connected to every other device in the
network. It provides multiple paths for data so if one path fails another can take over.
Tree Topology: Tree topology is the combination of star and bus topology. Tree topology is
good for organizing large networks and allows for easy expansion.
Hybrid Topology: Hybrid topology is the combination of two or more different topologies
(like star and mesh). It is flexible and can be customized based on the network’s specific
needs.
Network Topology
Modes of communication:
1. Simplex Communication: It is one-way communication, or we can say that unidirectional
communication in which one device only receives, and another device only sends data and
devices uses their entire capacity in transmission. For example, IoT, entering data using a
keyboard, listening to music using a speaker, etc.
2. Half Duplex communication: It is a two-way communication, or we can say that it is a
bidirectional communication in which both the devices can send and receive data but not at
the same time. When one device is sending data then another device is only receiving and
vice-versa. For example, walkie-talkie.
3. Full-duplex communication: It is a two-way communication, or we can say that it is a
bidirectional communication in which both the devices can send and receive data at the same
time. For example, mobile phones, landlines, etc.
Introduction to Internet and its safeguards: The Internet is a vast network that connects computers
all over the world. Through the Internet, people can share information and communicate from
anywhere with an Internet connection.
Difference between world wide web &internet
The world wide web uses HTTP. The Internet uses IP Addresses.
URL: URL or Uniform Resource Locator is a Unique identifier that is contained by all the resources
available on the internet. It can help to locate a particular resource due to its uniqueness. It is also
known as the web address. A URL consists of different parts like protocol, domain name, etc. The
users can access the URLs by simply typing them inside the address bar or by clicking any button or
link web page.
Example: https://www.iul.ac.in./
Web Browser: The web browser is an example of application software that is developed to retrieve
and view the information from web pages or HTML files present on the web servers. The first web
browser was invented by Sir Tim Berners-Lee in 1990, and the very first graphical web browser was
developed in 1993 and is named the mosaic. After that, various web browsers were developed. Some
of them are navigator, which is developed by Netscape communication, Microsoft Edge, Google
Chrome, Mozilla Firefox, Opera, and Apple safari.
Search Engine: A search engine is a kind of website through which users can search the content
available on the Internet. For this purpose, users enter the desired keywords into the search field. Then
the search engine looks through its index for relevant web pages and displays them in the form of a
list. The Internet is a huge source of information & resources and to access the resource from the
Internet there are some kinds of software, this software is known as a Search Engine. Some of the
popular ones are Google, Bing, Yahoo, DuckDuckGo, Baidu, etc.
Firewalls: A firewall is a network security device that monitors incoming and outgoing network
traffic and decides whether to allow or block specific traffic based on a defined set of security rules.
Firewalls have been a first line of defense in network security for over 25 years.
Antivirus: Antivirus software is used to protect computers from viruses. Viruses can cause a lot of
damage to a computer, including deleting files, corrupting data, or even crashing the computer.
Antivirus software helps to protect the computer from these threats. It does this by scanning all of the
files on the computer for viruses and then deleting or quarantining any infected files.
Working of Antivirus
Virus: A computer virus is a type of malicious software, or malware, that infects computers and
corrupts their data and software. Worm, ILOVEYOU, SQL Slammer, Stuxnet, Crypto Locker, Tinba,
Welchia, and Shlayer are some examples of computer viruses.
Translator: A translator or programming language processor is a computer program that converts the
programming instructions written in human convenient form into machine language codes that the
computers understand and process. It is a generic term that can refer to a compiler, assembler or
internet—anything that converts code from one computer language into another.
These include translations between high level and human-readable computer languages such as C++
and Java, intermediate-level languages such as java bytecode, low level languages such as
the assembly language and machine code, and between similar levels of language on different
computing platform.
Compiler: The language processor that reads the complete source program written in high-level
language in one go and translates it into an equivalent program in machine language is called a
Compiler. Example: C,C++, C#.
In a compiler, the source code is translated to object code successfully if it is free of errors. The
compiler specifies the errors at the end of the compilation with line numbers when there are any errors
in the source code. The errors must be removed before the compiler can successfully recompile the
source code again the object program can be executed number of times without translating it again.
Working of compiler
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.
example, the architecture of intel 8085 and intel 8086 are different.
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.
Algorithm: The word Algorithm means ” A set of finite rules or instructions to be followed in
calculations or other problem-solving operations ”
Or
“ A procedure for solving a mathematical problem in a finite number of steps that frequently involves
recursive operations”.
Characteristics of an Algorithm:
The need for algorithms:
1. Algorithms are necessary for solving complex problems efficiently and effectively.
2. They help to automate processes and make them more reliable, faster, and easier to perform.
3. Algorithms also enable computers to perform tasks that would be difficult or impossible for
humans to do manually.
4. They are used in various fields such as mathematics, computer science, engineering, finance,
and many others to optimize processes, analyse data, make predictions, and provide solutions
to problems.
Example: Algorithm:
1. Start
2. Now initialise c = 1
3. Now we check the condition if c < 11, then goto step 4 otherwise goto step 6.
4. Print c
5. c = c + 1 then goto step 3
6. Stop
Flowchart: A flowchart is a type of diagram that represents a workflow or process. A flowchart can
also be defined as a diagrammatic representation of an algorithm, a step-by-step approach to solving a
task.
Flowchart symbols:
Different types of boxes are used to make flowcharts flowchart Symbols. All the different kinds of
boxes are connected by arrow lines. Arrow lines are used to display the flow of control. Let’s learn
about each box in detail.
Solved Examples on Flowchart
Question 1. Draw a flowchart to find the greatest number among the 2 numbers.
Solution:
Algorithm:
1. Start
2. Input 2 variables from user
3. Now check the condition If a > b, goto step 4, else goto step 5.
4. Print a is greater, goto step 6
5. Print b is greater
6. Stop
FlowChart:
Question 2. Draw a flowchart to check whether the input number is odd or even
Solution:
Algorithm:
1. Start
2. Put input a
3. Now check the condition if a % 2 == 0, goto step 5. Else goto step 4
4. Now print(“number is odd”) and goto step 6
5. Print(“number is even”)
6. Stop
Flowchart:
Question 3. Draw a flowchart to print the input number 5 times.
Solution:
Algorithm:
1. Start
2. Input number a
3. Now initialise c = 1
4. Now we check the condition if c <= 5, goto step 5 else, goto step 7.
5. Print a
6. c = c + 1 and goto step 4
7. Stop
FlowChart:
Flowchart to print the input number 5 times