Programming Notes 1
Programming Notes 1
A computer is an electronic device that can be programmed to accept data (input), process it and
generate result (output). A computer along with additional hardware and software together is called
a computer system. A computer system primarily comprises a central processing unit (CPU),
memory, input/output devices and storage devices. All these components function together as a
single unit to deliver the desired output. A computer system comes in various forms and sizes. It
can vary from a high-end server to personal desktop, laptop, tablet computer, or a smartphone.
Figure 1.1 shows the block diagram of a computer system. The directed lines represent the
flow of data and signal between the components.
It is the electronic circuitry of a computer that carries out the actual processing and usually referred
as the brain of the computer. It is commonly called processor also. Physically, a CPU can be placed
on one or more microchips called integrated circuits (IC). The ICs comprise semiconductor
materials.
The CPU is given instructions and data through programs. The CPU then fetches the program and
data from the memory and performs arithmetic and logic operations as per the given instructions
and stores the result back to memory. While processing, the CPU stores the data as well as
instructions in its local memory called registers. Registers are part of the CPU chip and they are
limited in size and number. Different registers are used for storing data, instructions or
intermediate results. Other than the registers, the CPU has two main components — Arithmetic
Logic Unit (ALU) and Control Unit (CU). ALU performs all the arithmetic and logic operations
that need to be done as per the instruction in a program. CU controls sequential instruction
execution interprets instructions and guides data flow through the computer’s memory, ALU and
input or output devices. CPU is also popularly known as microprocessor.
The devices through which control signals are sent to a computer are termed as input devices.
These devices convert the input data into a digital form that is acceptable by the computer system.
Some examples of input devices include keyboard, mouse, scanner, touch screen, etc., Besides, we
can now enter data through voice, for example, we can use Google voice search to search the web
where we can input the search string through our voice. Data entered through input device is
temporarily stored in the main memory (also called RAM) of the computer system. For permanent
storage and future use, the data as well as instructions are stored permanently in additional storage
locations called secondary memory.
The device that receives data from a computer system for display, physical production, etc., is
called output device. It converts digital information into human understandable form. For example,
monitor projector, headphone, speaker, printer, etc.
Software
Till now, we have studied about the physical components or the hardware of the computer system.
But the hardware is of no use on its own. Hardware needs to be operated by a set of instructions.
These sets of instructions are referred to as software. It is that component of a computer system,
which we cannot touch or view physically. It comprises the instructions and data to be processed
using the computer hardware. The computer software and hardware complete any task together.
The software comprises a set of instructions which on execution deliver the desired outcome. In
other words, each software is written for some computational purpose. Some examples of software
include operating systems like Ubuntu or Windows 7/10, word processing tool like LibreOffice or
Microsoft Word, video player like VLC Player, photo editors like GIMP and LibreOffice draw. A
document or image stored on the hard disk or pen drive is referred to as a soft-copy. Once printed,
the document or an image is called a hard-copy.
Need of Software
The sole purpose of a software is to make the computer hardware useful and operational. A
software knows how to make different hardware components of a computer work and
communicate with each other as well as with the end-user. We cannot instruct the hardware of a
computer directly. Software acts as an interface between human users and the hardware.
Depending on the mode of interaction with hardware and functions to be performed, the software
can be broadly classified into three categories viz. (i) System software, (ii) Programming tools and
(iii) Application software.
System Software
System software is software that directly operates the computer hardware and provides the basic
functionality to the users as well as to the other software to operate smoothly. Or in other words,
system software basically controls a computer’s internal functioning and also controls hardware
devices such as monitors, printers, and storage devices, etc. It is like an interface between hardware
and user applications, it helps them to communicate with each other because hardware understands
machine language (i.e. 1 or 0) whereas user applications are work in human-readable languages
like English, Hindi, German, etc. so system software converts the human-readable language into
machine language and vice versa.
The software that provides the basic functionality to operate a computer by interacting directly
with its constituent hardware is termed as system software. A system software knows how to
operate and use different hardware components of a computer. It provides services directly to the
end user, or to some other software. Examples of system software include operating systems,
system utilities, device drivers, etc.
As the name implies, the operating system is a system software that operates the computer. An
operating system is the most basic system software, without which other software cannot work.
The operating system manages other application programs and provides access and security to the
users of the system. Some of the popular operating systems are Windows, Linux, Macintosh,
Ubuntu, Fedora, Android, iOS, etc.
As the name signifies, the purpose of a device driver is to ensure proper functioning of a particular
device. When it comes to the overall working of a computer system, the operating system does the
work. But everyday new devices and components are being added to a computer system. It is not
possible for the operating system alone to operate all of the existing and new devices, where each
device has diverse characteristics. The responsibility for overall control, operation and
management of a particular device at the hardware level is delegated to its device driver. The
device driver acts as an interface between the device and the operating system. It provides required
services by hiding the details of operations performed at the hardware level of the device. Just like
a language translator, a device driver acts as a mediator between the operating system and the
attached device.
Programming Tools
In order to get some work done by the computer, we need to give instructions which are applied
on the input data to get the desired outcome. Computer languages are developed for writing these
instructions. It is important to understand here that computers and humans understand completely
different languages. While humans are able to write programs in high-level language, computers
understand machine language. There is a continuous need for conversion from high level to
machine level language, for which translators are needed. Also, to write the instruction, code
editors (e.g., IDLE in Python) are needed. We will briefly describe here the programming
languages, language translators and program development tools.
Application Software
Software that performs special functions or provides functions that are much more than the basic
operation of the computer is known as application software. Or in other words, application
software is designed to perform a specific task for end-users. It is a product or a program that is
designed only to fulfill end-users’ requirements. It includes word processors, spreadsheets,
database management, inventory, payroll programs, etc.
The system software provides the core functionality of the computer system. However, different
users need the computer system for different purposes depending upon their requirements. Hence,
a new category of software is needed to cater to different requirements of the endusers. This
specific software that works on top of the system software is termed as application software. There
are again two broad categories of application software— general purpose and customized
application software.
The application software developed for generic applications, to cater to a bigger audience in
general are called general purpose software. Such ready-made application software can be used by
end users as per their requirements. For example, spreadsheet tool Calc of LibreOffice can be used
by any computer user to do calculation or to create account sheet. Adobe Photoshop, GIMP,
Mozilla web browser, iTunes, etc., fall in the category of general-purpose software.
These are custom or tailor-made application software, that are developed to meet the requirements
of a specific organization or an individual. They are better suited to the needs of an individual or
an organization, considering that they are designed as per special requirements. Some examples of
user-defined software include websites, school management software, accounting software, etc. It
is similar to buying a piece of cloth and getting a tailor-made garment with the fitting, colour, and
fabric of our choice.
Less interactive for the users More interactive for the users
Computing Environments
Computing environments refer to the technology infrastructure and software platforms that are
used to develop, test, deploy, and run software applications. There are several types of computing
environments, including:
In the world of technology where every tasks are performed with help of computers, these
computers have become one part of human life. Computing is nothing but process of completing
a task by using this computer technology and it may involve computer hardware and/or software.
But computing uses some form of computer system to manage, process, and communicate
information.
Computing Environments: When a problem is solved by the computer, during that computer
uses many devices, arranged in different ways and which work together to solve problems. This
constitutes a computing environment where various number of computer devices arranged in
different ways to solve different types of problems in different ways. In different computing
environments computer devices are arranged in different ways and they exchange information in
between them to process and solve problem. One computing environment consists of many
computers’ other computational devices, software and networks that to support processing and
sharing information and solving task. Based on the organization of different computer devices and
communication processes there exists multiple types of computing environments.
Types of Computing Environments: There are the various types of computing environments.
They are:
ALGORITHM
An Algorithm is a step-by-step procedure to solve a given problem. The word algorithm originates
from the word ‘algorism’ which means process of doing arithmetic with Arabic numerals.
Characteristics of algorithm:
1. Input: Algorithm starts with procedural steps to accept input data. The algorithm must accept
one or more data to be processed.
2. Definite: Each operational step or operation must be definite i.e. each and every instruction
must clearly specify that what should be done.
3. Effective: Each operational step can at least in principle is carried out by a person using a
paper and pencil in a minimum number of times.
4. Terminate: After some minimum number operation algorithm must come to an end.
5. Output: An algorithm is written to solve the problem; therefore it must produce one or more
computed result or answer called output.
What is a Flowchart?
1. Terminal: The oval symbol indicates Start, Stop and Halt in a program’s logic
flow. A pause/halt is generally used in a program logic under some error conditions.
Terminal is the first and last symbols in the flowchart.
• Flow lines: Flow lines indicate the exact sequence in which instructions are
executed. Arrows represent the direction of flow of control and relationship among
different symbols of flowchart.
Rules For Creating Flowchart:
Advantages of Flowchart:
• Flowcharts are a better way of communicating the logic of the system.
• Flowcharts act as a guide for blueprint during program designed.
• Flowcharts help in debugging process.
• With the help of flowcharts programs can be easily analyzed.
• It provides better documentation.
• Flowcharts serve as a good proper documentation.
• Easy to trace errors in the software.
• Easy to understand.
• The flowchart can be reused for inconvenience in the future.
• It helps to provide correct logic.
Disadvantages of Flowchart:
• It is difficult to draw flowcharts for large and complex programs.
• There is no standard to determine the amount of detail.
• Difficult to reproduce the flowcharts.
• It is very difficult to modify the Flowchart.
• Making a flowchart is costly.
• Some developer thinks that it is waste of time.
• It makes software processes low.
• If changes are done in software, then the flowchart must be redrawn
What Is Pseudo-Code in C?
In C programming language, it becomes mandatory to follow syntax while executing the program,
and it becomes challenging to understand the logic of the complex program. Therefore, to
understand the program logic in a better way and to solve the complex problem, you must write it
in pseudocode, which is written in simple English that makes it easy to understand.
The pseudocode in C is an informal way of writing a program for better human understanding. It
is written in simple English, making the complex program easier to understand.
Pseudocode cannot be compiled or interpreted. It doesn't follow the programming language's
syntax; it is thus written in pseudocode so that any programmers or non-programmers can easily
understand it.
pseudo-code for Factorial Program
Start program
Display fact
End program
Rather than focusing on the execution of statements, functional languages focus on the output of
mathematical functions and evaluations. Each function–a reusable module of code–performs a
specific task and returns a result. The result will vary depending on what data you input into the
function. Some popular functional programming languages include:
• Scala
• Erlang
• Haskell
• Elixir
• F#
This type of language treats a program as a group of objects composed of data and program
elements, known as attributes and methods. Objects can be reused within a program or in other
programs. This makes it a popular language type for complex programs, as code is easier to reuse
and scale. Some common object-oriented programming (OOP) languages include:
• Java
• Python
• PHP
• C++
• Ruby
4. Scripting languages
Programmers use scripting languages to automate repetitive tasks, manage dynamic web content,
or support processes in larger applications. Some common scripting languages include:
• PHP
• Ruby
• Python
• bash
• Perl
• Node.js
Instead of telling a computer what to do, a logic programming language expresses a series of facts
and rules to instruct the computer on how to make decisions. Some examples of logic languages
include:
• Prolog
• Absys
• Datalog
• Alma-0
1. First-Generation Language :
The first-generation languages are also called machine languages/ 1G language. This language
is machine-dependent. The machine language statements are written in binary code (0/1 form)
because the computer can understand only binary language.
Advantages :
1. Fast & efficient as statements are directly written in binary language.
2. No translator is required.
Disadvantages :
1. Difficult to learn binary codes.
2. Difficult to understand – both programs & where the error occurred.
2. Second Generation Language :
The second-generation languages are also called assembler languages/ 2G languages. Assembly
language contains human-readable notations that can be further converted to machine language
using an assembler.
Assembler – converts assembly level instructions to machine-level instructions.
Programmers can write the code using symbolic instruction codes that are meaningful
abbreviations of mnemonics. It is also known as low-level language.
Advantages :
1. It is easier to understand if compared to machine language.
2. Modifications are easy.
3. Correction & location of errors are easy.
Disadvantages :
1. Assembler is required.
2. This language is architecture /machine-dependent, with a different instruction set for different
machines.
3. Third-Generation Language :
The third generation is also called procedural language /3 GL. It consists of the use of a series
of English-like words that humans can understand easily, to write instructions. It’s also called
High-Level Programming Language. For execution, a program in this language needs to be
translated into machine language using a Compiler/ Interpreter. Examples of this type of
language are C, PASCAL, FORTRAN, COBOL, etc.
Advantages :
1. Use of English-like words makes it a human-understandable language.
2. Lesser number of lines of code as compared to the above 2 languages.
3. Same code can be copied to another machine & executed on that machine by using compiler-
specific to that machine.
Disadvantages :
1. Compiler/ interpreter is needed.
2. Different compilers are needed for different machines.
4. Fourth Generation Language :
The fourth-generation language is also called a non – procedural language/ 4GL. It enables users
to access the database. Examples: SQL, Foxpro, Focus, etc.
These languages are also human-friendly to understand.
Advantages :
1. Easy to understand & learn.
2. Less time is required for application creation.
3. It is less prone to errors.
Disadvantages :
1. Memory consumption is high.
2. Has poor control over Hardware.
3. Less flexible.
5. Fifth Generation Language :
The fifth-generation languages are also called 5GL. It is based on the concept of artificial
intelligence. It uses the concept that rather than solving a problem algorithmically, an
application can be built to solve it based on some constraints, i.e., we make computers learn to
solve any problem. Parallel Processing & superconductors are used for this type of language to
make real artificial intelligence.
Examples: PROLOG, LISP, etc.
Advantages :
1. Machines can make decisions.
2. Programmer effort reduces to solve a problem.
3. Easier than 3GL or 4GL to learn and use.
Disadvantages :
1. Complex and long code.
2. More resources are required & they are expensive too.