Programming in C 2nd Edition Safari pdf download
Programming in C 2nd Edition Safari pdf download
https://ebookgate.com/product/programming-in-c-2nd-edition-
safari/
https://ebookgate.com/product/programming-with-ansi-c-2nd-ed-edition-
trivedi/
ebookgate.com
https://ebookgate.com/product/c-for-business-programming-2nd-ed-
edition-molluzzo/
ebookgate.com
https://ebookgate.com/product/programming-principles-and-practices-
using-c-2nd-edition-bjarne-stroustrup/
ebookgate.com
https://ebookgate.com/product/programming-in-objective-c-4th-edition-
stephen-kochan/
ebookgate.com
Programming in ANSI C 6th Edition E. Balagurusamy
https://ebookgate.com/product/programming-in-ansi-c-6th-edition-e-
balagurusamy/
ebookgate.com
https://ebookgate.com/product/programming-in-scala-2nd-2nd-edition-
martin-odersky/
ebookgate.com
https://ebookgate.com/product/mobile-computing-1st-edition-edition-
safari/
ebookgate.com
https://ebookgate.com/product/separation-process-engineering-second-
edition-safari/
ebookgate.com
https://ebookgate.com/product/programming-in-java-2nd-edition-edition-
choudhary/
ebookgate.com
Programming in C++
Second Edition
No part of this eBook may be used or reproduced in any manner whatsoever without the publisher’s
prior written consent.
This eBook may or may not include all assets that were part of the print version. The publisher
reserves the right to remove any material in this eBook at any time.
ISBN 9788131791448
eISBN 9789332520288
Head Office: A-8(A), Sector 62, Knowledge Boulevard, 7th Floor, NOIDA 201 309, India
Registered Office: 11 Local Shopping Centre, Panchsheel Park, New Delhi 110 017, India
Brief Contents
PrEfAcE xv
About thE Author xvii
1. iNtroductioN to c++ 1
2. bASicS of c++ 21
4. c++ dEclArAtioNS 99
APPENdicES 869
iNdEx 879
Contents
Preface xv
About the Author xvii
1. iNtroductioN to c++ 1
1.1 Differences between C and C++ 1
1.2 Evolution of C++ 2
1.3 The ANSI Standard 2
1.4 The Object Oriented Technology 2
1.5 Disadvantage of Conventional Programming 4
1.6 Programming Paradigms 5
1.7 Preface to Object Oriented Programming 6
1.8 Key Concepts of Object Oriented Programming 7
1.9 Advantages of OOP 15
1.10 Object Oriented Languages 16
1.11 Usage of OOP 17
1.12 Usage of C++ 18
Summary 18
Exercises 19
2. bASicS of c++ 21
2.1 Introduction 21
2.2 Steps to Create and Execute a C++ Program 21
2.3 Flowchart for Creating a Source File, Compiling, Linking
and Executing in C++ 22
2.4 C++ Environments 23
2.5 Typical C++ Environment (Borland C++) 24
2.6 Structure of a C++ Program 27
2.7 Illustrative Simple Program in C++ without Class 28
2.8 Header Files and Libraries 29
Summary 30
Exercises 31
vi Contents
4. c++ dEclArAtioNS 99
4.1 Introduction 99
4.2 Tokens 100
4.3 Variable Declaration and Initialization 108
4.4 Data Types in C++ 115
4.5 Operators in C and C++ 129
4.6 Scope Access Operator 133
4.7 Namespace 133
4.8 Memory Management Operators 137
4.9 Comments 141
4.10 Comma Operator 142
4.11 Comma in Place of Curly Braces 143
4.12 More Programs 145
Summary 155
Exercises 156
Appendices 869
Index 879
Preface
Programming in C++ is meant for students pursuing various disciplines such as engineer-
ing, science, computer application, and diploma courses. Students who are learning object-
oriented programming (OOP) can also refer to this book. It covers the subject of C++ as per
the syllabi prescribed by various branches of Indian universities, state board of technical
educations, and the Department of Electronics and Accreditation of Computer Courses. Hence,
this book can be adopted in engineering, degree as well as other courses that deal with this sub-
ject. Written for beginners and for those who have some knowledge of C, the book will be espe-
cially useful for students who are learning object-oriented programming.
Designed to bridge the gap between theory and practice, the chapters have been presented
using a systematic and lucid approach. Each topic is explained in an easy-to-understand manner
with ample worked-out examples and programs. The book abounds with about 700 solved
programs and as many as 300 exercises for the student’s benefit. The programmer can run the
solved programs, see the output and appreciate the concepts of C++.
The programs have been fully tested and executed with Borland’s Turbo C++ compiler
version 3.00 and Visual C++ 6.0 compiler. The programs in Chapter 22 have been tested and
compiled with Java Compiler version 2.
This second edition has been thoroughly revised based on comments and responses received
for the previous edition. All programming examples have been tested, compiled and executed.
While utmost care has been taken at the time of writing this book, it is possible that errors and
omissions may have inadvertently crept in. Such incongruities, if any, may please be pointed
out. Suggestions and feedback are most welcome and may be directed to my e-mail address:
ankamthane@gmail.com.
AcKNowlEdgEmENtS
I express my gratitude to the Minister for Technical and Medical Education of Maharashtra State,
Honorable Shri D. P. Sawant, who complimented and felicitated me for writing technical books,
while he was invited to our institute recently in the month of May 2013. He also encouraged me
to write more books.
I am grateful to Prof. B. M. Naik, Former Principal of S.G.G.S. Institute of Engineering and
Technology, Nanded, who has always acted as a source of encouragement. His dynamism and
leadership led me to write this book and I will never forget his support and words of wisdom.
xvi Preface
Special thanks are due to the members of the board of governors of S.G.G.S. Institute of
Engineering and Technology, who motivated me to write this book. I thank eminent industrialist
Shri B. N. Kalyani, head of the Kalyani Group of Companies, for inspiring and complimenting
me for authoring technical books. I am also obliged to Dr L. M. Waghmare, Director of our
institute, for supporting and appreciating me while writing this book.
I am indebted to all my colleagues, friends and students who helped me at the time of
preparing the manuscript for this book. I acknowledge the support rendered by Dr S. V. Bonde,
Dr P. D. Jadhav, Dr P. Pramanik, Dr P. S. Charpe, Dr B. M. Dabde, Dr Y. V. Joshi, Dr U. V. Kulkarni,
Dr S. P. Kallurkar, Dr V. M. Nandedkar, Dr A. U. Digraskar, Dr R. S. Holambe, Dr B. M. Patre,
Prof. R. K. Chavan, Dr J. V. L. Venkatesh, Prof. P. S. Nalawade, S. S. Hatkar, Dr R. C. Thool,
Dr V. R. Thool, Dr D. D. Doye, Milind Bhalerao, Dr A. B. Gonde, Dr A. Chakraborthi,
Dr A. V. Nandedkar, Dr P. B. Londhe, Dr R. R. Manthalkar, Dr S. S. Gajre, Prof. N. G. Megde,
Dr A. S. Sontakke, Dr R. H. Chille, Dr L. M. Waikar and A. I. Tamboli of S.G.G.S. Institute of
Engineering and Technology.
I thank my friends Principal Prof. S. L. Kotgire and Prof. Balaji Bacchewar for their words
of encouragement. M. M. Jahagirdar, L. M. Buddhewar, K. M. Buddhewar, D. V. Deshpande,
S. R. Kokne, M. G. Damkondawar, Yeramwar, Pampatwar, D. R. Yerawar, S. R. Tumma, and
S. R. Mana also helped me to a great extent while writing this book.
I thank Pearson Education for publishing this book. In particular, I thank Ms V. Pavithra and
Ms Neha Goomer for their help in seeing this book through production. In addition, I also thank
Thomas Rajesh for his constant encouragement.
I appreciate the help and support provided by all the students, faculty, and non-teaching staff
of this institute as well as that of other friends who have directly or indirectly added value to this
book.
Thanks are also due to my wife, Surekha, who persistently supported me at all times. I am
indebted to my sons Amol and Amit, daughter Sangita, as also my daughter-in-law Swarupa, who
all played a key role in bringing this book to fruition. Swarupa was of immense help in drawing
the figures in several chapters. I thank all of them.
Ashok Namdev Kamthane obtained his M.E. (Electronics) degree from S.G.G.S. Institute of
Engineering and Technology, Nanded. A meritorious student throughout his career, he has bagged
a number of prizes including cash and medals for his distinct work in the academics. For his
M. E. (Electronics) dissertation, he worked at the Bhabha Atomic Research Center, Mumbai.
Associated with the teaching profession for the past 30 years, Kamthane was instrumental
in the development of hardware and software using the 8051 (8-bit microcontroller) on Acoustic
Transceiver System required in submarines. He has also worked at Melton as an executive.
Currently Associate Professor at the Department of Electronics and Telecommunication
Engineering in S.G.G.S Institute of Engineering and Technology, he has guided a number of
undergraduate and postgraduate students in their projects and published a number of technical
papers at both national and international conferences.
This page is intentionally left blank.
Introduction to C++ 1
cHaPter
(5) C uses printf() and scanf() functions to write and read the data respectively,
while C++ uses cout and cin objects for output and input operations, respectively.
Further, the cout uses << (insertion operator) and cin uses >> ( extraction operator).
(6) C uses stdio.h file for input and output functions, whereas C++ uses iostream.h
for these functions.
(7) Constructor and destructors are absent in C and the same are provided in C++.
(8) Inline functions are supported by C++, and the same are absent in C. Inline func-
tions can be used as micros. They are stated by a word ‘inline’.
C SIMULA 67
C++ is an object oriented programming language and also con-
sidered as an extension of C. Bjarne Stroustrup at AT&T Bell
Laboratories in Murray Hill, New Jersey (USA) developed this
language in the early 1980s. Stroustrup, a master of Simula67
and C, wanted to combine the features of both the languages
and he developed a powerful language that supports object-ori-
ALGOL 68 C WITH CLASSES
ented programming with features of C. The outcome was C++
as per Fig. 1.1. Various features were derived from Simula67
and algol68. Stroustrup called the new language ‘C with
classes’. However, in 1983, the name was changed to C++.
The thought of C++ came from the C increment operator
C++ ++. Rick Mascitti coined the term C++ in 1983. Therefore,
C++ is an extension of C. C++ is a superset of C. All the
concepts of C are applicable to C++ also.
fig. 1.1 Evolution of C++
For developing complicated applications, object orient-
ed language such as C++ is the most convenient and easy.
Hence, a programmer must be aware of its features.
the coordination of management. The various departments of any organization can be thought of
as objects working for certain goals and objectives.
Usually an institute has faculty of different departments. The Director/Principal is a must for
the overall management of the institute. The Academic Dean is responsible for the academics of
the institute. The Dean for Planning should have the future plans of the institute and he/she must
see how the infrastructure is utilized effectively. The Dean R&D should see research activities
run in the institute forever.
Besides teaching staff there must be laboratory staff for assistance in conducting practical ses-
sions, and a site development section for beautification of the campus. The accounts department
is also required for handling monetary transactions and salaries of the employees. The Sports sec-
tion is entrusted the responsibility of sports activities. The Registrar for Administration and staff
for dealing with administrative matters of the institute are also required. Each department has an
in-charge who carries clear-cut given responsibilities. Every department has its own work as stat-
ed above. When an institute’s work is distributed into departments as shown in Fig. 1.1, it is com-
fortable to accomplish goals and objectives. The activities are carried on smoothly. The burden of
one particular department has to be shared among different departments with personnel. The staff
in the department is controlled properly and act according to the instructions laid down by the
management. The faculty performs activities related to teaching. If the higher authority needs to
know the details regarding the theory, practical, seminar and project loads of individuals of the de-
partment, then a person from the department furnishes the same to the higher authority. This way
some responsible person from the department accesses the data and provides the higher authority
with the requisite information. It is also good to think that no unconnected person from another
department reads the data or attempts to make any alteration that might corrupt the data.
As shown in Fig. 1.2, an institute is divided into different departments such as library,
classroom, computer laboratory, etc. Each department performs its own activities in association
with the other departments. Each department may be considered as a module and it contains
class and object in C++ language. This theory of class and object can be extended to every
walk of life and can be implemented with software. In general, objects are in terms of entities.
Computer Lab
Class Room
Library
Main Function
Function-D Function-E
Each function can call another function, as shown in Fig. 1.3. Each function has its own task. If
the program is too large the function also creates problems. In many programs, important data
variables are declared as global. In case of programs containing several functions, every function
can access the global data as per the simulation in Fig. 1.4. In huge programs it is difficult to know
what data is used by which function. Due to this the program may contain several logical errors.
Global Variables Global Variables Global variables
The following are the drawbacks observed in monolithic, procedure, and structured program-
ming languages:
Programming Paradigms 5
(1) Huge programs are divided into smaller programs known as functions. These functions
can call one another. Hence security is not provided.
(2) No importance is given to security of data and importance is laid on doing things.
(3) Data passes globally from function to function.
(4) Most function accesses global data.
(G) The control of program can be transferred using unsafe goto statement.
(H) This type of programming language uses different control structures that are as
follows.
• Decision/selection control statements
• Iteration control statements
• Jump control statements
(I) Data are global and all the sub-programs share the same data, i.e. data are globally
accessible to all functions. Thus, any function operates on the global data and this
directs to loosing some vital information. We can conclude here that a module
represents a function.
(J) Procedural structured/programming languages permit data transfer through mes-
sages by means of functions.
(K) Least importance is given to the data in procedural/structured programming languages.
(L) These languages are used for developing medium-sized software applications.
(M) Complier and interpreter construction are easy and simple with this type of pro-
gramming language. Furthermore, these compilers and interpreters need low
memory to run on the computers.
(N) It is difficult to implement simultaneous processes/parallelization.
GLOBAL DATA
Modules
Object oriented programming language is a feature that allows a mode of modularizing programs by
forming ory area for data as well as functions that is used as object for making copies of modules as per
requirement.
There are several fundamental concepts in object oriented programming. They are shown in Fig. 1.8
and are discussed as follows.
Encapsulation
Data abstraction
Inheritance
C++
Polymorphism
Delegation
Genericity
(1) objects
Objects are primary run-time entities in object-oriented programming. They may stand for a
thing that makes sense in a specific application. Some examples are a spot, a person, any data
item related to the program including user-defined data types. Programming issues are analyzed
in terms of object and the type of transmission between them. Program objects must be selected
like the items equivalent to actual world objects. Objects occupy space in memory. Every object
has its own properties or features that illustrate what the object can do. An object is a specimen
of a class. It can be singly recognized by its name. It declares the state that is shown by the data
values of its characteristic at a specific time. The state of the object varies according to the pro-
cedure used with it. It is called as the action of the object. The action of the object depends upon
the member function defined within its class.
Fig. 1.9 (a) shows some of the objects that we use in our daily life.
Object: City
Data:
Name_of_city
Population
Telephone Book Computer Watch Lock
Area
Functions:
Average age
Literacy_rate
Display
Home Trophy Television Bicycle Ambulance
fig. 1.9 (a) Commonly available objects fig. 1.9 (b) Representation of
an object
Objects communicate with each other by sending messages. An object can be represented by
Fig 1.9 (b).
The name of the above object is city. Its data members are name_of_city, population, and
area. The various functions associated with the city are average age, literacy_ rate, and display.
(2) classes
A class is grouping of objects that have the identical properties, common behavior, and shared relation-
ship. A class binds the data and its related functions together.
A class is the accomplishment of abstract data type. It defines the nature and methods that act
on the data structure and abstract data type, respectively. Specimens are also called as objects. In
other words, a class is a grouping of objects that have identical properties, common behavior, and
shared relationship. For example, Tata’s Swift, Maruti’s Alto etc. are the members of a class car.
The entire group of data and code of an object can be built as a user-defined data type us-
ing class. Objects are nothing but variables of type class. Once a class has been declared, the
programmer can create a number of objects associated with that class. The syntax used to create
Key Concepts of Object Oriented Programming 9
an object is similar to the syntax used to create an integer variable in C. A class is a model and
not a true specimen of the object. Every object has its own value for each of its member variables.
However, it shares the property names or operations with other instances of the class. Thus,
classes define the characteristic and action of objects.
Class: car
Properties: company, model, color, and capacity
Actions: Speed(), average() and break().
Class: computer
Properties: Brand, resolution, price and size
Action: processing(), display() and printing()
Class: floppy
Properties: company, size and capacity
Action: storing(), protection(), and retrieving()
In Fig. 1.10 commonly useful classes are described with their properties and action they per-
form. For example, a car has properties like company, model and color with which a car can be
identified among a number of cars of other properties, and the actions like speed() and aver-
age() describes its working.
Class home
{
Telephone
Book
Computer {
Watch
}
Lock
Class vehicle
{}
Class entertainment
{}
}
fig. 1.11 Classes and their members
Figure 1.11 describes the classes and related data that come under the different classes.
10 Introduction to C++
(3) method
An operation required for an object or entity when coded in a class is called a method.
An operation required for an object or entity when coded in a class is called a method. The opera-
tions that are required for an object are to be defined in the class. All objects in a class carry out
certain common actions or operations. Each action needs an object that becomes a function in the
class that defines it and is referred to as a method.
In Fig. 1.12 the class and its associated data members and functions are shown in different
styles. It is a frequent style of writing a class in the program.
The class A contains private data members and public methods or member functions.
Usually, the data members are declared private and methods or member functions are declared
as public and they are available outside the class. The data member of any class uses its member
functions or methods to perform operations.
class A
{
private
data member1;
data member2; Members
data member(n);
public
method1() { } Methods or
method2() { } Member functions
method_n() { }
};
(a)
Class A Class A
Method 1
Method 2
Method 3 Method n
:
:
Method n
(b)
Abstraction refers to the procedure of representing essential features without including the background
details.
Abstraction refers to the procedure of representing essential features without including the back-
ground details. Classes use the theory of abstraction and are defined as a list of abstract properties
such as size, cost, height, and few functions to operate on these properties. Data abstraction is
the procedure of identifying properties and method related to a specific entity as applicable to
the application.
A powerful method to achieve abstraction is through the manipulation of hierarchical clas-
sifications. It permits us the breaking of semantics of multiple systems into layers by separating
them into multiple controllable parts. For example, a computer as shown in Fig. 1.13 is made of
various parts such as CPU, keyboard, and so on. We think it as a single unit, but the single unit
has several sub-units. They together do the single task. By assembling sub-parts we can build a
single system.
Hierarchical abstraction of complicated systems can also be used in computer software. The
data from conventional procedure oriented programs can be converted by abstraction mechanism
into its partial objects. A series of operation steps may develop a set of messages between these
objects. Each object shows its own attributes.
Data abstraction is used to define a data type available in the programming language, called
as abstract data type (ADT). It consists of a set of values and a set of operations.
(a) Computer as single unit (b) Different components of computer
(5) encapsulation
The packing of data and functions into a single component is known as encapsulation.
C++ supports the features of encapsulation using classes. The packing of data and functions into
a single component is known as encapsulation. The data is not reachable by the outside functions.
Only those functions that are able to access the data are defined within the class. These functions
prepare the interface between the object’s data and the program. With encapsulation we can
accomplish data hiding. Data hiding is an important feature using which an object can be used
without the user knowing how it works internally.
In C++ the fundamental of encapsulation is class. A class defines the structure of data and
member functions. It is common to all its objects. Class is a logical structure whereas object is
12 Introduction to C++
a physical actuality. The goal of the class is to encapsulate complication. The class also has a
mechanism for hiding the data. Each member in the class may be private or public. Any non-
member function cannot access the data of the class. The public section of the class must be
mindfully coded not to expose the inner details of the class. Figure 1.14 explains sections of
encapsulation.
class C
Φ Φ Φ Φ Φ
κ Private Data
υυυ κκκκκ
Members
υ Private methods Φ υυυ κκκκκ Φ
υυυ κκκκκ
Φ Public methods Φ υυυ κκκκκ Φ
ι Public data Φ Φ Φ Φ Φ
members ιιιι
(6) inheritance
Inheritance is the method by which objects of one class get the properties of objects of another class.
(7) Polymorphism
Polymorphism allows the same function to act in a different way in different classes.
Key Concepts of Object Oriented Programming 13
Polymorphism makes it possible for the same functions to act differently on different classes as
shown in Fig. 1.16. It is an important feature of OOP concept. It holds an ability to take more than
one form. Polymorphism accomplishes an important part in allowing objects of different classes
to share the same external interface. It is possible to code a non-specific (generi(c) interface to a
set of associated actions.
Line
Display()
Binding means connecting one program to another program that is to be executed in reply to the call.
Binding means connecting one program to another program that is to be executed in reply to
the call. Dynamic binding is also known as late binding. The code present in the specified
program is unknown till it is executed. It is analogous polymorphism.
In Fig. 1.16 polymorphism allows the single object to invoke similar function from different
classes. The program action is different in all the classes. At execution time, the code analogous
to the object under the present reference will be executed. The reader is advised to refer polymor-
phism chapter for more details.
the same class. Thus a message is a solicitation to an object to call one of its member functions.
A message contains name of the member function and parameters of the function. Execution of
member function is just a response generated due to receipt of a message. It is possible when the
function and the object are of the same class.
Obj.Display (argument)
Object Data
Communication operator
Message
(10) reusability
Object oriented technology allows reusability of the classes by extending them to other classes using
inheritance.
Object oriented technology allows reusability of the classes by extending them to other class-
es using inheritance. Once a class is defined, the other programmer can also use it in their
programs. The programmer can also add new feature to the derived classes. The verified and
checked qualities of base classes need not to be redefined. Thus, the reusability saves the time.
In Fig. 1.18, class A is reused and class B is created. Again class B is reused and class
C is created.
CLASS A
CLASS B
CLASS C
(11) Delegation
In OOP, two classes can be joined in two ways: (a) Inheritance, (b) Delegation. Both these ways
provide reusability of the class.
In Inheritance one class can be derived from the other class. The relationship between these
two classes is called as kind of relationship. For example if class Y is derived from class X, then
class Y is known as kind of X. Figure 1.19 (a) explains this point.
Advantages of OOP 15
CLASS A CLASS B
{ }; { };
CLASS C
{
A a; // Object of class A as data member
B b; // Object of class B as data member
Class Y//Derived class }
(a) (b)
fig. 1.19 Relationships between two classes: (a) Kind of relationship (Inheritance)
(b) has a relationship (Delegation)
The second type of relationship is has a relationship. When object of one class is used as
data member in the other class, such composition of objects is known as delegation. As shown in
Fig. 1.19 (b) class C has two data members. These two data members are objects of class A
and B, such relationship between the classes in known as has a relationship.
(12) genericity
The software components of a program have more than one version depending on the data
types of arguments. This feature allows declaration of variables without specifying exact
data type. The compiler identifies the data type at run time. The programmer can create a
function that can be used for any type of data. The template feature in C++ allows generic
programming.
Multiple inheritance No
Polymorphism
Binding (Early and late) Both Both Late binding Early binding Both Early binding
Genericity
Class libraries Few
Garbage collection
Persistence Promised Less Same as 3GL
The following are the object-oriented languages, which are widely accepted by the pro-
grammer.
• C++
• Smalltalk
• Charm ++
• Java
smalltalK
Smalltalk is a pure object oriented language. C++ makes few compromises to ensure quick per-
formance and small code size. Smalltalk uses run-time binding. Smalltalk programs are con-
sidered to be faster than the C++. Smalltalk needs longer time to learn than C++. Smalltalk
programs are written using Smalltalk browser. Smalltalk uses dynamic objects and memory is
allocated from free store. It also provides automatic garbage collection and memory is released
when object is no longer in use.
cHarm++
Charm ++ is also an object oriented programming language. It is a portable. The language pro-
vides features such as inheritance, strict type checking, overloading, and reusability. It is de-
signed in order to work efficiently with different parallel systems together with shared memory
systems, and networking.
java
Java was developed by Patrick Naughton, James Gosling, Chris Warth, Mike Sheridan and Ed Frank
at Sun Microsystems. Java is an object oriented programming language and supports maximum
OOP characteristics exist. Its statement structure is like C and C++, but it easier than C++. Java
excludes few confusing and unsafe features of C and C++ like pointers.
Java allows client/server programming. Java is used for Internet programming. The Java
programs are downloaded by the client machines and executed on different types of hardware.
This portability is achieved by translation of Java program to machine code using compiler and
interpreter.
The Java compiler converts the source program to JVM (Java virtual machine). The JVM is
a dummy CPU. The compiler Java program is called as byte code. The Java interpreter translates
byte code into the object code. Compiler and interpreter do the conversion of Java program to
object code.
eral windowing software based on OOP technology. Following are the areas for which OOP is
considered.
(1) Simulation
(2) Object oriented DBMS
(3) Office automation software
(4) Artificial Intelligence and expert systems
(5) CAD/CAM software
(6) Network programming & Internet applications
(7) System software
summary
(1) C++ is an object oriented programming (7) Larger programs are developed in structured
language invented by Bjarne Stroupstrup at programming such as Pascal and C. Pro-
AT&T Bell Laboratories. grams are divided in multiple sub modules
(2) The recognized council working under the and procedures.
procedure of the American National Standard (8) OOP acts with data as a critical component in
Institute (ANSI) has made an international the program development and does not let the
standard for C++. data to flow freely around the systems.
(3) The disadvantage in conventional program- (9) Object: Objects are primary run-time enti-
ming language is that the program written in ties in an object-oriented programming. They
these languages consists of a sequence of in- may stand for a thing that makes sense in a
structions that tells the compiler or interpreter specific application.
to perform a given task. When program code (10) Class: A class is grouping of objects that have
is large then it becomes inconvenient to man- the identical properties, common behavior,
age. and shared relationship. The entire group of
(4) The prime factor in the design of object ori- data and code of an object cab be built as a
ented programming approach is that to get user-defined data type using class.
back some of the faults found in the proce- (11) Method: An operation required of an object
dure oriented languages. or entity when coded in a class is called a
(5) In monolithic programming languages such method.
as basic and assembly language, the data (12) Data Abstraction: Abstraction directs to the
variables declared are global and the state- procedure of representing essential features
ments are written in sequence. without including the background details.
(6) In the procedural programming languages (13) Encapsulation: C++ supports the features of
such as FORTRAN and COBOL, programs encapsulation using classes. The packing of
are divided into number of segments called data and functions into a single component is
as subprograms. Thus it focuses on functions known as encapsulations.
apart from data. (14) Inheritance: Inheritance is the method by
Exercises 19
which objects of one class get the proper- (17) The languages C++, Smalltalk, Eiffel and
ties of objects of another class. In object ori- Java are widely used OOP languages.
ented programming inheritance provides the (18) Object oriented technology is changing the
thought of reusability. style of software engineers to think, analyze,
(15) Polymorphism: Polymorphism makes pos- plan and implements the software. The soft-
sible the same functions to act differently on ware developed using OOP technology is
different classes. It is an important feature of more efficient and easy to update.
OOP concept. (19) C++ is a flexible language. Lengthy programs
(16) Object oriented technology allows reusabil- can be easily controlled by the use of C++.
ity of the classes by extending them to other
classes using inheritance.
eXercises
• 2.1 Introduction
CHAPTER OuTlinE
2.1 inTRODuCTiOn
A programmer must know rules and steps to develop programs with C++. Programs given in this
book are developed using Borland’s C++ IDE compiler version 3.0. Let us try to follow the steps
for creating, compiling and running programs under Borland’s C++ IDE compiler.
Yes Syntax
Error / s?
No
Link with library
Figure 2.1 Flowchart for creating a C++ program, compiling and linking
The process of compiling, linking and running a program in C++ is elaborated in the following
section.
Alternatively, create a source program using integrated Turbo C++ editor. Go to the File menu
and select New. The file name NONAME00.CPP appears on the screen at the centre of the window.
Check whether your source program is typed correctly. If mistakes are found, correct them.
Now press F 2 to save your program or use Save option with .cpp extension. You can change
the file name and save it using the Save option in File menu. In the following window the file
is saved with ABC.CPP.
TOY DEALERS.
Brickley Anne, High st
Doharty Martin, Listley st
Evason Edward, St. Mary st
VETERINARY SURGEONS.
Atcherley James Rennell, High st
Bradshaw Henry Ainsworth, Saint Mary street
WHEELWRIGHTS.
Lloyd John, Salop st
Pearce William, West Castle st
Perry John, Bernard’s hill
Preece Benjamin, East Castle st
Price Benjamin, Whitburn st
MISCELLANEOUS.
Bagnall Mary, clothes dealer, Listley st
Baker James, cutler, Listley st
Baker Joseph, rope maker, Whitburn st
Batte William D. coroner, East Castle st
Bennett John L. tax collectr, West Castle st
Cureton Benjamin, registrar of births and deaths, High street
Doughty Richard, wharfinger, Underhill st
Fowles Mary Ann, dyer, Whitburn st
Goalby John, haberdasher, High st
Gwynn James, basket maker, Salop st
Hughes Ann, pawnbroker, St. Leonard’s Church yard
Jefferies & Co. tallow chandlers, High st
Jones Dodo Davis, parish clerk, High st
Nock & Wilson, corn factors, High st
Rutter Benjamin, nail maker, Bernard’s hill
Sewell John, professor of music, Church st
Sing & Macmichael, tanners, Mill street, Low Town
Williams Charles, land steward, Morville Hall
Williams Fanny Evans, Berlin wool repository, High st
Williams Thos. gun manufacturer, High st
PLACES OF WORSHIP,
AND THEIR MINISTERS.
St. Leonard’s Church—Rev. George Bellett, A.M. incumbent; Rev. Charles Isaac
Powie, curate
St. Mary’s Church—Rev. William Knox Marshall, A.M. incumbent; Rev. Henry
Bolland, curate
St. Mary Macdalene’s Church, Quatford—Rev. George Leigh Wasey, incumbent
St. Michael’s Church, Morville—Rev. George Leigh Wasey, incumbent; Rev. John
Clarke, curate
Stockton Church, Stockton—Rev. Charles Whitmore, incumbent; Rev. Stuteville
Isaacson, curate
Baptist Chapel, West Castle street—Rev. Alfred Tilley
Independent Chapel, Stoneway steps—Rev. David D. Evans
Methodist (Wesleyan) Chapel, Low Churchway
Roman Catholic Chapel, High st—Rev. Francis O’Neill, priest
Irvingite Chapel, East Castle st—Rev. John H. Cooper
COUNTY COURT
HELD IN THE TOWN HALL.
Judge—Uvedale Corbett, Esq.
Clerk—John Jacob Smith
RAILWAY.
The nearest Station is at Shiffnall, 10 miles N.E. from Bridgnorth, on the Great
Western line. For conveyance thereto see above.
VANS.
FOR PASSENGERS AND GOODS.
To KIDDERMINSTER, — Sefton, from the Star Inn, Low Town, every Mon.
Wed. and Saturday evening at five.
To MUNSLOW, a Van, from the Raven Inn, every Saturday aftern. at three.
To WENLOCK, — Jones, from the Crow Keys Inn, every Sat. afternoon at four.
CARRIERS.
To CHURCH STRETTON, — Jones, from the Bell, Sat. afternoon at three.
To SHIFFNALL STATION, a Wagon, from the Great Western Railway Co.’s
Office, bottom of High st, daily.
To WENLOCK, — Clayton, from the Bell, Saturday afternoon at three.
To WOLVERHAMPTON, Richard Beeston’s Wagon, from the Crown and Royal
Oak, daily.
CONVEYANCE BY WATER.
To BEWDLEY, COALPORT, COALBROOKDALE, STOURPORT, WORCESTER,
GLOUCESTER, and BRISTOL, Benjn. Devy, from — Jones’ wharf, three times a
week.
To COALPORT, IRONBRIDGE, SHREWSBURY, &c. from the River side, twice a
week—Richard Doughty, wharfinger.
BROSELEY AND MADELEY,
WITH COALBROOKDALE, COALPORT, IRONBRIDGE, BENTHALL,
ACCOUNTANTS.
Harvey John, Broseley
Leadbetter Enoch, Broseley
Munday Thomas, Madeley
Nevitt Enoch, Broseley
Poole James G. Dawley bank
Weare William, Ironbridge
AGENTS.
(See also Fire, &c. Office Agents.)
Anstice William Reynolds (to Joseph Reynolds, Esq.), Ironbridge
Evans Edwin R. (estate), Broseley
Jones George (mining agent, and surveyor to James Foster, Esq.), Madeley
Court
Leadbetter Enoch (house), Broseley
Milner Betsy (to Crowley & Co., carriers), Ironbridge
Pearce Francis (iron & coal), Madeley Court
Pugh Thomas (general), Madeley
Whiteley James (to the Coalport Porcelain Company), Coalport
ATTORNEYS.
Anstice Wm. Reynolds, Ironbridge
Potts & Gordon, Broseley
AUCTIONEERS.
Hartshorne George, Broseley
Leadbetter Enoch, Broseley
Weare William, Ironbridge
BANKERS.
Pritchards’, Boycott & Nicholas, Broseley—(draw on Barnett’s, Hoares’ & Co.
London)
Shropshire Banking Company, (Coalbrookdale branch), Ironbridge—(draw on the
Union Bank of London)—Henry C. T. Dickenson, manager
Savings’ Banks, Ironbridge and Dawley—(open every alternate Monday)—Wm.
Smith, actuary
BARGE OWNERS.
Beard Thomas, Werps
Burton John & Edward, Ironbridge
Davies James, Coalford
Davies Thomas Coalford
Dodd Andrew, Salthouse
Doughty George, Salthouse
Doughty Robert, Salthouse
Doughty Theophilus Coalford
Exley William, Jackfield
Lloyd Henry, Jackfield
Lloyd Thomas, Salthouse
Oakes Francis, Salthouse
Owen Benjamin, Ironbridge
Owen Edwd. bottom of Coalbrookdle
Parker Benjamin, Coalford
Reynolds John, Salthouse
Roden Samuel, Benthall
Transom James, Salthouse
Yates Francis & John, Ironbridge
BASKET MAKERS.
Gwynn Enoch, Broseley
Roderick Joseph, Broseley
BLACKSMITHS.
Brown Edward, Jackfield
Browne William, Jackfield
Cock James, Little Dawley
Davies Richard, Ironbridge
Dorsett Thomas, Madeley
Edwards John, Ironbridge
Edwards Joseph, Lloyd head
Garbett Joseph, Broseley
Gittins John, the Court
Instone Joshua, Benthall
Merrington Chas. Finger lane, Dawley
Morris Richard, Madeley
Parish Charles, Dawley
Poole James, Dawley Green lane
Robinson Thomas, Broseley
Rushton Samuel (& manufacturers of hurdles, pallisades, gates, fencing, &c.
and all descriptions of wrought iron work), Madeley
Sheward John, Little Dawley
Spragg & Hinsley, Madeley wood
Walton Richard, Ironbridge
BOAT BUILDERS.
Chune Geo. & Jos., Coalbrookdale
Gother Edward (barge), Benthall
Griffiths Thomas (canal), Coalport
BRICKLAYERS.
Barclay John, Ironbridge
Farmer John, Ironbridge
Nevett Thomas & Co. Ironbridge
Nickless James, Madeley Wood
Squires Richard, Broseley
BUILDERS.
(See also under the head Joiners.)
Barclay John, Ironbridge
Exley William, Jackfield
Nevett Thomas & Co. Ironbridge
Smith Thomas, Madeley
BUTCHERS.
Bailey Henry, Dawley
Bailey John, Dawley
Barnett Thomas, Ironbridge
Bills Jeremiah, Broseley
Brown William, Dawley
Cartwright Charles, Broseley and Ironbridge
Cartwright George, Madeley
Cartwright George, Broseley
Cartwright James, Broseley
Cartwright John, Broseley
Cooke Joseph, Broseley
Corfield Thomas, Broseley
Crump William, Broseley
Davis Samuel, Broseley
Delves Joseph, Ironbridge
Dyas William, Ironbridge & Madeley
Everall Robert, Broseley
Guy Thomas (pork), Dawley
Harper John, Coalport
Harvey John, Broseley
Lewis George, Dawley
Page John, Ironbridge
Page William, Madeley
Poole Charles, Ironbridge
Taylor William, Broseley & Ironbrdge
Wilcox Bernard, Ironbridge
Wilcox John, Madeley green
Wilcox William, Madeley Wood
Wotton Herbert, Broseley
CABINET MAKERS.
Marked thus * are also Upholsterers.
* Barker John, Dawley
Currier Joseph, Madeley
* Davies George, Ironbridge
Hartshorne George, Broseley
* Jones William, Ironbridge
Lloyd Hiram, Broseley
Turley Thomas, Broseley
Watkis Miles, Dawley Green lane
* Williams James, Madeley
CHAIN MANUFACTURERS.
Edge & Son (flat & improved round chains and cables for mining purposes,
&c.) Coalport
Harris James, Finger lane, Dawley
Poole James, Dawley Green lane
CHINA MANUFACTURERS.
Rose John & Co., Coalport—warehouses, Newcastle street, Strand, London;
King street, Manchester, and Wyle cop, Shrewsbury
COAL MASTERS.
Coalbrookdale Company, Coalbrookdale and Horsehay
Evans George, Broseley
Foster Wm. Orme, Madeley Court & Calcut—Francis Pearce, agent
Holmes William, Broseley
Langford George & Thomas, Broseley
Langleyfield Company, Langleyfield—Arthur Hinde, manager
Madeley Wood Company, Madeley Wood
Onions John, Broseley
Raspass, Patten & Plimbley, Clonebury Colliery, Broseley
COOPERS.
Cox William, Ironbridge
Jones George, Broseley
Roberts Richard, Ironbridge
Williams William, Ironbridge
CURRIERS.
Cherrington Thomas, Ironbridge
Pierce Richard R. Dawley
Stirrop Robert, Ironbridge
Summers Richard, Dawley
DRUGGISTS.
Deakin Thomas, Dawley
Oakley Jesse, Broseley
Roberts & Deakin, Little Dawley
Smith Charles William, Ironbridge
HAIR DRESSERS.
Baugh George, Ironbridge
Davenhall John, Dawley
Ferriday John, Dawley
Glover Edward, Broseley
Heighway John, Madeley
Pinkstone John, Madeley Green
Poole Richard, Dawley
Reynolds Richard, Ironbridge
Shaw Thomas, Broseley
HOSIERS.
Burnet Mary Ann & Hy., Broseley
Comley John, Dawley
Fox John, Coalbrookdale
Garbett John, Dawley
Greenhalgh & Ferrington, Ironbrdg
Lloyd Mary Ann, Broseley
Rushton Jane, Madeley
Smith Moses, Broseley
Thomas & Son, Broseley
IRON MASTERS.
Coalbrookdale Company, Coalbrookdale and Horsehay—warehouses, Severn,
Coalbrookdale, and Castle street, Bristol
Foster William Orme, Madeley Court—Francis Pearce, agent
Langleyfield Company, Langleyfield—Arthur Hinde, manager
Madeley Wood Company, Madeley Wood
IRONMONGERS.
Bailey George, Madeley & Dawley
Cowley James, Broseley
Davies Richard, Ironbridge
Fenton John, Ironbridge and Broseley
Haywood John (and wire worker), Ironbridge
Peters Moses, Broseley
Price Charles L. Coalbrookdale
Smith Charles William, Ironbridge
JOINERS.
Marked that * are also Builders.
(See also Builders.)
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!
ebookgate.com