Listen to your teachers when they tell you WHAT to do. But more importantly, think about it later and ask yourself WHY they told you to do it.
--Your friends at LectureNotes

Object Oriented Programming Using Cpp

by Vssut Rulers
Type: NoteInstitute: Veer Surendra Sai University Of Technology VSSUT Views: 5Uploaded: 1 month agoAdd to Favourite

Touch here to read

Object Oriented Programming Using Cpp by Vssut Rulers

Vssut Rulers
Vssut Rulers

/ 61

Share it with your friends

Suggested Materials

Leave your Comments


Vssut Rulers
Vssut Rulers
BCS 201: OBJECT ORIENTED PROGRAMMING Module-1 (10 Lectures) Introduction to object oriented programming, user-defined types, polymorphism, and encapsulation. Getting started with C++ syntax, data-type, various, functions, exceptions and statement, namespaces and exceptions, operators, flow control, functions, recursion. Arrays and pointers, structures. Module – II (10 Lectures) Abstraction mechanisms: Classes, private, public construction, member functions, static members, references etc. class hierarchy, derived classes. Inheritance: simple inheritance, polymorphism, object slicing, base initialization virtual functions. Module – III (12 Lectures) Prototypes, linkages, operator overloading, ambiguity, friends, member operators, operator function, I/O operator etc. Memory management: new delete, object copying copy constructors, assignment operator, this input/output. Exception handling: Exceptions and derived classes, function exception declarations, Unexpected exceptions, Exceptions when handling exceptions, resource capture and release etc. Module – IV (08 Lectures) Templates and standard Template library: template classes, declaration, template functions, namespaces, string, iterates hashes, iostreams and other type. Design using C++ design and development, design and programming, role of classes. VEER SURENDRA SAI UNIVERSITY OF TECHNOLOGY, BURLA, ODISHA
BCS 201: OBJECT ORIENTED PROGRAMMING Introduction to C++ Starting with C++ How C++ evolved from C? OOP vs. procedure-oriented programming Features of C++ The basic anatomy of a C++ program Compiling, linking and running a C++ program Note: The history of C++ begins with C. C++ is built upon the foundation of C. Thus, C++ is a superset of C. C++ expanded and enhanced the C language to support objectoriented programming. C++ also added several other improvements to the C language, including an extended set of library routines. However, much of the spirit and flavor of C++ is directly inherited from C. Therefore, to fully understand and appreciate C++, you need to understand the “how and why” behind C. C++ was invented by Bjarne Stroustrup in 1979, at Bell Laboratories in Murray Hill, New Jersey. He initially called the new language “C with Classes” However in 1983 the name was changed to C++ Stroustrup built C++ on the foundation of C including all of C’s features attributes and benefits. Most of the features that Stroustrup added to C were designed to support object-oriented programming. In essence, C++ is the objectoriented version of C. By building upon the foundation of C, Stroustrup provided a smooth migration path to OOP. Instead of having to learn an entirely new language, a C programmer needed to learn only a few new features before reaping the benefits of the object-oriented methodology. Procedure-Oriented Programming Vs. OOP 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 C, Pascal, fortran etc. The primary focus is on functions. A typical structure for procedural programming is shown in fig.1.1. The technique of hierarchical decomposition has been used to specify the tasks to be completed for solving a problem. Fig. 1.1 Structure of procedural oriented programs Procedure oriented programming basically consists of writing a list of instructions for the computer to follow and organizing these instructions into groups known as VEER SURENDRA SAI UNIVERSITY OF TECHNOLOGY, BURLA, ODISHA
BCS 201: OBJECT ORIENTED PROGRAMMING functions. We normally use flowcharts to organize these actions and represent the flow of control from one action to another. In a multi-function program, many important data items are placed as global so that they may be accessed by all the functions. Each function may have its own local data. Global data are more vulnerable to an inadvertent change by a function. In a large program it is very difficult to identify what data is used by which function. In case we need to revise an external data structure, we also need to revise all functions that access the data. This provides an opportunity for bugs to creep in. Another serious drawback with the procedural approach is that we do not model real world problems very well. This is because functions are action-oriented and do not really corresponding to the element of the problem. Some Characteristics exhibited by procedure-oriented programming are: • Emphasis is on doing things (algorithms). • Large programs are divided into smaller programs known as functions. • Most of the functions share global data. • Data move openly around the system from function to function. • Functions transform data from one form to another. • Employs top-down approach in program design. Object-Oriented Programming (OOP) 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.2. 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. Fig. 1.2 Organization of data and function in OOP Some Characteristics of Object Oriented Programming • 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. VEER SURENDRA SAI UNIVERSITY OF TECHNOLOGY, BURLA, ODISHA
BCS 201: OBJECT ORIENTED PROGRAMMING • • • 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. To support the principles of object-oriented programming, all OOP languages, including C++, have the following characteristics • Objects • Classes • Data abstraction and encapsulation • Inheritance • Polymorphism • Dynamic binding • Message passing Let’s examine each. 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 should be chosen such that they match closely with the real-world objects. Objects take up space in the memory and have an associated address like a record in Pascal, or a structure in c. When a program is executed, the objects interact by sending messages to one another. For example, if “customer” and “account” are to object in a program, then the customer object may send a message to the count object requesting for the bank balance. Each object contain data, and code to manipulate data. Objects can interact without having to know details of each other’s data or code. It is sufficient to know the type of message accepted, and the type of response returned by the objects. Classes As mentioned above the objects contain data, and code to manipulate that data. The entire set of data and code of an object can be made a user-defined data type with the help of class. In fact, objects are variables of the type class. Once a class has been defined, we can create any number of objects belonging to that class. Each object is associated with the data of type class with which they are created. A class is thus a collection of objects similar types. For examples, guava, mango and orange are members of the class fruit. Classes are user-defined that types and behave like the builtin 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 Encapsulation is a programming mechanism that binds together code and the data it manipulates, and that keeps both safe from outside interference and misuse. In an object-oriented language, code and data can be bound together in such a way that a self-contained black box is created. Within the box are all necessary data and code. VEER SURENDRA SAI UNIVERSITY OF TECHNOLOGY, BURLA, ODISHA

Lecture Notes