117x Filetype PDF File size 0.54 MB Source: apsacollege.com
PROGRAMMING IN C++ and ALGORITHMS SUBJECT CODE : 1BIT3C1,4BIT3C1 HANDLED BY PR,RAJESH MCA.,B.Ed CORE COURSE V – PROGRAMMING IN C++ AND ALGORITHMS Unit I Principles of object oriented programming – Introduction to c++ – Tokens, Expressions and Control Structures – Functions in c++ – Classes and Objects:- Introduction, C Structures Revisited, Specifying a Class, Defining Member Functions, A C++ Program with Class, Making an Outside Function Inline, Nesting of Member Functions, Private member Functions, Array within a class, Memory Allocation for Objects, Static Data Members, Static Member Functions, Array of Objects, Objects as Function Arguments, Friendly Functions, Returning Objects, Const Member Functions, Pointer to Member. Unit II Constructor and Destructors – Introduction, Constructors, Parameterized Constructors, Multiple Constructors in a class, Constructors with Default Arguments – Dynamic Initialization of Objects, Copy Constructor, Dynamic Constructors, Constructing Two-Dimensional Arrays, Destructors. Unit III Operator Overloading and Type Conversion – Introduction, Defining Operator Overloading – Overloading Unary, Binary Operators – Inheritance – Introduction, Defining Derived Class, Single Inheritance, Making Private Member inheritable, Multilevel Inheritance, Multiple Inheritance, Hierarchical Inheritance – Hybrid Inheritance, Virtual Base Class, Abstract Classes – Pointers, Virtual Functions and Polymorphism – Introduction, pointers to objects, this pointer, pointer to Derived Classes, Virtual Functions, Pure Virtual Functions. Unit IV [only the algorithm and examples no theorems] Binary search – Depth-first search – Breadth-first search – topological sort – Backtracking – Mergesort – finding the closest pair of points – Strassen’s matrix product algorithm – insertion sort – quicksort – a lower bound for the sorting problem – selection Unit V only the algorithm and examples no theorems] Coin changing – Kruskal’s algorithm – Prim’s algorithm – Dijkstra’s algorithm – Huffman codes – The continuous Knapsack problem – computing Fibonacci number – multiplying matrices – the longest-common-subsequence problem – Algorithm of Floyd and Warshall 1. Data given less importance. 2. Data structure. (The way data is organized becomes very critical. since many functions access the common data.). 3. Relationship to the real world. It is difficult to design. The problem is that the main components data structure and function do not model the real world very well. Here software maintenance will be easier. Programs become more readable. OOPS Concept Importance of oops 1. Emphasis is on data rather than procedure. 2. Programs are divided into objects. 3. Data structures are designed such that they characterize the object. 4. Functions that operate on the data of an object are tied together in the data structure. 5. Data is hidden and cannot be accessed by external functions. 6. Objects may communicate with each other through functions. 7. New data and functions can be added whenever necessary. 8. Follow bottom up approach in program design. Characteristics of oops 1. Class 2. Objects 3. Data abstraction. 4. Data encapsulation. 5. Inheritance 6. Polymorphism 7. Dynamic binding 8. Message passing. 1. Class It is nothing but a user defined data type. It consists of member data and member functions. Hence a class is a collection of objects of similar type. The entire set of a data and code of an object can be made a user defined data type with the help of a class. 2. Objects Objects contain data and the code to manipulate that data. It is the runtime entity for a class. We can access the member variable and member functions of a class by using the objects only. Objects are called as instance (variables) of a class. Once a class has been defined we can create any no of objects belonging to that class. Objects interact by sending messages to one another. 3. Data abstraction The way of accessing variables of a class or member functions of a class is called data abstraction. Class uses the concept of data abstraction, and hence they are known as abstract base class. (ABC) 4. Data encapsulation The wrapping up of data and functions into a single unit is known as encapsulation. The data is not accessible to the outside world and only those functions which are wrapped in the class can access it. The insulation of the data from direct access by the program is called data hiding. 5. Inheritance Inheritance is the process by which objects of one class acquires the properties of objects of another class. It provides the idea of reusability. This means that we can add additional features to an existing class without modifying it. I.e. we can derive a new class from the existing one. The new class will have the combined features of both the classes. 6. Polymorphism Polymorphism is the ability to take more than one form. It is extensively used in implementing inheritance. e.g.: Consider an addition operation. For two no, it will generate a sum. Similarly if the operands are strings then the operation would produce a third string by concatenation. A single object can react on multiple functions. Overloading It is same as polymorphism. We can overload functions, operators etc. 7. Dynamic binding Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at runtime. It is associated with polymorphism and inheritance. 8. Message communication This is done by using the objects. A message for an object is a request for execution of a procedure and therefore will invoke a function in the receiving object that generates the desired result. Functions Function overloading It is the logical method of calling the several functions with the same name. Each redefinition of a function must use different type of parameters, or different no of parameters, or different sequence of parameters. The current function to be invoked is determined by checking the number and type of the arguments but not on the function type. A function call first matches the prototype having the same no and type of arguments and then calls the appropriate function for execution. A best match must be unique. Advantages 1. Eliminating the use of different function name for the same operation. 2. Helps to understand, delay, and grasp easily. 3. Easy maintainability of 1the code. 1. Function overloading with different type of parameters E.g.: funo1.cpp #include#include #include int abs(int); double abs(double); void main() { int a; double b;
no reviews yet
Please Login to review.