--Your friends at LectureNotes

Note for Object Oriented Programming Using Cpp - OOP By Papithasri K

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

Share it with your friends

Leave your Comments

Text from page-1

080230004 - Object Oriented Programming www.Vidyarthiplus.com UNIT 1 Basic Concepts of OOPS Before starting to learn C++ it is essential that one must have a basic knowledge of the concepts of Object Oriented Programming. Some of the important object oriented features are namely:  Objects  Classes  Inheritance  Data Abstraction  Data Encapsulation  Polymorphism  Overloading  Reusability In order to understand the basic concepts in C++, the programmer must have a command of the basic terminology in object-oriented programming. Below is a brief outline of the concepts of Object-oriented programming languages: Objects Object is the basic unit of object-oriented programming. Objects are identified by its unique name. An object represents a particular instance of a class. There can be more than one instance of an object. Each instance of an object can hold its own relevant data. An Object is a collection of data members and associated member functions also known as methods. Classes Classes are data types based on which objects are created. Objects with similar properties and methods are grouped together to form a Class. Thus a Class represents a set of individual objects. Characteristics of an object are represented in a class as Properties (Attributes). The actions that can be performed by objects become functions of the class and are referred to as Methods (Functions). For example consider we have a Class of Cars under which Santro Xing, Alto and WaganR represents individual Objects. In this context each Car Object will have its own, Model, Year of Manufacture, Colour, Top Speed, Engine Power etc., which form Properties of the Car class and the associated actions i.e., object functions like Start, Move, Stop form the Methods of Car Class. No memory is allocated when a class is created. Memory is allocated only when an object is created, i.e., when an instance of a class is created. Inheritance Inheritance is the process of forming a new class from an existing class or base class. The base class is also known as parent class or super class. The new class that is formed is called derived class. Derived class is also known as a child class or sub class. Inheritance helps in reducing the overall code size of the program, which is an important concept in object-oriented programming. Data Abstraction Data Abstraction increases the power of programming language by creating user defined data types. Data Abstraction also represents the needed information in the program without presenting the details. www.Vidyarthiplus.com Dept of IT SVHEC 1

Text from page-2

080230004 - Object Oriented Programming www.Vidyarthiplus.com Data Encapsulation Data Encapsulation combines data and functions into a single unit called Class. When using Data Encapsulation, data is not accessed directly; it is only accessible through the functions present inside the class. Data Encapsulation enables the important concept of data hiding possible. Polymorphism Polymorphism allows routines to use variables of different types at different times. An operator or function can be given different meanings or functions. Polymorphism refers to a single function or multi-functioning operator performing in different ways. Overloading Overloading is one type of Polymorphism. It allows an object to have different meanings, depending on its context. When an exiting operator or function begins to operate on new data type, or class, it is understood to be overloaded. Reusability This term refers to the ability for multiple programmers to use the same written and debugged existing class of data. This is a time saving device and adds code efficiency to the language. Additionally, the programmer can incorporate new features to the existing class, further developing the application and allowing users to achieve increased performance. Introduction to C++ Variable, Constants and Data types in C++ Variables A variable is the storage location in memory that is stored by its value. A variable is identified or denoted by a variable name. The variable name is a sequence of one or more letters, digits or underscore, for example: character _ Rules for defining variable name: example character _. denote variable name. programming language. C++ is a case-sensitive language. Variable names written in capital letters differ from variable names with the same name but written in small letters. For example, the variable name EXFORSYS differs from the variable name exforsys. Data Types Below is a list of the most commonly used Data Types in C++ programming language Using variable names and data type, we shall now learn how to declare variables. Declaring Variables: In order for a variable to be used in C++ programming language, the variable must first be declared. The syntax for declaring variable names is data type variable name; The date type can be int or float or any of the data types listed above. A variable name is given based on the rules for defining variable name (refer above rules). www.Vidyarthiplus.com Dept of IT SVHEC 2

Text from page-3

080230004 - Object Oriented Programming www.Vidyarthiplus.com Example: int a; This declares a variable name a of type int. If there exists more than one variable of the same type, such variables can be represented by separating variable names using comma. For instance int x,y,z ; This declares 3 variables x, y and z all of data type int. The data type using integers (int, short int, long int) are further assigned a value of signed or unsigned. Signed integers signify positive and negative number value. Unsigned integers signify only positive numbers or zero. For example it is declared as unsigned short int a; signed int z; By default, unspecified integers signify a signed integer. For example: int a; is declared a signed integer It is possible to initialize values to variables: data type variable name = value; Example: int a=0; int b=5; Constants Constants have fixed value. Constants, like variables, contain data type. Integer constants are represented as decimal notation, octal notation, and hexadecimal notation. Decimal notation is represented with a number. Octal notation is represented with the number preceded by a zero character. A hexadecimal number is preceded with the characters 0x. Example 80 represent decimal 0115 represent octal 0x167 represent hexadecimal By default, the integer constant is represented with a number. The unsigned integer constant is represented with an appended character u. The long integer constant is represented with character l. Example: 78 represent int 85u present unsigned int 78l represent long Floating point constants are numbers with decimal point and/or exponent. Example 2.1567 4.02e24 These examples are valid floating point constants. Floating point constants can be represented with f for floating and l for double precision floating www.Vidyarthiplus.com Dept of IT SVHEC 3

Text from page-4

080230004 - Object Oriented Programming www.Vidyarthiplus.com point numbers. Character constants have single character presented between single quotes. Example ‗c‘ ‗a‘ are all character constants. Strings are sequences of characters signifying string constants. These sequence of characters are represented between double quotes. Example: ―Exforsys Training‖ is an example of string constant. Referencing variables The & operator is used to reference an object. When using this operator on an object, you are provided with a pointer to that object. This new pointer can be used as a parameter or be assigned to a variable. C++ Objects and Classes An Overview about Objects and Classes In object-oriented programming language C++, the data and functions (procedures to manipulate the data) are bundled together as a self-contained unit called an object. A class is an extended concept similar to that of structure in C programming language, this class describes the data properties alone. In C++ programming language, class describes both the properties (data) and behaviors (functions) of objects. Classes are not objects, but they are used to instantiate objects. Features of Class: Classes contain member data and member functions. As a unit, the collection of member data and member functions is an object. Therefore, this unit of objects makes up a class. How to write a Class: In Structure in C programming language, a structure is specified with a name. The C++ programming language extends this concept. A class is specified with a name after the keyword class. The starting flower brace symbol, {is placed at the beginning of the code. Following the flower brace symbol, the body of the class is defined with the member functions data. Then the class is closed with a flower brace symbol} and concluded with a colon;. class exforsys { member data; member functions; …………… }; There are different access specifiers for defining the data and functions present inside a class. Access specifiers: Access specifiers are used to identify access rights for the data and member functions of the class. There are three main types of access specifiers in C++ programming language: www.Vidyarthiplus.com Dept of IT SVHEC 4

Lecture Notes