Posts

Showing posts from 2018

LAB Practical V

a) Write a program to show the working mode of try, throw and catch blocks in C++

LAB Practical IV

a) Write a program to show overriding Base class members in a Derived class b) Write a program to show Complexity and ambiguity in Inheritance  

LAB Practical III

a) write a c++ program to implement binary and unary operator overloading  

LAB Practical II

i) Write a c++ program to show static member function and static member data. ii) Write a c++ program to show constructor, destructor, inheritance and dynamic memory allocation in same program.

Operator Overloading

Image
Operator overloading is an important concept in C++. It is a type of polymorphism in which an operator is overloaded to give user defined meaning to it. Overloaded operator is used to perform operation on user-defined data type. For example '+' operator can be overloaded to perform addition on various data types, like for Integer, String(concatenation) etc. Almost any operator can be overloaded in C++. However there are few operator which can not be overloaded. Operator that are not overloaded are follows scope operator - :: sizeof member selector - . member pointer selector - * ternary operator - ?: Operator Overloading Syntax Implementing Operator Overloading Operator overloading can be done by implementing a function which can be : Member Function Non-Member Function Friend Function Operator overloading function can be a member function if the Left operand is an Object of that class, but if the Left operand is different, then Operator ove...

LAB Practical I

Write a c++ program to show multiple inheritance and dynamic polymorphism in same program.

B.TECH CSE BT ECE(oop's): Abstract Classes in C++

Sometimes implementation of all function cannot be provided in a base class because we don’t know the implementation. Such a class is called abstract class. For example, let Shape be a base class. We cannot provide implementation of function draw() in Shape, but we know every derived class must have implementation of draw(). Similarly an Animal class doesn’t have implementation of move() (assuming that all animals move), but all animals must know how to move. We cannot create objects of abstract classes. A pure virtual function (or abstract function) in C++ is a virtual function for which we don’t have implementation, we only declare it. A pure virtual function is declared by assigning 0 in declaration. See the following example. #include<iostream> using namespace std;     class Base {     int x; public :      virtual void fun() = 0;      int getX() { return x; } }; ...

B.TECH CSE BT ECE(oop's): ‘this’ pointer in C++

To understand ‘this’ pointer, it is important to know that how objects look at functions and data members of a class. 1. Each object gets its own copy of the data member. 2. All access the same function definition as present in the code segment. Meaning each object gets its own copy of data members and all objects share single copy of member functions. Then now question is that if only one copy of each member function exists and is used by multiple objects, how are the proper data members are accessed and updated? Compiler supplies an implicit pointer along with the functions names as ‘this’. The ‘this’ pointer is passed as a hidden argument to all nonstatic member function calls and is available as a local variable within the body of all nonstatic functions. ‘this’ pointer is a constant pointer that holds the memory address of the current object. ‘this’ pointer is not available in static member functions as static member functions can be called without any object (with ...

B.TECH CSE BT ECE(oop's): Member Function

Types of Member Functions We already know what member functions are and what they do. Now lets study some special member functins present in the class. Following are different types of Member functions, Simple functions Static functions Const functions Inline functions Friend functions a) Simple Member functions These are the basic member function, which dont have any special keyword like static etc as prefix. All the general member functions, which are of below given form, are termed as simple and basic member functions. return_type functionName(parameter_list) { function body; } b) Static member functions/ Static Data member  When we declare a normal variable (data member) in a class, different copies of those data members create with the associated objects. In some cases when we need a common data member that should be same for all objects, we cannot do this using normal data members. To fulfill such cases, we need static data members. In...

B.TECH CSE BT ECE(oop's): Dynamic memory allocation

Dynamic memory allocation means creating memory at runtime. For example, when we declare an array, we must provide size of array in our source code to allocate memory at compile time. But if we need to allocate memory at runtime me must use new operator followed by data type. If we need to allocate memory for more than one element, we must provide total number of elements required in square bracket[ ]. It will return the address of first byte of memory. Syntax of new operator ptr = new data-type; //allocte memory for one element ptr = new data-type [ size ]; //allocte memory for fixed number of element C++ delete operator Delete operator is used to deallocate the memory created by new operator at run-time. Once the memory is no longer needed it should by freed so that the memory becomes available again for other request of dynamic memory. ...

B.TECH CSE BT ECE(oop's): Function Overloading vs Function Overriding in C++

Function Overloading vs Function Overriding in C++ Function Overloading (achieved at compile time) It provides multiple definitions of the function by changing signature i.e changing number of parameters, change datatype of parameters, return type doesn’t play anyrole. It can be done in base as well as derived class. Example: void area(int a); void area(int a, int b); // CPP program to illustrate // Function Overloading #include <iostream> using namespace std;     // overloaded functions void test( int ); void test( float ); void test( int , float );     int main() {      int a = 5;      float b = 5.5;          // Overloaded functions      // with different type and      // number of parameters      test(a);      test(b); ...

B.TECH CSE BT ECE(oop's) : Inheritance in C++

Image
Inheritance in C++ The capability of a class to derive properties and characteristics from another class is called Inheritance . Inheritance is one of the most important feature of Object Oriented Programming. Sub Class: The class that inherits properties from another class is called Sub class or Derived Class. Super Class: The class whose properties are inherited by sub class is called Base Class or Super class.  Modes of Inheritance Public mode : If we derive a sub class from a public base class. Then the public member of the base class will become public in the derived class and protected members of the base class will become protected in derived class. Protected mode : If we derive a sub class from a Protected base class. Then both public member and protected members of the base class will become protected in derived class. Private mode : If we derive a sub class from a Private base class. Then both public member and protected...

B.TECH CSE BT ECE(oop's)- Abstract class

Abstract class in C++ is the one which is not used to create objects. These type of classes are designed only to treat like a base class (to be inherited by other classes). It is a designed technique for program development which allows making a base upon which other classes may be built. In C++ language, programmers can use access modifiers to define the abstract interface of the class. A C++ class may contain zero or more access labels: As you all became familiar that members defined within the public access specifier are accessible to l parts of the program. The data abstraction of a type can be viewed or classified by its public members. When the access specifier is in private mode, members defined in the private mode are not accessible to code that uses the class. The private section is designed specifically for hiding the implementation of code within a C++ program. There is no limitation on how access modifiers may appear within a program. The specific acces...

B.TECH CSE BIO ECE- OOP'S

HI students here i attached study materila for oops  Ch1 Click here to download