OOP in c++ notes from chapter 1 to 4, Study notes of Object Oriented Programming

These notes cover Object-Oriented Programming in C++ (Units 1–5) for TU IOST BIT 2nd semester, Nepal. Unit-1: Introduction – OOP concepts, merits/demerits, OOP vs POP. Unit-2: Basics of C++ – program structure, data types, operators, cin/cout, control statements. Unit-3: Classes & Objects – class definition, access specifiers, constructors, destructors, arrays of objects, friend functions. Unit-4: Operator Overloading – unary/binary operators, rules, member vs friend functions with examples. Unit-5: Inheritance – base/derived classes, types (single, multiple, multilevel, hierarchical, hybrid), visibility modes, ambiguity resolution. Notes are well-structured, simple, and exam-focused with diagrams, definitions, and coding examples. File is PDF, concise but complete, based on TU syllabus and lectures. Ideal for quick revision, assignments, and exam prep for BIT students in Nepal.

Typology: Study notes

2024/2025

Available from 08/27/2025

aarogya-raj-uprety
aarogya-raj-uprety 🇳🇵

3 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Subject: Object Oriented Programming
Unit 1: Introduction to Object Oriented Programming
Software Evolution
Ernest Tello, A well known writer in the field of artificial intelligence, compared the
evolution of software technology to the growth of the tree. Like a tree, the software evolution has
had distinct phases “layers” of growth. These layers were building up one by one over the last
five decades as shown in fig. 1.1, with each layer representing an improvement over the previous
one. However, the analogy fails if we consider the life of these layers. In software system each of
the layers continues to be functional, whereas in the case of trees, only the uppermost layer is
functional.
Alan Kay, one of the promoters of the object-oriented paradigm and the principal designer
of Smalltalk, has said: “As complexity increases, architecture dominates the basic materials”. To
build today’s complex software it is just not enough to put together a sequence of programming
statements and sets of procedures and modules; we need to incorporate sound construction
techniques and program structures that are easy to comprehend implement and modify.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download OOP in c++ notes from chapter 1 to 4 and more Study notes Object Oriented Programming in PDF only on Docsity!

Subject: Object Oriented Programming

Unit 1: Introduction to Object Oriented Programming

Software Evolution Ernest Tello, A well known writer in the field of artificial intelligence, compared the evolution of software technology to the growth of the tree. Like a tree, the software evolution has had distinct phases “layers” of growth. These layers were building up one by one over the last five decades as shown in fig. 1.1, with each layer representing an improvement over the previous one. However, the analogy fails if we consider the life of these layers. In software system each of the layers continues to be functional, whereas in the case of trees, only the uppermost layer is functional. Alan Kay, one of the promoters of the object-oriented paradigm and the principal designer of Smalltalk, has said: “As complexity increases, architecture dominates the basic materials”. To build today’s complex software it is just not enough to put together a sequence of programming statements and sets of procedures and modules; we need to incorporate sound construction techniques and program structures that are easy to comprehend implement and modify.

With the advent of languages such as c, structured programming became very popular and was the main technique of the 1980’s. Structured programming was a powerful tool that enabled programmers to write moderately complex programs fairly easily. However, as the programs grew larger, even the structured approach failed to show the desired result in terms of bug-free, easy-to- maintain, and reusable programs. Object Oriented Programming (OOP) is an approach to program organization and development that attempts to eliminate some of the pitfalls of conventional programming methods by incorporating the best of structured programming features with several powerful new concepts. It is a new way of organizing and developing programs and has nothing to do with any particular language. However, not all languages are suitable to implement the OOP concepts easily. Procedure Oriented Programming In the procedure oriented approach, the problem is viewed as the sequence of things to be done such as reading, calculating and printing such as COBOL, FORTRAN and C. The primary focus is on functions. A typical structure for procedural programming is shown in fig.1.2. The technique of hierarchical decomposition has been used to specify the tasks to be completed for solving a problem.

follows a simple hierarchical model that employs three types of control flows: sequential, selection, and iteration. Problems with Structured Programming: As programs grow larger, structured programming approach begins to show signs of strain. No matter how well the structured programming approach is implemented, the project becomes too complex, the schedule slips, more programmers are needed, and costs skyrocket. Object Oriented Programming The major motivating factor in the invention of object-oriented approach 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. It ties data more closely to the function that operate on it, and protects it from accidental modification from outside function. OOP allows decomposition of a problem into a number of entities called objects and then builds data and function around these objects. The organization of data and function in object-oriented programs is shown in fig.1.3. The data of an object can be accessed only by the function associated with that object. However, function of one object can access the function of other objects.

