C++_Chapter1
C++_Chapter1
Software crisis was a term used in the early days of computing science for, the difficulty of
writing useful and efficient programs in the required time.
The software crisis was due to the rapid increase in computer power and the complexity of the
problems that could be tackled. With the increase in the complexity of the software, many software
problems arose because existing methods were neither sufficient nor up to mark.
The major motivating factor in the invention of OOP is to remove some of the flaws
encountered in the procedural approach. OOP treats data as a critical element in the program
development and does not allow it to flow freely around the system. OOP allows decomposition of
problem into a number of entities called objects and then build data and functions around these objects.
The data of an object can be accessed only by the function associated with the object. However,
functions of one object can access the functions of other objects. OOP employ bottom-up approach in
program design.
1
Compiled By:
Er. RANJAN RAJ ARYAL
Conventional programming using high level programming is commonly known as POP. In the procedure-
oriented approach, the problem is viewed as a sequence of things to be done such as reading,
calculating and printing. POP basically consists of writing a list of instructions for the computer to follow
and organizing these instructions into groups known as functions. These functions share global data and
can transfer data from one form to another. POP employs top-down approach in program design.
2
Compiled By:
Er. RANJAN RAJ ARYAL
3
Compiled By:
Er. RANJAN RAJ ARYAL
3.) Abstraction:
The process of representing essential features without internal details. The classes use
the concept of abstract attributes such as size, weight, cost and the function to operate these
attributes. The attributes are called data members and the function or methods as member
function. Since the classes use the data abstraction, they are known as abstract data-type.
4.) Encapsulation:
The hiding of data and function in a single unit is known as encapsulation. It is not
accessible to object, treats like a discrete black box testing.
4
Compiled By:
Er. RANJAN RAJ ARYAL
5.) Inheritance:
The mechanism of deriving from its base class. OR it is a process by which the objects of one
class acquire the properties of objects of another class. It supports the hierarchy of classification.
6.) Polymorphism:
It stands for ability to make more than one. In C++, the operators and a methods area different
depending on what they are operating. E.g. When an existing as operator ‘ + ’ or ‘ = ’ is given, the
capability to operate on a new data type, it is said to be operator overloading. Similarly, if a function call
‘sum’ can have two integers but if we define a function with same name, but taking its string as
argument, we can add them together. Then it is called the function overloading.
It is the way of communication in a similar way that we human do. It involves the name of
message, information to be send.
5
Compiled By:
Er. RANJAN RAJ ARYAL
In C++, a structure can have both variables and functions as members. It can also declare some
of its members as ‘private’ so that they cannot be accessed directly by the external functions.
In c++, the structure names are stand-alone and can be used like any type names. In other
words, the keyword ‘struct’ can be omitted in the declaration of structure variable. For example, we can
declare the student variable A as :
C++ incorporates all these extensions in another user-defined type known as class. There is very
little syntactical difference between structures and classes in C++ and therefore, they can be used
interchangeably with minor modifications.
Since class is a specially introduced data type in C++, most of the C++ programmers tend to use
the structures for hiding only data and classes to hold both the data and functions.
The only difference between a structure and a class in C++ is that, by default, the members of a
class are private, while by default, the members of a structures are public.
C
C++
Java etc.
6
Compiled By:
Er. RANJAN RAJ ARYAL
Selection Statements
Sequence Statements
Iteration Statements
The structured program consists of well-structured and separated modules. But the entry and exit in a
Structured program is a single-time event. It means that the program uses single-entry and single-exit
elements. Therefore, a structured program is well maintained, neat and clean program. This is the
reason why the Structured Programming Approach is well accepted in the programming world.