CPP PPT Best
CPP PPT Best
Coimbatore – 641018
Re-Accredited with ‘A’ grade by NAAC
Dr. S. Chitra
Associate Professor
Post Graduate & Research Department of Computer
Science Government Arts College(Autonomous)
Coimbatore – 641 018.
Year Subject Title Sem. Sub Code
2018 -19
OBJECT ORIENTED PROGRAMMING WITH C++ III 18BCS33C
Onwards
Objective:
•Learn the fundamentals of input and output using the C++ library
•Design a class that serves as a program module or package.
•Understand and demonstrate the concepts of Functions, Constructor and inheritance.
UNIT – I
Principles of Object Oriented Programming: Software Crisis - Software Evolution - Procedure
Oriented Programming - Object Oriented Programming Paradigm - Basic concepts and benefits of
OOP - Object Oriented Languages - Structure of C++ Program - Tokens, Keywords, Identifiers,
Constants, Basic data type, User-defined Data type, Derived Data type – Symbolic Constants –
Declaration of Variables – Dynamic Initialization - Reference Variable – Operators in C++ -
Scope resolution operator – Memory management Operators – Manipulators – Type Cast
operators – Expressions and their types – Conversions – Operator Precedence - Control
Structures
UNIT – II
Functions in C++: Function Prototyping - Call by reference - Return by reference - Inline functions
- Default, const arguments - Function Overloading – Classes and Objects - Member functions -
Nesting of member functions - Private member functions - Memory Allocation for Objects - Static
Data Members - Static Member functions - Array of Objects - Objects as function arguments -
Returning objects - friend functions – Const Member functions .
UNIT – III
Inheritance: Defining derived classes - Single Inheritance - Making a private member inheritable – Multilevel,
Multiple inheritance - Hierarchical inheritance - Hybrid inheritance - Virtual base classes - Abstract classes -
Constructors in derived classes - Member classes - Nesting of classes.
UNIT – V
Pointers, Virtual Functions and Polymorphism: Pointer to objects – this pointer- Pointer to derived Class -
Virtual functions – Pure Virtual Functions – C++ Streams –Unformatted I/O- Formated Console I/O – Opening
and Closing File – File modes - File pointers and their manipulations – Sequential I/O – updating a
file :Random access –Error Handling during File operations – Command line Arguments.
TEXT BOOKS
1.E. Balagurusamy, “Object Oriented Programming with C++”, Fourth edition, TMH, 2008.
Unit II – Functions
Modular Programming
“The process of splitting of a large program into small manageable tasks and designing
them independently is known as Modular Programming or Divide-&-Conquer
Technique.”
C++ Functions
• Self-contained program that performs a specific task.
• “Set of program statements that can be processed independently.”
• Like in other languages, called subroutines or procedures.
Advantages
• Elimination of redundant code
• Easier debugging
• Reduction in the Size of the code
• Leads to reusability of the code
Functions are broadly classified as
Function Components
• 5. return statement
In C++, the main () returns a value of type int to the operating system.
The functions that have a return value should use the return
statement for terminating.
The main () function in C++ is therefore defined as follows.
int main( )
{
-- -
--
- return(0)
}
Since the return type of functions is int by default, the keyword int
in the main( ) header is optional.
1. Function Declaration Syntax
return-type function-name(list of parameters with their type separated by
comma);
eg. 1. int add-function(int a,int
b); eg. 2. int largest(int a,int b,int
c);
eg. 3. double power-
function(float a, int b);
2. Function
Definition(declarator & body)
Syntax
return-type function-name(list
of parameters with their type
separated by comma)
{….
statement block;
……
return
}
3. Function call(actual parameters) Syntax
function-name(actual parameters);
eg.
void main()
{
int k;
int add-function(int a,int b); function declaration
…..
…..
k=add-function(int a,int b); function call ; a & b are actual
….. parameters
}
void main()
{
void add();
add();
}
void
add(void)
{
int a,b,c;
cin>>a>>b
; c=a+b;
2. function that takes parameters & doesn’t return any
value void main()
{
void add(int,int);
int a,b;
cin>>a>>b;
add(a,b);
}
void add(int
x,int y)
{
int c;
c=x+y;
cout<<c
;
3. function that takes parameters & returns a value
void main()
{
int add(int,int);
int a,b,c;
cin>>a>>b;
c=add(a,b);
cout<<c;
}
int add(int
x,int y)
{
int c;
c=x+y;
return(c)
4. function that takes no parameters & returns a
value void main()
{
int add();
int c;
c=add();
cout<<c;
}
int add()
{
int x,y,z;
cin>>x>>y
; z=x+y;
return(z);
}
Parameter Passing in
Functions
* actual parameters used in the function call
– used in function declarator
* formal parameters & definition
–
Passing Constant Values to Functions
Passing Variable Values to Functions
Functions with Multiple
Arguments
Memory Allocation for Functions
Parameter passing by
Parameter passing by
reference
Return by Reference
Functions with default arguments
* Usually functions should be passed values during function call.
inline function-header
{
function body;
}
Example:
*The region of source code in which the identifier is visible is called the scope of
the identifier.
* The period of time during which the memory is associated with a variable is called
the
extent of the variable.
Storage Classes
Syntax of declaring variables with storage class
Recursive Functions
*A function calling itself repeatedly until a condition is satisfied is
called a recursive function
Classes &
Objects
Using Class in C++ needs 3 steps to be followed
i. Declaration of class
ii. Defintion of member functions
1. private
2. public
3. protected
Two objects of the class student
Client-Server model for message communication
Characteristics of Member Functions:
Write a simple program using class in C++ to input subject mark and prints
it. class marks
{
private :
int roll;
int ml,m2;
public:
void getdata();
void displaydata();
};
void
marks: :getdata()
{ cout<<“enter
the roll-
no:”;cin>>roll;
cout<<”enter 1st subject
mark:”; cin>>ml;
cout<<”enter 2nd subject
mark:”; cin>>m2;
}
void marks: :displaydata()
{ cout<<“Roll No.”<<roll;
cout<<”Ist subject
void main()
{
clrscr();
marks x;
x.getdata();
x.displayda
ta();
}
Nesting of Member Functions
Memory allocation for static member
Array of objects
REFERENCES:
1.E. Balagurusamy, “Object Oriented Programming with C++”, Fourth edition, TMH,
2008.
2.LECTURE NOTES ON Object Oriented Programming Using C++ by Dr. Subasish Mohapatra,
Department of Computer Science and Application College of Engineering and Technology, Bhubaneswar
Biju Patnaik University of Technology, Odisha