OBJECT ORIENTED PROGRAMMING THROUGH C++ SYLLABUS Objectives:
Expertise in object oriented principles and their implementation in C++
UNIT – I
Objectives:
Exposure to basics of object oriented mode, C++ programming and I/O in C++
INTRODUCTION:
Differences between C and C++, the Object Oriented Technology, disadvantages of conventional programming, concepts of object oriented programming, advantages of OOP, Structure of C++ Program, Header Files and Libraries.
INPUT AND OUTPUT IN C++ :
Introduction, Streams in C++ and Stream Classes, Pre-Defined Streams, Stream Classes, Formatted and Unformatted Data, Unformatted Console I/O Operations, Member Functions of Istream Class, Formatted Console I/O Operations, Bit Fields, Flags without Bit Filed, Manipulators, User Defined Manipulators.
UNIT – II Objectives:
Focus on basic concept in C++ programming, Operators, control structures, function, overloading, and recursion. Tokens in C++, Variable Declaration and Initialization, Data Types, Operators in C and C++, Scope Access Operator, Namespace, Memory Management Operators, Comma Operator, Revision of Decision Statements, Control Loop Statements.
FUNCTIONS IN C++:
Introduction, Structure and Function, Passing Arguments, Lvalues and Rvalues, Return by Reference, Returning more values by reference. Default Arguments, Const Arguments, Inputting Default Arguments, Inline Functions, Function Overloading, Principles of Function Overloading, Recursion.
UNIT – III Objectives:
Acquaintance with classes, objects and member functions CLASSES AND OBJECTS: Introduction, Classes in C++, Declaring objects, Access Specifiers and their scope, Member functions, outside member function as Inline, Data hiding or encapsulation, Classes, Objects and Memory, static member variables, static member functions static object, Array of objects, Objects as Function Arguments, Friend Functions, The Const Member Functions, The volatile member function, Recursive member function, local classes, Empty, static and const classes, member function and non-member function, Overloading Member functions, Nested Classes.
UNIT – IV
Objectives:
Focus on constructors, destructors, variants in them, operator overloading, type conversions CONSTRUCTORS AND DESTRUCTORS: Introduction, Characteristic of Constructors and Destructors, Applications with constructors, Parameterized Constructor, Overloading Constructors (Multiple Constructors), Array of Objects using constructors, Constructors with default arguments, Copy Constructors, The const objects, Destructors, Calling constructors and destructors, qualifier and nested classes, Anonymous objects, private constructors and destructors, Dynamic initialization using constructors, dynamic operators and constructors, recursive constructors, constructor and destructor with static members, Local Vs Global object. OPERATOR OVERLOADING AND TYPE CONVERSION : Introduction, Overloading unary operators, Constraint on Increment and Decrement Operators, Overloading binary operators, overloading with friend function, overloading assignment operator(=), Type Conversion, Rules for overloading operators, One Argument Constructor and operator function, overloading stream operators.
UNIT – V Objectives :
Concentration on inheritance, types of inheritance, polymorphism, virtual functions INHERITANCE: Introduction, Reusability, Access Specifiers and Simple Inheritance, Protected Data with Private inheritance, types of inheritance (Single inheritance, Multilevel inheritance, Multiple inheritance, hierarchical inheritance, hybrid inheritance, Multipath inheritance), Virtual base classes, constructors, destructors and inheritance, object as a class member, abstract classes, qualifier classes and inheritance, constructor in derived class, pointers and inheritance, overloading member function, advantages of inheritance, disadvantages of inheritance.
BINDING POLYMORPHISM AND VIRTUAL FUNCTIONS:
Introduction, binding in C++, static (early) binding, dynamic (late) binding, pointer to base and derived class objects, virtual functions, rules for virtual functions, virtual function in derived classes, object slicing, constructors and virtual functions, virtual destructors, destructor and virtual functions.
UNIT – VI Objectives:
Focus on Files, File operations, generic programming, templates, function templates, Exception handling. APPLICATIONS WITH FILES : Introduction, File Stream Classes, File Opening modes, file pointers and manipulators, manipulators with arguments, sequential access files, binary and ASCII files random access operation. GENERIC PROGRAMMING WITH TEMPLATES : Introduction, Need of Template, Definition of class template, normal function template, working of function templates, class template with more parameters, functions templates with more arguments, overloading of template functions, member function templates, recursion with template function, class template with overloaded operators, class template revisited, class templates and inheritance, Container classes, types of containers, container adaptors, Iterators. EXCEPTION HANDLING : Introduction, Principles of Exception handling, the key words try, throw and catch, Exception handling mechanism, Multiple catch statements, catching multiple exceptions, re-throwing exception, specifying exception, exceptions in constructor and destructor, controlling uncaught exceptions, class template with exception handling.
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++.
Although C was one of the most liked and widely used professional programming languages in the world, the invention of C++ was necessitated by one major programming factor: increasing complexity.
The essence of C++ is to allow the programmer to comprehend and manage larger, more complex programs.
Most additions made by Stroustrup to C support object-oriented programming, referred to as OOP.
C++ is a general purpose programming language with a bias towards systems programming that is a better C
supports data abstraction
supports object-oriented programming
supports generic programming. Disadvantages of Conventional programming : Traditional programming languages such as COBOL, FORTRAN, C etc. are commonly known as procedure oriented languages. The program written in these languages consists of a sequence of instructions that tells the compiler or interpreter to perform a given task. Numerous functions are initiated by the user to perform a task. When a program code is large, it becomes inconvenient to manage it. To overcome this problem, procedures or subroutines were adopted to make a program more understandable to the programmers. A program is divided into many functions. Each function can call another function, as shown in Figure. Each function has its own task. If the program is too large the function also creates problems. In many programs, important data variables are declared as global. In case of programs containing several functions, every function can access the global data as per the simulation in Figure. In huge programs, it is difficult to know what data is used by which function. Due to this the program may contain several logical errors.
INTRODUCTION:
Differences between C and C++, the Object Oriented Technology, disadvantages of conventional programming,
The following are the drawbacks observed in conventional programming languages:
1. Huge programs are divided into smaller programs known as functions. These functions can call one another. Hence security is not provided.
2. No importance is given to security of data and importance is laid on doing things.
3. Data passes globally from function to function. Global data are more vulnerable to an inadvertent change by a function.
4. Most functions accesses global data.
5. This approach does not model real world problems very well.
6. Emphasis is mainly focussed on algorithms.
7. Maintenance of large software system is tedious and costly.
8. Communication between procedures is facilitated by parameter passing. Coordination among multiple parameters is required for handling the changes made to mutually shared data items.
Object Oriented Paradigm:
Object Oriented Programming popularly called OOP is one of the buzzwords in the software industry and it is the solution to overcome software crisis.
OOP as a paradigm, is playing an increasingly significant role in the analysis, design and implementation of software systems. Software developed using Object oriented technologies are more reliable, easier to maintain, easier to reuse and enhance, and so on.
Structured programming and Object Oriented Programming fundamentally differ in the following way.
Structure programming views the two core elements (data and functions) of any program as separate entities, whereas OOP views them as a single entity.
The Object oriented paradigm is effective in solving many of the outstanding problems in software engineering.
The sole purpose of a computer program is to manipulate data. OOP is designed around the data being operated upon as opposed to the operations themselves.
OO languages provide the programmer the ability to create class hierarchies, instantiate co-operative objects collectively working on a problem to produce the solution and send messages between objects to process themselves.
Programmer can create modular, reusable code with the power of OO languages.
Flexibility is gained by being able to change or replace modules without disturbing other parts of the code.
Objects:
Objects are the basic run-time entities in an object-oriented system.
They may represent a person, a place, a bank account, a table of data or any item that the program must handle.
Program objects should be chosen such that they match closely with the real-world objects.
Objects take up space in the memory and have an associated address like structure in C.
When a program is executed the objects interact by sending messages to one another. Classes:
The entire set of data and code of an object can be made a user-defined data type with the help of a class
Objects are variable of type class.
Once a class has been defined we can create any number of objects belonging to that class.
A class is thus a collection of objects of similar type.
Classes are user-defined data types and behave like the built-in types of programming language.
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 or information
Unit - I Data Abstraction:
Abstraction refers to the act of representing essential features without including the background details or explanations.
Classes use the concept of abstraction and are defined as a list of abstract attributes such as size, weight and cost, and functions to operate on these attributes.
Since the classes use the concept of data abstraction, they are known as Abstract Data Types.
Inheritance:
Inheritance is the process by which objects of one class acquire the properties of objects of another class.
The principle behind this sort of division is that each derived class shares common characteristics with the class from which it is derived.
In OOP the concept of inheritance provides the idea of reusability.
This means that we can add additional features to an existing class without modifying it.
Polymorphism:
Polymorphism means the ability to take more than one form.
That is an operation may exhibit different behaviours in different instances. The behaviour depends upon the types of data used in the operation. Example : operation of addition.
For two numbers the operation will generate a sum. If the operands are strings, then operation would produce a third string by concatenation.
The process of making an operator to exhibit different behaviours in different instances is known as Operator Overloading.
Using a single function name to perform different types of tasks is known as function overloading.
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 run-time.
It is associated with polymorphism and inheritance.
Message Communication:
An object oriented program consists of a set of objects that communicate with each other.
Objects communicate with one another by sending and receiving information much that same way as people pass messages to one another.
Message passing involves specifying the name of the object, the name of the function (message) and the information to be sent. emp.salary(emp_name) Benefits of OOP: Object oriented technology provides many advantages to the programmer and the user. This technology solves many problems related to software development, provides improved quality and low cost software.
Object oriented programs can be comfortably upgraded.
Through inheritance we can eliminate the redundant code and extend the use of existing code.
Data hiding helps the programmer to build secure programs that cannot be invaded by code in other parts of the program.
It is possible to have multiple instances of an object to co-exist without any interference.
It is possible to map objects in the problem domain to those objects in the program.
Data-centred design approach enables us to capture more details of a model in implementable form.
Object-oriented systems can be easily upgraded from small to large systems.
Software complexity can be easily managed.
The encapsulation feature provided by OOP languages allows programmer to define the class with many functions and characteristics and only few functions are exposed to the user.
All OOP languages allow creating extended and reusable parts of the program.
Objects communicate with each other and pass messages.
Differences between C and C++ :
C++ is a direct descendant of C that retains almost all of C as a subset.
C++ is derived from C Language. It is a Superset of C.
Earlier C++ was known as C with classes.
C++ provides stronger type checking than C and directly supports a wider range of programming styles than C.
In C++, the major change was the addition of classes and a mechanism for inheriting class objects into other classes.
Most C Programs can be compiled using C++ compiler.
C++ expressions are the same as C expressions.
All C operators are valid in C++. C C++ C is Procedural Language. C++ is non Procedural i.e Object oriented Language. Virtual functions are not present in C Virtual functions are used in C++ Polymorphism is not possible The concept of polymorphism is used in C++. Polymorphism is the most Important Feature of OOP Operator overloading is not possible in C Operator overloading is one of the greatest feature of C++. Top down approach is used in Program Design Bottom up approach adopted in Program Design No namespace Feature is present in C Language Namespace Feature is present in C++ for avoiding Name collision.
scanf()
Function used for Input.
printf()
Function used for output.
cin>> stream used for Input.
cout<< stream used for output. Mapping between Data and Function is difficult and complicated. Mapping between Data and Function can be used using "Objects" C requires all the variables to be defined at the starting of a scope. C++ allows the declaration of variable anywhere in the scope i.e., at time of its first use. No inheritance is possible in C Inheritance is possible in C++
malloc( ) and calloc( )
functions are used for Memory allocation and free( ) function for memory deallocation. new and delete operators are used for Memory allocation and deallocation does not support exception handling C++ supports exception handling program : Following figure summarizes the structure of a C++ program. It shows five different parts of a C++ program. Header File Declaration Section: The pre-processor directives are to be included at the beginning of the program before the main(). It begins with symbol „#‟. It can be placed anywhere, but quite often, it is declared at the beginning. Header files used in the program are listed in the Header file declaration section. By using #include one can write modular programs. Header File provides Prototype declaration for different library functions. We can also include user defined header files. Basically all pre-processor directives are written in this section.
Global Declaration Section :
Global Variables are declared in this section. They may include Declaring Structure, Class, Variable. Class Declaration and Method Definition Section: Actually this section can be considered as a sub section for the global declaration section. Class declaration and all methods of that class are defined here. Main Function: Like C, each and every C++ program always starts with main function. This is entry point for all the execution. Each and every method is called indirectly through main. We can create class objects in the main. Operating system call this function automatically. Method definition section: This is optional section. This part contains definitions of methods. Header Files and Libraries: A header file is a file containing declarations and macro definitions to be shared between several source files. You request the use of a header file in your program by including it, with the pre-processing directive ‘#include’. Header files serve two purposes.
System header files declare the interfaces to parts of the operating system. You include them in your program to supply the definitions and declarations you need to invoke system calls and libraries.
Your own header files contain declarations for interfaces between the source files of your program. Each time you have a group of related declarations and macro definitions all or most of which are needed in several different source files, it is a good idea to create a header file for them. Including a header file produces the same results as copying the header file into each source file that needs it. Such copying would be time-consuming and error-prone. With a header file, the related declarations appear in only one place. If they need to be changed, they can be changed in one place, and programs that include the header file will automatically use the new version when next recompiled.The source code for these library functions enclosed in system header files are not provided, but they are in a compiled form. The library functions perform operations such as memory management, reading and writing disk files, mathematical operations etc. The following table illustrates header files and library functions. Name of the header file Function of the header file List of the few functions supported by the header files alloc.h Memory management functions calloc( ), malloc( ), free( ), realloc( ) etc. complex.h Complex math functions asin( ), atan( ), arg( ), etc. ctype.h Type conversion functions toupper( ), tolower( ), islower( ), isupper( ) etc. dos.h Perform DOS functions getdate(), gettime(), int86(), sleep() etc. graphics.h Graphical related functions arc(), bar(), circle(), getx(), gety() etc. process.h Process related information exit(), abort(), system() string.h Manipulation of strings strcpy(), strlen(), strcat() etc.
UNIT – I (part-1)
1. Differentiate between dynamic binding and message passing
. 2. Differentiate between dynamic binding and message passing.
3. Discuss the major advantages of OOP paradigm and functions of OOPs.
4. Explain the organization of data and functions in OOP.
5. List a few domain application of OOP technology.
6. Explain the organization of data and functions in OOP.
7 . What the concepts are of object oriented programming? Explain in detail.
8. Differentiate between C and C++ programs? Illustrate with sample programs?
9. Discuss about the structure of C ++ program? What are Streams?
Every program must go through the process of input-computation-output flow so that it can take some data as input and generate the processed data as output. It needs a mechanism to supply input data to a program and present the processed data in the desired form.
C++ supports a wide variety of features to control the way data is read and the output is presented.
C++ uses the concept of streams and stream classes to perform I/O operations with console and disk files. C++ streams deal with a sequence of characters.
A stream is an entity where a program can either insert or extract characters to/from. There is no need to know details about the media associated to the stream or any of its internal specifications. All we need to know is that streams are a source/destination of characters, and that these characters are provided/accepted sequentially.
Streams are classified into o Input streams o Output streams
In C++, the I/O system is designed to operate on a wide variety of devices including console, disks, printer etc. it is designed to provide a consistent and device independent interface.
The stream is a flow of data, measured in bytes in sequence.
If the data is received from input devices in sequence, then it is called as source stream. The data in source stream is used as input data by the program; hence it is also called as input stream.
If the data is passed to output devices, then it is called as destination stream. As this stream collects output from the program, it is also called as output stream.
A stream is an inter-mediator between I/O devices and the user. The input stream receives data from keyboard or storage devices such as hard disk, floppy disk etc. The data present in output stream is passed on to the output devices such as monitor or printer according to the user‟s choice. Streams in C++: The C language supports an extensive set of library functions for managing I/O operations. They are printf, scanf, puts, gets, fopen, fwrite. fread, fscanf, fclose, etc. and these I/O functions defined in the header file stdio. h. These are inadequate and clumsy when used with object-oriented programming. For instance, INPUT AND OUTPUT IN C++ :
Introduction, Streams in C++ and Stream Classes, Pre-Defined Streams, Stream Classes, Formatted and Unformatted Data, Unformatted Console I/O Operations, Member Functions of Istream Class, Formatted Console I/O Operations, Bit Fields, Flags without Bit Filed, Manipulators, User Defined Manipulators. through C++ Unit - I the user cannot add a new format either for printf or scanf function to handle the user-defined data type. Further, the stdio.h functions are inconsistent in parameter ordering and semantics. In C++, streams with operator overloading provide a mechanism for filtering. The standard stream operators << and >> do not know anything about the user-defined data types. They can be overloaded to operate on user-defined data items. Overloaded stream operators filter the user-defined data items and transfers only basic data items to the standard stream operators. Consider the following statements to illustrate the streams capability: cout << complex1; . . cin >> complex2; The data-items complex1 and complex2 are the objects of the complex class. The operators >> or << do not know anything about the objects complex1 and complex2. These are overloaded in the complex class as member functions, which process the attributes of complex objects as basic data-items.
The C++ language offers a mechanism which permits the creation of an extensible and consistent input-output system in the form of streams library. It is a collection of classes and objects which can be used to build a powerful system, or modified and extended to handle the user-defined data types.
There are different classes for handling input and output streams, as also for streams connecting different devices to the program.
C++ streams are also treated as filters, since they have capability to change the data representation from one number system to another when requested.
Pre-defined Streams:
C++ contains several predefined streams that are opened automatically when the execution of a program starts.
The most prominent predefined streams in C++ are related to the console device.
The four standard streams : cin, cout, cerr, and clog arc automatically opened before the function main() is executed; they are closed after main() has completed.
These predefined stream objects are declared in iostream. They have the following meaning: stream description cin standard input stream (usually keyboard) corresponding to stdin in C cout standard output stream (usually screen) corresponding to stdout in C cerr standard error (output) stream (usually screen) corresponding to stderr in C clog standard logging (output) stream. A fully buffered version of cerr no C equivalent
The main advantage of using iostream.h functions over the stdio.h functions is data-independence; the freedom to write code without worrying too much about the variable types. Mixed usage of stdio and the stream class functions to perform output is not advisable. This is because they use different buffers and the order in which the output appears may not conform to the order in which the output statements appear in the program.
No comments:
Post a Comment