×
WORK HARD UNTIL LAMP LIGHT OF STUDY TABLE BECOMES SPOT LIGHT OF STAGE.
--Your friends at LectureNotes
Close

Object Oriented Programming Using Cpp

by Amity KumarAmity Kumar
Type: NoteInstitute: Amity University Specialization: Computer Science EngineeringOffline Downloads: 13Views: 372Uploaded: 10 months ago

Share it with your friends

Suggested Materials

Leave your Comments

Contributors

Amity Kumar
Amity Kumar
INDEX UNIT 1 Introduction 2-46 UNIT 2 Classes & Objects – I 47-68 UNIT 3 Classes & Objects –II 69-118 UNIT 4 Inheritance – I1 19-128 UNIT 5 Inheritances – II1 29-145 UNIT 6 Virtual functions, Polymorphism1 46-163 UNIT 7 I/O System Basics, File I/0 164-188 UNIT 8 Exception Handling, STL 189-211
UNIT 1 Introduction 1.1 Overview of C++ 1.2 Sample C++ program 1.3 Different data types 1.4 Operators, expressions, and statements 1.5 Arrays and strings 1.6 Pointers & user-defined types 1.7 Function Components 1.8 Argument passing 1.9 Inline functions 1.10 Function overloading 1.11 Recursive functions 2
1.1 Overview of C++ C++ began as an expanded version of C. The C++ extensions were first 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++. Since C++ was first invented, it has undergone three major revisions, with each adding to and altering the language. The first revision was in 1985 and the second in 1990. The third occurred during the standardization of C++. Several years ago, work began on a standard for C++. Toward that end, a joint ANSI (American National Standards Institute) and ISO (International Standards Organization) standardization committee was formed. The first draft of the proposed standard was created on January 25, 1994. The ANSI/ISO C++ committee kept the features first defined by Stroustrup and added some new ones as well. But in general, this initial draft reflected the state of C++ at the time. What Is Object-Oriented Programming? Since object-oriented programming (OOP) drove the creation of C++, it is necessary to understand its foundational principles. OOP is a powerful way to approach the job of programming. Programming methodologies have changed dramatically since the invention of the computer, primarily to accommodate the increasing complexity of programs. For example, when computers were first invented, programming was done by toggling in the binary machine instructions using the computer's front panel. As long as programs were just a few hundred instructions long, this approach worked. As programs grew, assembly language was invented so that a programmer could deal with larger, increasingly complex programs, using symbolic representations of the machine instructions. As programs continued to grow, high-level languages were introduced that gave the programmer more tools with which to handle complexity. The first widespread language was, of course, FORTRAN. Although FORTRAN was a very impressive first step, it is hardly a language that encourages clear, easytounderstand programs. The 1960s gave birth to structured programming. This is the method encouraged by languages such asCand Pascal. The use of structured languages made it possible to write moderately 3
complex programs fairly easily. Structured languages are characterized by their support for stand-alone subroutines, local variables, rich control constructs, and their lack of reliance upon theGOTO. Although structured languages are a powerful tool, they reach their limit when a project becomes too large. Object-oriented programming took the best ideas of structured programming and combined them with several new concepts. The result was a different way of organizing a program. In the most general sense, a program can be organized in one of two ways: around its code (what is happening) or around its data (who is being affected). Using only structured programming techniques, programs are typically organized around code. This approach can be thought of as "code acting on data." For example, a program written in a structured language such as C is defined by its functions, any of which may operate on any type of data used by the program. Object-oriented programs work the other way around. They are organized around data, with the key principle being "data controlling access to code." In an object-oriented language, you define the data and the routines that are permitted to act on that data. Thus, a data type defines precisely what sort of operations can be applied to that data. To support the principles of object-oriented programming, all OOP languages have three traits in common: encapsulation, polymorphism, and inheritance. Let's examine each. Encapsulation Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse. In an object-oriented language, code and data may be combined in such a way that a self-contained "black box" is created. When code and data are linked together in this fashion, an object is created. In other words, an object is the device that supports encapsulation. Within an object, code, data, or both may be private to that object or public. Private code or data is known to and accessible only by another part of the object. That is, private code or data may not be accessed by a piece of the program that exists outside the object. When code or data is public, other parts of your program may access it even though it is defined within an object. Typically, the public parts of an object are used to provide a controlled interface to the private elements of the object. For all intents and purposes, an object is a variable of a user-defined type. It may seem strange that an object that links both 4

Lecture Notes