CLASS:BCA 2ndSem
Batch: 2019-22
Object Oriented Programming Language Using C++
Notes as per IKGPTU Syllabus
Name of Faculty: Mr/Ms<<<<<Jatinderpal kaur>>>
Faculty of Computer Applictions,SBS College. Ludhiana
Detailed Contents | Page No. |
Unit-I
Principles of object oriented programming Introduction to OOP and its basic features, Basic components of a C++, Program and program structure, Compiling and Executing C++ Program. Difference between Procedure Oriented Language(C) and Object Oriented Language |
1-20 |
Unit-II
Classes & Objects and Concept of Constructors Defining classes, Defining member functions, Declaration of objects to class, Access to member variables from objects, Different forms of member functions, Access specifiers (Private, public, protected), Array of objects.
Introduction to constructors, Parameterized constructors, Copy Constructor, Multiple constructors in class, Dynamic initialization of objects, Destructors. |
20-35 |
Unit-III
Inheritance and Operator overloading |
35-70 |
Introduction to Inheritance, Types of inheritance: – Single inheritance, Multiple inheritance, Multilevel inheritance, Hierarchical inheritance, Hybrid inheritance, Defining operator overloading, Overloading of Unary and Binary operators, Rules for overloading operators | |
Unit-IV
Polymorphism and File Handling Early Binding, Late Binding, Virtual Functions, pure virtual functions, Abstract Classes.
Opening and Closing File, Reading and Writing a file. |
70-96 |
Unit-1
Object-Oriented Programming approach
Object-Oriented Programming (OOPS) is the term used to describe a programming approach based on objects and classes. The object-oriented paradigm allows us to organize software as a collection of objects that consist of both data and behavior. This is in contrast to conventional functional programming practice that only loosely connects data and behavior.
Since the 1980s the word ‘object’ has appeared in relation to programming languages, with almost all languages developed since 1990 having object-oriented features. Some languages have even had object-oriented features retro-fitted. It is widely accepted that object-oriented programming is the most important and powerful way of creating software.
The object-oriented programming approach encourages:
- Modularization: where the application can be decomposed into modules.
- Software re-use: where an application can be composed from existing and new modules.
.
Difference between object oriented approach and procedure oriented approach
OOPS |
POP
|
OOP takes a bottom-up approach in designing a program. |
POP follows a top-down approach |
Program is divided into objects depending on the problem. | Program is divided into small chunks based on the functions.
|
Each object controls its own data. |
Each function contains different data.
|
Focuses on security of the data irrespective of the algorithm.
|
Follows a systematic approach to solve the problem.
|
The main priority is data rather than functions in a program.
|
Functions are more important than data in a program.
|
The functions of the objects are linked via message passing. |
Different parts of a program are interconnected via parameter passing.
|
Data hiding is possible in OOPS. |
No easy way for data hiding.
|
Inheritance is allowed in OOPS. | No such concept of inheritance in POP.
|
Operator overloading is allowed. | Operator overloading is not allowed.
|
Characteristics(Basic Concept) of object oriented languages
1)Class
A class in C++ is a user defined type or data structure declared with keyword class that has data and functions (also called methods) as its members whose access is governed by the three access specifiers private, protected or public (by default access to members of a class is private).
2) Object
An Object is an instance of a Class. When a class is defined, no memory is allocated but when it is instantiated (i.e. an object is created) memory is allocated. An object has two parts, one is a data that it remembers and the second one is the action that it can perform.
3) Inheritance
Inheritance is an OOPS concept in which one object acquires the properties and behaviors of the parent object
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.
4) Polymorphism(one thing with many meaning ):
C++ polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function. Polymorphism is considered as one of the important features of Object Oriented Programming. In C++ polymorphism is mainly divided into two types:
Compile time Polymorphism
Runtime Polymorphism
5) Abstraction
An abstraction is an act of representing essential features without including background details. It is a technique of creating a new data type that is suited for a specific application. For example, while driving a car, you do not have to be concerned with its internal working. In C++, classes provide great level of data abstraction. They provide sufficient public methods to the outside world to play with the functionality of the object and to manipulate object data, i.e., state without actually knowing how class has been implemented internally.
6) Encapsulation
Encapsulation is an OOP technique of wrapping the data and code. In this OOPS concept, the variables of a class are always hidden from other classes. It can only be accessed using the methods of their current class. For example – in school, a student cannot exist without a class. Encapsulation is a process of combining data members and functions in a single unit called class.
7)Dynamic Binding: In dynamic binding, the code to be executed in response to function call is decided at runtime. C++ has virtual functions to support this. Describe static and dynamic binding of functions. Dynamic Binding : C++ provides facility to specify that the compiler should match function calls with the correct definition at the run time; this is called dynamic binding or late binding or run-time binding.
8)Message Passing: Objects communicate with one another by sending and receiving information to each other. 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 results.
Difference between C and C++
C | C++ |
C was developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs. | C++ was developed by Bjarne Stroustrup in 1979 with C++’s predecessor “C with Classes”. |
When compared to C++, C is a subset of C++. | C++ is a superset of C. C++ can run most of C code while C cannot run C++ code. |
C supports procedural programming paradigm for code development. | C++ supports both procedural and object oriented programming paradigms; therefore C++ is also called a hybrid language. |
C does not support object oriented programming; therefore it has no support for polymorphism, encapsulation, and inheritance. | Being an object oriented programming language C++ supports polymorphism, encapsulation, and inheritance. |
In C (because it is a procedural programming language), data and functions are separate and free entities. | In C++ (when it is used as object oriented programming language), data and functions are encapsulated together in form of an object. For creating objects class provides a blueprint of structure of the object. |
In C, data are free entities and can be manipulated by outside code. This is because C does not support information hiding. | In C++, Encapsulation hides the data to ensure that data structures and operators are used as intended. |
C, being a procedural programming, it is a function driven language. | While, C++, being an object oriented programming, it is an object driven language. |
C does not support function and operator overloading. | C++ supports both function and operator overloading. |
C does not allow functions to be defined inside structures. | In C++, functions can be used inside a structure. |
C does not have namespace feature. | C++ uses NAMESPACE which avoid name collisions. |
C uses functions for input/output. For example scanf and printf. | C++ uses objects for input output. For example cin and cout. |
C does not support reference variables. | C++ supports reference variables. |
C has no support for virtual and friend functions. | C++ supports virtual and friend functions. |
C provides malloc() and calloc() functions for dynamic memory allocation, and free()for memory de-allocation. | C++ provides new operator for memory allocation and deleteoperator for memory de-allocation. |
C does not provide direct support for error handling (also called exception handling) | C++ provides support for exception handling. Exceptions are used for “hard” errors that make the code incorrect. |
Header file #include<stdio.h> | #include<iostream.h> |
Basic Structure of C++
- Documentation Section-we have the name of program ,it is hide from the compiler ,this section write with in comments.
For example
/* write a program display message */
- include header files Section -for include header file we have use preprocessor that is #include< > ,we have <iostream> header file for cpp code
For example
#include<iostream.h> or #include”iostream”
- main function Section-it is tells the compiler from where program execution is started.
For example
int main()
- opening brace ( { ): we have start the code writing from the opening
- Executable statement-executable statements are used to perform some task ,every statement should be ends with semi colon (;)
For example
cout<< ” hello guys how r u?”;
cout-this function is used to display message.
6.closing brace ( } )-this is used to end programming code .
For example
/* write a program to display message */
#include<iostream>
using namespace std;
int main()
{
cout<<”hello guys how r u?”;
}
Then save it (hello.cpp)
Compile it
Run it to show the program output
/*write a program to find sum of two numbers*/
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
a=2;
b=10;
c=a+b;
cout<<“sum is”<<c;
}
Note : you can use any C/C++ editor like(DEV C++, Turbo C++,Code Block and many more) and also use Online C++ Compiler.
Describe the steps in compiling and executing a C++
Compiling and Linking
During compilation, if there are any errors that will be listing by the compiler. The errors may be any
one of the following
1.Syntax error
This error occurs due to mistake in writing the syntax of a c++ statement or wrong use of
reserved words, improper variable names, using variables without declaration etc. Examples are :
missing semi colon or paranthesis, type integer for int datatype etc.
- Logical error
This error occurs due to the flaw in the logic. This will not be identified by the compiler.
However it can be traced using the debug tool in the editor. First identify the variable which you
- Linker error
This error occur when the files during linking are missing or misspell
- Runtime error
This error occurs if the program encounters division by zero, accessing a null pointer etc during execution of the program.
Course Features
- Lectures 0
- Quizzes 0
- Skill level All levels
- Students 7
- Assessments Self