Computer Programming 1st Edition E. Balagurusamy download
Computer Programming 1st Edition E. Balagurusamy download
Balagurusamy
pdf download
https://ebookgate.com/product/computer-programming-1st-edition-e-
balagurusamy/
https://ebookgate.com/product/programming-in-ansi-c-6th-edition-e-
balagurusamy/
ebookgate.com
https://ebookgate.com/product/c-programming-data-structures-4th-
edition-e-balagurusamy/
ebookgate.com
https://ebookgate.com/product/computer-programming-for-teens-1st-
edition-mary-e-farrell/
ebookgate.com
https://ebookgate.com/product/advanced-computer-programming-in-
python-1st-edition-karim-pichara/
ebookgate.com
Computer Arithmetic Volume I Earl E Swartzlander
https://ebookgate.com/product/computer-arithmetic-volume-i-earl-e-
swartzlander/
ebookgate.com
https://ebookgate.com/product/practical-programming-an-introduction-
to-computer-science-using-python-jennifer-campbell/
ebookgate.com
https://ebookgate.com/product/programming-with-java-a-primer-3-e-3rd-
edition-e-balaguruswamy/
ebookgate.com
https://ebookgate.com/product/mathematics-for-3d-game-programming-and-
computer-graphics-second-edition-eric-lengyel/
ebookgate.com
https://ebookgate.com/product/numerical-computer-methods-part-e-1st-
edition-michael-l-johnson/
ebookgate.com
As per
JNTU-Hyderabad
Syllabus regulation
2013
Computer Programming
First Edition
About the Author
E Balagurusamy, former Vice Chancellor, Anna University, Chennai, is currently Member, Union Public
Service Commission, New Delhi. He is a teacher, trainer, and consultant in the fields of Information
Technology and Management. He holds an ME (Hons) in Electrical Engineering and PhD in Systems
Engineering from the Indian Institute of Technology, Roorkee. His areas of interest include Object-Oriented
Software Engineering, Electronic Business, Technology Management, Business Process Re-engineering, and
Total Quality Management.
A prolific writer, he has authored a large number of research papers and several books. His best selling
books, among others, include:
• Computing Fundamentals and C Programming
• Fundamentals of Computers
• Programming in C#, 3/e
• Programming in Java, 4/e
• Object-Oriented Programming with C++, 5/e
• Programming in BASIC, 3/e
• Programming in ANSI C, 5/e
• Numerical Methods
• Reliability Engineering
A recipient of numerous honours and awards, he has been listed in the Directory of Who’s Who of
Intellectuals and in the Directory of Distinguished Leaders in Education.
As per
JNTU-Hyderabad
Syllabus regulation
2013
Computer Programming
First Edition
E Balagurusamy
Chairman
EBG Foundation
Coimbatore
Computer Programming, 1e
Copyright © 2014, by McGraw Hill Education (India) Private Limited.
No part of this publication may be reproduced or distributed in any form or by any means, electronic, mechanical,
photocopying, recording, or otherwise or stored in a database or retrieval system without the prior written permission of
the publishers. The program listing (if any) may be entered, stored and executed in a computer system, but they may not
be reproduced for publication.
This edition can be exported from India only by the publishers,
McGraw Hill Education (India) Private Limited.
Information contained in this work has been obtained by McGraw Hill Education (India), from sources believed to be reliable.
However, neither McGraw Hill Education (India) nor its authors guarantee the accuracy or completeness of any information
published herein, and neither McGraw Hill Education (India) nor its authors shall be responsible for any errors, omissions,
or damages arising out of use of this information. This work is published with the understanding that McGraw Hill Education
(India) and its authors are supplying information but are not attempting to render engineering or other professional services.
If such services are required, the assistance of an appropriate professional should be sought.
Typeset at Text-o-Graphics, B-1/56, Aravali Apartment, Sector-34, Noida 201 301, and printed at
Cover Printer:
Content
Preface xv
Roadmap to the Syllabus xix
2 Introduction to C 2.1-2.147
2.1 Introduction 2.1
2.2 Overview of C 2.2
2.2.1 History of C 2.2
2.2.2 Characteristics of C 2.4
2.2.3 Sample Program 1: Printing a Message 2.4
2.2.4 Sample Program 2: Adding Two Numbers 2.7
2.2.5 Sample Program 3: Interest Calculation 2.8
2.2.6 Sample Program 4: Use of Subroutines 2.10
2.2.7 Sample Program 5: Use of Math functions 2.11
2.3 Basic Structure of C Programs 2.13
2.4 Programming Style 2.13
2.5 Executing A ‘C’ Program 2.14
2.6 UNIX System 2.15
2.7 C Character Set 2.17
2.7.1 Trigraph Characters 2.19
2.8 C Tokens 2.19
2.9 Keywords and Identifiers 2.20
2.10 Constants 2.21
2.10.1 Integer Constants 2.21
2.10.2 Real Constants 2.22
2.10.3 Single Character Constants 2.23
2.10.4 String Constants 2.24
2.11 Variables 2.24
2.12 Data Types 2.25
Contents vii
Appendix A A.1-A.12
The developments in digital electronics and related technologies during the last few decades have ushered
in the second Industrial Revolution that is popularly referred to as the Information Revolution. Computer
technology plays an ever-increasing role in this new revolution. Today, the application of computers is all
pervasive in everybody’s life. A sound knowledge of how computers process data and information has,
therefore, become indispensable for anyone who seeks employment not only in the area of IT but also in any
other field.
COMPUTER PROGRAMMING
Computer programming is dedicated to writing, testing and maintaining programs that computers follow to
perform their functions. To create programs that control the behaviour of a machine, we need programming
languages. This book enables students to master the necessary skills for computer programming with C
language and shows them how to use these skills wisely with data structures and algorithms.
DATA STRUCTURES
Data structures are prevalent in almost every program, since they provide specialised formats of storing and
organising data in a computer. This book presents the design and implementation of data structures using
standard ANSI C programming language.
xvi Preface
PEDAGOGICAL FEATURES
• Bottom-up approach of explaining concepts.
• Algorithms and flowcharts are covered extensively.
• Codes and comments illustrate the use of various features of the language.
• Special boxes feature supplementary information and notes that complement the text.
• Case studies in relevant chapters demonstrate real-life applications.
• Just remember section lists out helpful hints and possible problem areas.
• Review questions (132) provide ample opportunities to test the conceptual understanding.
• Programming exercises (135) simulate interest to practice programming applications.
• Solved examples and programs (200) have been tested using compilers compatible to both UNIX
and MS-DOS operating systems and, wherever appropriate, the nature of output has been discussed.
These programs also demonstrate the general principles of a good programming style.
• Multiple choice questions (179) help students test their conceptual understanding of the subject.
• Lab assignments are given as per the new syllabus.
• Updated with information on compiler C-99 supported by numerous programs (12) using C-99.
• Solutions to 2011 exam question papers (4 sets) and 2012 exam question paper.
Preface xvii
CD RESOURCES
The book is accompanied with a CD which provides the following resources:
• All lab assignments
• Previous years’ solved university question papers
• 208 additional objective/ review/ debugging type questions pertaining to each unit
• 5 Model Question Papers
The supplementary CD helps students master the programming language and write their own programs
using Computer programming concepts and data structures.
ACKNOWLEDGEMENTS
The author is grateful to Mrs Nagaratna Parameshwar Hegde of Vasavi College of Engineering, Hyderabad
for her useful comments and suggestions.
E Balagurusamy
PUBLISHER’S NOTE
McGraw Hill Education (India) looks forward to receiving from teachers and students their valuable views,
comments and suggestions for improvements, all of which may be sent to tmh.corefeedback@gmail.com
(mentioning the title and author’s name). Also, please inform any observations on piracy related issues.
Roadmap to the Syllabus
COMPUTER PROGRAMMING
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
GO TO:
CHAPTER 1. Introduction to Computers
CHAPTER 2. Introduction to C
Module 2: Functions-Designing Structured Programs, Functions, user defined functions, inter function
communication, Standard functions, Scope, Storage classes-auto, register, static, extern, scope rules, type
qualifiers, recursion–recursive functions, Limitations of recursion, example C programs, Preprocessor
commands.
Arrays—Concepts, using arrays in C, inter function communication, array applications, two-dimensional
arrays, multidimensional arrays, C program examples.
GO TO:
CHAPTER 3A. Functions
CHAPTER 3B. Arrays
Module 3: Pointers—Introduction (Basic Concepts), Pointers for inter function communication, pointers
to pointers, compatibility, Pointer Applications-Arrays and Pointers, Pointer Arithmetic and arrays,
Passing an array to a function, memory allocation functions, array of pointers, programming applications,
pointers to void, pointers to functions.
Strings—Concepts, C Strings, String Input I Output functions, arrays of strings, string manipulation
functions, string I data conversion, C program examples.
GO TO:
CHAPTER 4A. Pointers
CHAPTER 4B. Strings
xx Roadmap to the Syllabus
Module 4: Enumerated, Structure, and Union Types—The Type Definition (typedef), Enumerated types,
Structures—Declaration, initialization, accessing structures, operations on structures, Complex structures,
structures and functions, Passing structures through pointers, self referential structures, unions, bit fields,
C programming examples, command-line arguments,
Input and Output—Concept of a file, streams, text files and binary files, Differences between text and
binary files, State of a file, Opening and Closing files, file input 1 output functions (standard library
input 1 output functions for files), file status functions (error handling), Positioning functions, C program
examples.
GO TO:
CHAPTER 5. Structures and Unions
CHAPTER 6. File Management in C
Module 5: Searching and Sorting—Sorting-selection sort, bubble sort, Searching-linear and binary
search methods.
Lists- Linear list—singly linked list implementation, insertion, deletion and searching operations on
linear list, StacksPush and Pop Operations, Queues—Enqueue and Dequeue operations.
GO TO:
CHAPTER 7. Sorting and Searching Techniques
CHAPTER 8. Data Structures
UNIT
1 Introduction to
Computers
1.1 INTRODUCTION
The term computer is derived from the word INPUT OUTPUT
compute. A computer is an electronic device Data PROCESS Information
that takes data and instructions as an input from
the user, processes data, and provides useful
information known as output. This cycle of Instructions
operation of a computer is known as the input–
Fig. 1.1 Input–process–output concept
process–output cycle and is shown in Fig. 1.1
The electronic device is known as hardware and
the set of instructions is known as software.
A computer consists of various components that function as an integrated system to perform computational
tasks. These components include the following:
• Central Processing Unit (CPU) It is the brain of the computer that is responsible for controlling
and executing program instructions.
• Monitor It is a display screen, which shows information in visual form.
• Keyboard and Mouse These are the peripheral devices used by the computer for receiving inputs
from the user.
Figure 1.2 shows the various components of a computer.
The unique capabilities and characteristics of a computer have made it very popular among its various
users, including engineers, managers, accountants, teachers, students, etc.
Some of the key characteristics of a modern digital computer include, among others the following:
• Speed The computer is a fast electronic device that can solve large and complex problems in few
seconds. The speed of a computer generally depends upon its hardware configuration.
• Storage capacity A computer can store huge amounts of data in many different formats. The storage
area of a computer system is generally divided into two categories, main memory and secondary
storage.
1.2 Computer Programming
Monitor
CPU
Keyboard
Mouse
as secondary memory. Primary memory includes Random Access Memory (RAM) and secondary
memory includes hard disks and floppy disks.
Software supports the functioning of a computer system internally and cannot be seen. It is stored on
secondary memory and can be an application software as well as system software. The application software
is used to perform a specific task according to requirements and the system software is mandatory for running
application software. The examples of application software include Excel and MS Word and the examples of
system software include operating system and networking system.
All the hardware components interact with each other as well as with the software. Similarly, the different
types of software interact with each other and with the hardware components. The interaction between various
hardware components is illustrated in Fig. 1.3.
1.2.1 Input Devices
Input devices can be connected to the computer system using cables. The most commonly used input devices
among others are:
• Keyboard
• Mouse
• Scanner
Magnetic Magnetic
Tape Disk
Arithmetic
Unit
Control
Unit
CPU
Data and results flow
Control Instructions to units
Instructions to control unit
Keyboard
A standard keyboard includes alphanumeric keys, function keys, modifier keys, cursor movement keys,
spacebar, escape key, numeric keypad, and some special keys, such as Page Up, Page Down, Home, Insert,
Delete and End. The alphanumeric keys include the number keys and the alphabet keys. The function keys
are the keys that help perform a specific task such as searching a file or refreshing a Web page. The modifier
1.4 Computer Programming
keys such as Shift and Control keys modify the casing style of a character or symbol. The cursor movement
keys include up, down, left and right keys and are used to modify the direction of the cursor on the screen.
The spacebar key shifts the cursor to the right by one position. The numeric keypad uses separate keypads for
numbers and mathematical operators. A keyboard is show in Fig. 1.4.
Function Keys
(F1 to F12)
Escape Key
Special Keys
Numeric Keypad
Modifier Keys
Mouse
The mouse allows the user to select elements on the screen, such Wheel
as tools, icons, and buttons, by pointing and clicking them. We can Right Button
also use a mouse to draw and paint on the screen of the computer Left Button
system. The mouse is also known as a pointing device because it
helps change the position of the pointer or cursor on the screen.
The mouse consists of two buttons, a wheel at the top and a
ball at the bottom of the mouse. When the ball moves, the cursor
on the screen moves in the direction in which the ball rotates. The Fig. 1.5 Mouse
left button of the mouse is used to select an element and the right
button, when clicked, displays the special options such as open and explore and shortcut menus. The wheel
is used to scroll down in a document or a Web page. A mouse is shown in Fig. 1.5.
Scanner
A scanner is an input device that converts documents and images as the
digitized images understandable by the computer system. The digitized
images can be produced as black and white images, gray images, or
colored images. In case of colored images, an image is considered as a
collection of dots with each dot representing a combination of red, green,
and blue colors, varying in proportions. The proportions of red, green, and
blue colors assigned to a dot are together called as color description. The
scanner uses the color description of the dots to produce a digitized image.
Fig. 1.6 shows a scanner.
There are the following types of scanners that can be used to produce Fig. 1.6 Scanner
digitized images:
• Flatbed scanner It contains a scanner head that moves across a page from top to bottom to read the
page and converts the image or text available on the page in digital form. The flatbed scanner is used
to scan graphics, oversized documents, and pages from books.
Introduction to Computers 1.5
• Drum scanner In this type of scanner, a fixed scanner head is used and the image to be scanned is
moved across the head. The drum scanners are used for scanning prepress materials.
• Slide scanner It is a scanner that can scan photographic slides directly to produce files understandable
by the computer.
• Handheld scanner It is a scanner that is moved by the end user across the page to be scanned. This
type of scanner is inexpensive and small in size.
1.2.2 CPU
The CPU consists of Control Unit (CU) and ALU. CU stores the instruction set, which specifies the operations
to be performed by the computer. CU transfers the data and the instructions to the ALU for an arithmetic
operation. ALU performs arithmetical or logical operations on the data received. The CPU registers store the
data to be processed by the CPU and the processed data also. Apart from CU and ALU, CPU seeks help from
the following hardware devices to process the data:
Motherboard
It refers to a device used for connecting the CPU with the input and output devices. The components on the
motherboard are connected to all parts of a computer and are kept insulated from each other. Some of the
components of a motherboard are:
• Buses Electrical pathways that transfer data and instructions among different parts of the computer.
For example, the data bus is an electrical pathway that transfers data among the microprocessor,
memory and input/output devices connected to the computer. The address bus is connected among
the microprocessor, RAM and Read Only Memory (ROM), to transfer addresses of RAM and ROM
locations that is to be accessed by the microprocessor.
• System clock It is a clock used for synchronizing the activities performed by the computer. The
electrical signals that are passed inside a computer are timed, based on the tick of the clock. As a
result, the faster the system clock, the faster is the processing speed of the computer.
• Microprocessor CPU component that performs the processing and controls the activities performed
by the different parts of the computer. The microprocessor is plugged to the CPU socket placed on the
motherboard.
• ROM Chip that contains the permanent memory of the computer that stores information, which
cannot be modified by the end user.
Monitor
A monitor is the most commonly used output device that produces visual
displays generated by the computer. The monitor, also known as a screen, is
connected as an external device using cables or connected either as a part of the
CPU case. The monitor connected using cables, is connected to the video card
placed on the expansion slot of the motherboard. The display device is used for
visual presentation of textual and graphical information.
The monitors can be classified as cathode ray tube (CRT) monitors or liquid
crystal display (LCD) monitors. The CRT monitors are large, occupy more space
in the computer, whereas LCD monitors are thin, light weighted, and occupy Fig. 1.8 Monitor
lesser space. Both the monitors are available as monochrome, gray scale and
color models. However, the quality of the visual display produced by the CRT is
better than that produced by the LCD.
A monitor can be characterized by its monitor size and resolution. The monitor size is the length of
the screen that is measured diagonally. The resolution of the screen is expressed as the number of picture
Introduction to Computers 1.7
elements or pixels of the screen. The resolution of the monitor is also called the dot pitch. The monitor with
a higher resolution produces a clearer image.
Printer
The printer is an output device that is used to produce a hard copy of the
electronic text displayed on the screen, in the form of paper sheets that can be
used by the end user. The printer is an external device that is connected to the
computer system using cables. The computer needs to convert the document
that is to be printed to data that is understandable by the printer. The printer
driver software or the print driver software is used to convert a document to
a form understandable by the computer. When the computer components are
upgraded, the upgraded printer driver software needs to be installed on the
computer.
Fig. 1.9 Printer
The performance of a printer is measured in terms of dots per inch (DPI)
and pages per minute (PPM) produced by the printer. The greater the DPI
parameter of a printer, the better is the quality of the output generated by it. The higher PPM represents
higher efficiency of the printer. Printers can be classified based on the technology they use to print the text
and images:
• Dot matrix printers Dot matrix printers are impact printers that use perforated sheet to print the
text. The process to print a text involves striking a pin against a ribbon to produce its impression on
the paper.
• Inkjet printers Inkjet printers are slower than dot matrix printers and are used to generate high
quality photographic prints. Inkjet printers are not impact printers. The ink cartridges are attached to
the printer head that moves horizontally, from left to right.
• Laser printers The laser printer may or may not be connected to a computer, to generate an output.
These printers consist of a microprocessor, ROM and RAM, which can be used to store the textual
information. The printer uses a cylindrical drum, a toner and the laser beam.
Speaker
The speaker is an electromechanical transducer that converts an electrical
signal into sound. They are attached to a computer as output devices, to
provide audio output, such as warning sounds and Internet audios. We can
have built-in speakers or attached speakers in a computer to warn end users
with error audio messages and alerts. The audio drivers need to be installed in
the computer to produce the audio output. The sound card being used in the
computer system decides the quality of audio that we listen using music CDs
or over the Internet. The computer speakers vary widely in terms of quality
and price. The sophisticated computer speakers may have a subwoofer unit, to
enhance bass output. Fig. 1.10 Speakers
Plotter
The plotter is another commonly used output device that is connected to a computer to print large documents,
such as engineering or constructional drawings. Plotters use multiple ink pens or inkjets with color cartridges
1.8 Computer Programming
for printing. A computer transmits binary signals to all the print heads of the plotter. Each binary signal
contains the coordinates of where a print head needs to be positioned for printing. Plotters are classified on
the basis of their performance, as follows:
• Drum plotter They are used to draw perfect circles and other graphic images. They use a drawing
arm to draw the image. The drum plotter moves the paper back and forth through a roller and the
drawing arm moves across the paper.
• Flat-bed plotter A flat bed plotter has a flat drawing surface and the two drawing arms that move
across the paper sheet, drawing an image. The plotter has a low speed of printing and is large in
size.
• Inkjet plotter Spray nozzles are used to generate images by spraying droplets of ink onto the paper.
However, the spray nozzles can get clogged and require regular cleaning, thus resulting in a high
maintenance cost.
• Electrostatic plotter As compared to other plotters, an electrostatic plotter produces quality print
with highest speed. It uses charged electric wires and special dielectric paper for drawing.
Control
Buttons
Plotted
Paper
1.2.4 Memory
The memory unit of a computer is used to store data, instructions for processing data, intermediate results
of processing and the final processed information. The memory units of a computer are classified as primary
memory and secondary memory. Figure 1.12 shows the memory categorization in a computer system.
Introduction to Computers 1.9
Primary Memory
The primary memory is available in the computer as a built-in unit of the computer. The primary memory is
represented as a set of locations with each location occupying 8 bits. Each bit in the memory is identified by
a unique address. The data is stored in the machine-understandable binary form in these memory locations.
The commonly used primary memories are:
• ROM ROM represents Read Only Memory that stores data and instructions, even when the
computer is turned off. It is the permanent memory of the computer where the contents cannot be
modified by an end user. ROM is a chip that is inserted into the motherboard. It is generally used to
store the Basic Input/Output system (BIOS), which performs the Power On Self Test (POST).
• RAM RAM is the read/write memory unit in
which the information is retained only as long
as there is a regular power supply. When the
power supply is interrupted or switched off, the
information stored in the RAM is lost. RAM is a
volatile memory that temporarily stores data and
applications as long as they are in use. When the
Integrated
use of data or the application is over, the content in chips
RAM is erased.
Fig. 1.13 RAM
• Cache memory Cache memory is used to store
the data and the related application that was last processed by the CPU. When the processor performs
processing, it first searches the cache memory and then the RAM, for an instruction. The cache
memory is always placed between CPU and the main memory of the computer system.
1.10 Computer Programming
Table 1.1 depicts some of the key differences between RAM and ROM:
TABLE 1.1
RAM ROM
It is a read/write memory It is a read only memory
It is volatile storage device It is a permanent storage device
Data is erased as soon as power supply is Data remains stored even after power supply
turned off has been turned off
It is used as the main memory of a computer It is used to store Basic input output system
system (BIOS).
Secondary Memory
Secondary memory represents the external storage devices that are connected to the computer. They provide
a non-volatile memory source used to store information that is not in use currently. A storage device is either
located in the CPU casing of the computer or is connected externally to the computer. The secondary storage
devices can be classified as:
• Magnetic storage device The magnetic storage
devices store information that can be read, erased
and rewritten a number of times. These include
floppy disk, hard disk and magnetic tapes.
• Optical storage device The optical storage devices
are secondary storage devices that use laser beams
to read the stored data. These include CD-ROM,
rewritable compact disk (CD-RW), and digital video
disks with read only memory (DVD-ROM). Fig. 1.14 Magnetic tape
Tracks
Sectors
Protective coating
Dielectric
layers
Laser beams
Lens
Substrate layer
in comparison to other storage devices like CD and floppy disk. One of the most important advantages
of a USB drive is that it is larger in capacity as compared to other removable storage devices. Off late,
it has become very popular amongst computer users.
An assembly language program consists of a series of instructions and mnemonics that correspond to a
stream of executable instructions. An assembly language instruction consists of a mnemonic code followed
by zero or more operands. The mnemonic code is called the operation code or opcode, which specifies the
operation to be performed on the given arguments. Consider the following machine code:
10110000 01100001
Its equivalent assembly language representation is:
mov al, 061h
In the above instruction, the opcode “move” is used to move the hexadecimal value 61 into the processor
register named ‘al’. The following program shows the assembly language instructions to subtract two
numbers:
ORG 500 /Origin of program is location 500
LDA SUB /Load subtrahend to AC
CMA /Complement AC
INC /Increment AC
ADD MIN /Add minuend to AC
STA DIF /Store difference
HLT /Halt computer
MIN, DEC 56 /Minuend
SUB, DEC -2 /Subtrahend
DIF, HEX 0 /Difference stored here
END /End of symbolic program
It should be noted that during execution, the assembly language program is converted into the machine
code with the help of an assembler. The simple assembly language statements had one-to-one correspondence
with the machine language statements. This one-to-one correspondence still generated complex programs.
Then, macroinstructions were devised so that multiple machine language statements could be represented
using a single assembly language instruction. Even today programmers prefer to use an assembly language
for performing certain tasks such as:
• To initialize and test the system hardware prior to booting the operating system. This assembly
language code is stored in ROM
• To write patches for disassembling viruses, in anti-virus product development companies
• To attain extreme optimization, for example, in an inner loop in a processor-intensive algorithm
• For direct interaction with the hardware
• In extremely high-security situations where complete control over the environment is required
• To maximize the use of limited resources, in a system with severe resource constraints
STORE C
Using FORTRAN, the above code can be represented as:
C=A+B
The above high-level language code is executed by translating it into the corresponding machine language
code with the help of a compiler or interpreter.
High-level languages can be classified into the following three categories:
• Procedure-oriented languages (third generation)
• Problem-oriented languages (fourth generation)
• Natural languages (fifth generation)
such as LISP and PROLOG are mainly used to develop artificial intelligence and expert systems. These
languages are widely known as fifth generation languages.
The programming languages of this generation mainly focus on constraint programming, which is
somewhat similar to declarative programming. It is a programming paradigm in which the programmer only
needs to specify the solution to be found within the constraints rather than specifying the method of finding
the desired solution
The programming languages of this generation allow the users to communicate with the computer system
in a simple and an easy manner. Programmers can use normal English words while interacting with the
computer system.
Further, it suggests avoiding the use of goto, break and continue statements in a program as all these are
unconditional branch statements.
Language Translators
• Assembler An assembler is a computer program that translates assembly language statements into
machine language codes. The assembler takes each of the assembly language statements from the source
code and generates a corresponding bit stream using 0’s and 1’s. The output of the assembler in the form of
sequence of 0’s and 1’s is called object code or machine code. This machine code is finally executed to obtain
the results.
A modern assembler translates the assembly instruction mnemonics into opcodes and resolves symbolic
names for memory locations and other entities to create the object code. Several sophisticated assemblers
provide additional facilities that control the assembly process, facilitate program development, and aid
debugging. The modern assemblers like Sun SPARC and MIPS based on RISC architectures, optimize
instruction scheduling to attain efficient utilization of CPU. The modern assemblers generally include a
macro facility and are called macro assemblers.
Assemblers can be classified as single-pass assemblers and two-pass assemblers. The single-pass
assembler was the first assembler that processed the source code once to replace the mnemonics with the
binary code. The single-pass assembler was unable to support advanced source-code optimization. As a
result, the two-pass assembler was developed that read the program twice. During the first pass, all the
variables and labels are read and placed into the symbol table. On the second pass, the label gaps are filled from
the table by replacing the label name with the address. This helps to attain higher optimization of the source
code. The translation process of an assembler consists of the following tasks:
• Replacing symbolic addresses like LOOP, by numeric addresses
• Replacing symbolic operation code by machine operation codes
• Reserving storage for the instructions and data
• Translating constants into their machine representation
• Compiler The compiler is a computer program that translates the source code written in a high-level
language into the corresponding object code of the low-level language. This translation process is called
compilation. The entire high-level program is converted into the executable machine code file. A program
that translates from a low-level language to a high-level one is a decompiler. Compiled languages include
COBOL, FORTRAN, C, C++, etc.
In 1952, Grace Hopper wrote the first compiler for the A-0 programming language. In 1957, John Backus
at IBM introduced the first complete compiler. With the increasing complexity of computer architectures
and expanding functionality supported by newer programming languages, compilers have become more
Introduction to Computers 1.17
and more complex. Though early compilers were written in assembly languages, nowadays it has become
common practice to implement a compiler in the language it compiles. Compilers are also classified as single-
pass compilers and multi-pass compilers. Though single-pass compilers are generally faster than multi-pass
compilers, for sophisticated optimization, multi-pass assemblers are required to generate high-quality code.
• Interpreter The interpreter is a translation program that converts each high-level program statement
into the corresponding machine code. This translation process is carried out just before the program statement
is executed. Instead of the entire program, one statement at a time is translated and executed immediately.
The commonly used interpreted language are BASIC and PERL. Although, interpreters are easier to create as
compared to compilers, the compiled languages can be executed more efficiently and are faster.
Linkers
Most of the high-level languages allow the developer to develop a large program containing multiple modules.
Linker arranges the object code of all the modules that have been generated by the language translator into
a single program. The execution unit of the computer system is incapable of linking all the modules at
the execution time and therefore, linker is regarded as one of the important software because of its ability
to combine all the modules into a single program. Linker assembles the various objects generated by the
compiler in such a manner that all the objects are accepted as a single program during execution. Linker
also includes the links of various objects, which are defined in the runtime libraries. In many cases, linker
inserts the symbolic address of the objects in place of their real address. Figure 1.19 illustrates the working
of a linker.
Debuggers
Debugger is the software that is used to detect the errors and bugs present in the programs. The debugger
locates the position of the errors in the program code with the help of what is known as the Instruction Set
. Executable
. Linker Program
.
Language Object Code
Module n
Translator
Source Code
Routine
Libraries
Simulator (ISS) technique. ISS is capable of stopping the execution of a program at the point where an
erroneous statement is encountered.
Debugger is divided into two types, namely machine-level debugger and symbolic debugger. The machine-
level debugger debugs the object code of the program and shows all the lines where bugs are detected. On
the other hand, the symbolic debugger debugs the original code, i.e., the high-level language code of the
program. It shows the position of the bug in the original code of the program developed by the programmer.
While debugging a program, the debugger performs a number of functions other than debugging, such as
inserting breakpoints in the original code, tracking the value of specific variables, etc. In order to debug the
program, a debugger helps perform the following tasks:
• Step-by-step execution of a program
• Back tracking for checking the previous steps
• Stopping the execution of the program until the errors are corrected
Editors
Editor is a special program that allows the user to work with text in a computer system. It is used for the
documentation purposes and enables us to edit the information present in an existing document or a file. The
editor enables us to perform various editing operations such as copy, cut and paste while editing the text. On
the basis of the content edited by the editors, they are divided into the following categories:
• Text editor It is used to edit plain text. An operating system always includes a text editor for
updating the configuration files.
• Digital audio editor It is used to edit the information related to the audio components of a
multimedia application. These editors are used in audio applications where editing the music and the
sound signals is necessary.
• Graphics editor It is used to edit the information related to the graphical objects. These editors
are generally used in the multimedia applications where the user is working with multiple animation
objects.
• Binary file editor It is used to edit the digital data or the binary data, i.e., data having strings of 0s
and 1s.
• HTML editor It is used to edit the information included in the Web pages.
• Source code editor It is used to edit the source code of a program written in a programming
language such as C, C++ and Java.
factors that should be taken into consideration while selecting the target programming language, such as
performance and efficiency of the programming language, programmer’s prior experience with the language,
etc.
A programming language is typically bundled together with an IDE containing the necessary tools for
developing, editing, running and debugging a computer program. For instance, Turbo C is provided with a
strong and powerful IDE to develop, compile, debug and execute the programs.
Figure 1.20 shows the IDE of C language.
Start
False
Display ‘‘Fail’’
End
Fig. 1.21 Flowchart for calculating the percentage of marks and displaying the result.
After developing the algorithm and flowchart, the actual development of the program can be started in the
source code editor of C language. The following code shows the C language program for calculating the
percentage of marks in two different subjects for a student.
#include<stdio.h>
#include<conio.h>
void main()
{
float mark1,mark2;
float percentage;
clrscr();
printf("\n Enter marks of first subject:");
scanf("\n %f", &mark1);
printf("\n Enter marks of second subject:");
scanf("\n %f", &mark2);
percentage =((mark1+mark2)/200)*100;
if(percentage>40)
Introduction to Computers 1.21
Figure 1.22 shows the program code in the source code editor of C language.
Analysing the
requirements
Feasibility
Analysis
Creating
the Design
Developing
code
Testing the
software
Deploying
the software
Maintaining
the software
• Analysing operational feasibility Operational feasibility assessment involves studying the software
on operational and maintenance fronts. The operational feasibility of any software is done on the basis
of several factors, such as:
– Type of tools needed for operating the software
– Skill set required for operating the software
– Documentation and other support required for operating the software
• The code for different modules of the new software must be simple so that it can be easily
understood.
• The code must be logically correct so as to minimise logical errors in the program.
PRIMERA PARTE
EXPERIENCIAS Y DESILUSIONES
Páginas.
En la Engadina. 7
I.— De Santander a Bayona. 11
II.— Aviraneta y yo. 16
III.— Proyectos. 21
IV.— Algo de mi infancia. 26
V.— La tienda de antigüedades. 30
VI.— Nuevas instrucciones. 35
VII.— La vida en Bayona. 41
VIII.— Sensibilidad patriótica. 48
IX.— Noticias de Aviraneta. 54
X.— Madama de Laussat. 57
XI.— Madama d'Aubignac. 60
XII.— La duquesa y su abate. 67
XIII.— La arbitrariedad. 74
SEGUNDA PARTE
DANDYSMO
En la frontera del Tirol. 79
I.— Una imprudencia. 80
II.— Desafío. 84
III.— Stratford Grain. 89
IV.— Las cartas de lord Chesterfield. 91
V.— Variedades sobre el dandysmo. 97
VI.— En Cambo. 102
VII.— Cita a la luz de la luna. 106
VIII.— Los políticos. 108
IX.— Nostalgias. 115
X.— Física. 118
XI.— Muñagorri y su gente. 121
XII.— Nueva tertulia. 126
XIII.— Vuelta por España. 130
TERCERA PARTE
NUEVOS CONOCIMIENTOS
En Saint-Moritz. 141
I.— París y Madrid. 143
II.— Los agentes secretos. 149
III.— La Reina. 155
IV.— Aquel Madrid. 157
V.— Vinuesa y su familia. 159
VI.— Aventura en Tolosa de Francia. 162
CUARTA PARTE
LOS PEONES DEL JUEGO
En Basilea. 167
I.— Los rivales. 170
II.— El Murciélago. 174
III.— Las letras S, T, U, V. 177
IV.— Valdés de los gatos. 181
V.— Bertache. 186
VI.— La letra Z. 192
VII.— Las bacantes vascas de Añoa. 197
VIII.— Emboscada. 203
IX.— Aviraneta, de nuevo. 205
X.— Apuros de Vinuesa. 211
XI.— Un proyecto atrevido. 215
XII.— El plan escrito. 221
XIII.— De Biriatu a Erlaiz. 228
XIV.— Rompimiento. 233
XV.— En el faubourg Saint-Germain. 236
XVI.— Los chapuzones de Valdés. 241
XVII.— Encuentro. 246
XVIII.— Un hombre de mala suerte. 251
QUINTA PARTE
LA AVENTURA PELIGROSA
En la costa cantábrica. 167
I.— María Luisa de Taboada. 261
II.— Petulancia contra petulancia. 265
III.— En Estella. 271
IV.— Los conjurados. 275
V.— Las tropas de Maroto. 278
VI.— La encerrona. 282
VII.— Explicaciones y amenazas. 285
VIII.— La escapatoria. 290
IX.— Tribulaciones. 295
X.— De Estella a San Juan de Luz. 300
XI.— Otra vez Vinuesa. 304
XII.— Enfermedad. 310
XIII.— La vuelta de María. 313
XIV.— Comienza la nueva vida. 316
*** END OF THE PROJECT GUTENBERG EBOOK EL AMOR, EL
DANDYSMO Y LA INTRIGA ***
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
ebookgate.com