Some of the features of object oriented programming are:

  • Emphasis is on data rather than procedure.
  • Programs are divided into what are known as objects.
  • Data structures are designed such that they characterize the objects.
  • Functions that operate on the data of an object are ties together in the data structure.
  • Data is hidden and cannot be accessed by external function.
  • Objects may communicate with each other through function.
  • New data and functions can be easily added whenever necessary.
  • Follows bottom up approach in program design. Basic Concepts of Object Oriented Programming It is necessary to understand some of the concepts used extensively in object-oriented programming. These include:
  • Objects
  • Classes
  • Data abstraction and encapsulation
  • Inheritance
  • Polymorphism
  • Dynamic binding
  • Message passing Objects Objects are the basic run time entities in an object-oriented system. They may represent a person, a place, a bank account, a table of data or any item that the program has to handle. They may also represent user-defined data such as vectors, time and lists. Programming problem is analyzed in term of objects and the nature of communication between them. Program objects

built-in types of a programming language. The syntax used to create an object is not different then the syntax used to create an integer object in C. If fruit has been defines as a class, then the statement Fruit Mango; Will create an object mango belonging to the class fruit. Data Abstraction and Encapsulation The wrapping up of data and function into a single unit (called class) is known as encapsulation. Data and encapsulation is the most striking feature of a class. The data is not accessible to the outside world, and only those functions which are wrapped in the class can access it. These functions provide the interface between the object’s data and the program. This insulation of the data from direct access by the program is called data hiding or information hiding. Abstraction refers to the act of representing essential features without including the background details or explanation. Classes use the concept of abstraction and are defined as a list of abstract attributes such as size, wait, and cost, and function operate on these attributes. They encapsulate all the essential properties of the object that are to be created. The attributes are some time called data members because they hold information. The functions that operate on these data are sometimes called methods or member function. Inheritance Inheritance is the process by which objects of one class acquired the properties of objects of another classes. It supports the concept of hierarchical classification. For example, the bird, ‘robin’ is a part of class ‘flying bird’ which is again a part of the class ‘bird’. The principal behind this sort of division is that each derived class shares common characteristics with the class from which it is derived as illustrated in fig 1.6. In OOP, the concept of inheritance provides the idea of reusability. This means that we can add additional features to an existing class without modifying it. This is possible by deriving a new class from the existing one. The new class will have the combined feature of both the classes.

The real appeal and power of the inheritance mechanism is that it allows the programmer to reuse a class i.e almost, but not exactly, what he wants, and to tailor the class in such a way that it does not introduced any undesirable side-effects into the rest of classes. Polymorphism Polymorphism is another important OOP concept. Polymorphism, a Greek term, means the ability to take more than on form. An operation may exhibit different behavior is different instances. The behavior depends upon the types of data used in the operation. For example, consider the operation of addition. For two numbers, the operation will generate a sum. If the operands are strings, then the operation would produce a third string by concatenation. The process of making an operator to exhibit different behaviors in different instances is known as

Message Passing An object-oriented program consists of a set of objects that communicate with each other. The process of programming in an object-oriented language, involves the following basic steps:

  • Creating classes that define object and their behavior,
  • Creating objects from class definitions, and
  • Establishing communication among objects. Objects communicate with one another by sending and receiving information much the same way as people pass messages to one another. The concept of message passing makes it easier to talk about building systems that directly model or simulate their real- world counterparts. A Message for an object is a request for execution of a procedure, and therefore will invoke a function (procedure) in the receiving object that generates the desired results. Message passing involves specifying the name of object, the name of the function (message) and the information to be sent. Example: Benefits of OOP OOP offers several benefits to both the program designer and the user. Object- Orientation contributes to the solution of many problems associated with the development and quality of software products. The new technology promises greater programmer productivity, better quality of software and lesser maintenance cost. The principal advantages are: Through inheritance, we can eliminate redundant code extend the use of existing Classes. We can build programs from the standard working modules that communicate with one another, rather than having to start writing the code from scratch. This leads to saving of development time and higher productivity. The principle of data hiding helps the programmer to build secure

program that cannot be invaded by code in other parts of a programs. It is possible to have multiple instances of an object to co-exist without any interference. It is possible to map object in the problem domain to those in the program. It is easy to partition the work in a project based on objects. The data-centered design approach enables us to capture more detail of a model can implemental form. Object-oriented system can be easily upgraded from small to large system. Message passing techniques for communication between objects makes to interface descriptions with external systems much simpler. Software complexity can be easily managed. While it is possible to incorporate all these features in an object-oriented system, their importance depends on the type of the project and the preference of the programmer. There are a number of issues that need to be tackled to reap some of the benefits stated above. For instance, object libraries must be available for reuse. The technology is still developing and current product may be superseded quickly. Strict controls and protocols need to be developed if reuse is not to be compromised. Application of OOP OOP has become one of the programming buzzwords today. There appears to be a great deal of excitement and interest among software engineers in using OOP. Applications of OOP are beginning to gain importance in many areas. The most popular application of object-oriented programming, up to now, has been in the area of user interface design such as window. Hundreds of windowing systems have been developed, using the OOP techniques. Real-business system are often much more complex and contain many more objects with complicated attributes and method. OOP is useful in these types of application because it can simplify a complex problem. The promising areas of application of OOP include:

  • Real-time system
  • Simulation and modeling
  • Object-oriented data bases
  • Hypertext, Hypermedia, and expert text
  • AI and expert systems
  • Neural networks and parallel programming