Excuses Don't get results
--Your friends at LectureNotes

Note for Object Oriented Programming Using Cpp - OOP By veena bhat

  • Object Oriented Programming Using Cpp - OOP
  • Note
  • 9 Topics
  • 6 Offline Downloads
  • Uploaded 1 year ago
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-3

AMC ENGINEERING COLLEGE 5. Inheritance Inheritance is the mechanism by which one class can inherit the properties of another. It allows a hierarchy of classes to be build, moving from the most general to the most specific. When one class is inherited by another, the class that is inherited is called the base class. The inheriting class is called the derived class. In general, the process of inheritance begins with the definition of a base class. The base class defines all qualities that will be common to any derived class. . In OOPs, the concept of inheritance provides the idea of reusability. In essence, the base class represent the most general description of a set of traits. The derived class inherits those general traits and adds properties that are specific to that class. 6. Polymorphism Polymorphism is a feature that allows one interface to be used for a general class of actions. The concept of polymorphism is often expressed by the phrase “one interface, multiple methods.” Polymorphism Compile time Run time Polymorphism Polymorphism Function overloading Operator overloading Virtual functions In compile time polymorphism, the compiler is able to select the appropriate function for a particular call at compile time. In C++, it is possible to use one function name for many different purposes. This type of polymorphism is called function overloading. Polymorphism can also be applied to operators. Operators are given additional meaning to handle objects.In that case, it is called operator overloading. In run time polymorphism, the compiler selects the appropriate function for a particular call while the program is running. C++ supports a mechanism known as virtual functions to achieve run time polymorphism. Need for Object oriented Programming Object-oriented programming scales very well, provides bottom up approach,complexity can be handled in efficient manner,provides data abstraction. OOPS WITH C++ - 10CS36 VEENA BHAT, Department of CSE

Text from page-4

AMC ENGINEERING COLLEGE Benefits of Object oriented Programming 1. Simplicity: Software objects model real world objects, so the complexity is reduced and the program structure is very clear. 2. Modularity: Each object forms a separate entity whose internal workings are decoupled from other parts of the system. 3. Modifiability: It is easy to make minor changes in the data representation or the procedures in an OO program. Changes inside a class do not affect any other part of a program, since the only public interface that the external world has to a class is through the use of methods. 4. Extensibility: adding new features or responding to changing operating environments can be solved by introducing a few new objects and modifying some existing ones. 5. Maintainability: objects can be maintained separately, making locating and fixing problems easier. 6. Re-usability: objects can be reused in different programs. C++ C++ is an object oriented programming language. It was developed 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++. C++ is a superset of 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 .These features comprise of classes, inheritance, function overloading and operator overloading. C++ has many other new features as well, including an improved approach to input/output (I/O) and a new way to write comments. A Simple C++ Program #include<iostream.h> #include<conio.h> int main() { cout<< “Simple C++ program without using class”; return 0; } Lines beginning with a hash sign (#) are directives read and interpreted by what is known as the preprocessor. They are special lines interpreted before the compilation of the program itself begins. In this case, the directive #include <iostream.h>, instructs the preprocessor to include a section of standard C++ code, known as header iostream that allows to perform standard input and output operations, such as writing the output of this program to the screen. OOPS WITH C++ - 10CS36 VEENA BHAT, Department of CSE

Text from page-5

AMC ENGINEERING COLLEGE The function named main is a special function in all C++ programs; it is the function called when the program is run. The execution of all C++ programs begins with the main function, regardless of where the function is actually located within the code. The open brace ({) indicates the beginning of main's function definition, and the closing brace (}) indicates its end. The statement : cout<< “Simple C++ program without using class”; causes the string in quotation marks to be displayed on the screen. The identifier cout (pronounced as c out) denotes an object. It points to the standard output device namely the console monitor. The operator << is called insertion operator. It directs the string on its right to the object on its left. The program ends with this statement: return 0; This causes zero to be returned to the calling process (which is usually the operating system). Returning zero indicates that the program terminated normally. Abnormal program termination should be signaled by returning a nonzero value. The general structure of C++ program with classes is shown as: 1. Documentation Section 2. Preprocessor Directives or Compiler Directives Section (i) Link Section (ii) Definition Section 3. Global Declaration Section 4. Class declaration or definition 5. Main C++ program function called main ( ) C++ keywords When a language is defined, one has to design a set of instructions to be used for communicating with the computer to carry out specific operations. The set of instructions which are used in programming, are called keywords. These are also known as reserved words of the language. They have a specific meaning for the C++ compiler and should be used for giving specific instructions to the computer. These words cannot be used for any other purpose, such as naming a variable. OOPS WITH C++ - 10CS36 VEENA BHAT, Department of CSE

Text from page-6

AMC ENGINEERING COLLEGE Identifiers An identifier is a name assigned to a function, variable, or any other user-defined item. Identifiers can be from one to several characters long. Rules for naming identifiers:   ▪ ▪ Variable names can start with any  letter of the alphabet or an underscore. Next comes a letter, a digit, or an underscore.  Uppercase and lowercase are distinct. C++ keywords cannot be used as identifier. Data types Data type defines size and type of values that a variable can store along with the set of operations that can be performed on that variable. C++ provides built-in data types that correspond to integers, characters, floating-point values, and Boolean values. There are the seven basic data types in C++ as shown below: Type char(character) wchar_t(Wide character) Meaning holds 8-bit ASCII characters holds characters that are part of large character sets int(Integer) represent integer numbers having no fractional part float(floating point) stores real numbers in the range of about 3.4x10–38to 3.4x10 38,with a precision of seven digits. OOPS WITH C++ - 10CS36 VEENA BHAT, Department of CSE

Lecture Notes