KEMBAR78
OOP WITH C++-ppt Slide show unitwise NOTES | PPTX
Government Arts College(Autonomous)
Salem - 636007
Re-Accredited with ‘B’ grade by NAAC
Object Oriented Programmimg with C++
Year Subject Title Sem. Sub Code
2024-2025
Onwards
OBJECT ORIENTED PROGRAMMING WITH C++ II 23UCA05
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
Constructors: Parameterized Constructors - Multiple Constructors in a class - Constructors with
default arguments - Dynamic initialization of objects - Copy and Dynamic Constructors -
Destructors
- Operator Overloading - Overloading unary and binary operators – Overloading Using Friend
functions – manipulation of Strings using Operators.
UNIT – IV
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
1. Built-in functions (C++ Library
functions)
2. User-defined functions
1. Built-in functions or C++ Library functions
Some of the built-in library functions
are
strlen(), strncpy(), strcmp()
pow(),sqrt(),sin(),tan()
getch(),clrscr(
 available in string.h
 available in math.h
 available in conio.h
2. User-definied Functions:
Function Components
• 1. Function Prototypes (or) Function Declaration
• 2. Function Definition(declarator & body)
• 3. Function call(actual parameters)
• 4. Function Parameters(formal parameters)
• 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);
 function declaration
 function call ; a & b are actual
parameters
eg.
void main()
{
int k;
int add-function(int a,int b);
…..
…..
k=add-function(int a,int b);
…..
}
 function definition ; x & y are formal
parameters
int add-function(int x,int
y)
Types of functions based on their return type & parameters
1. function that takes no parameters & doesn’t return any value
2. function that takes parameters & doesn’t return any value
3. function that takes parameters & returns a value
4. function that takes no parameters & returns a value – (rare
type)
1. function that takes no parameters & doesn’t return any
value
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
–
* formal parameters
–
used in the function call
used in function declarator
& 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.
* C++ allows function calls with fewer argument values if the
remaining arguments are assigned default values
Example:
#include<iostream.h
> #include<stdio.h>
main()
{
float amount;
float value(float p,int n,float r=15);
void printline(char ch=’*’,int len=40);
printline( );
amount=value(5000.00,5);
cout<<”n final
value=”<<amount<<endl; printline(‘=’);
//function definitions
float value (float p,int n, float r)
{
float si; si=p+
(p*n*r)/100;
return(si);
}
void printline
(char ch,int len)
{
for(inti=l;i<=len;i+
+)
cout<<ch<<endl;
}
output:-
* * * * * * * * * * * * * * *
* final value = 8750.00
const arguments
INLINE FUNCTION:
An inline function is a function that is expanded inline when it is invoked. That is
the
compiler replaces the function call with the corresponding function code.
The inline functions are defined as follows:-
inline function-header
{
function body;
}
Example:
inline int sqr(int num)
{
return(num*num);
}
Function Overloading
Scope & Extent of Variables
*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
1. Specify the class
i. Declaration of class
ii. Defintion of member functions
2. Create objects for the class
3. Access the public members of the class using objects
Specifying a class
Creating Objects
Accessing the Members of the Class
Accessing the Members
Defining Member Functions
Member function definition Outside the class specification
Access Specifiers/Visibility Modes:
C++ provides 3 types of Visibility Modes
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
3.K.R. Venugopal, Rajkumar, T. Ravishankar, “Mastering C++”, Tata McGraw-Hill
Publishing Company Limited
4. Object Oriented Programming With C++ - PowerPoint Presentation by Alok
Kumar
5. OOPs Programming Paradigm – PowerPoint Presentation by an Anonymous
Author

OOP WITH C++-ppt Slide show unitwise NOTES

  • 1.
    Government Arts College(Autonomous) Salem- 636007 Re-Accredited with ‘B’ grade by NAAC Object Oriented Programmimg with C++
  • 2.
    Year Subject TitleSem. Sub Code 2024-2025 Onwards OBJECT ORIENTED PROGRAMMING WITH C++ II 23UCA05 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
  • 3.
    UNIT – II Functionsin 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 Constructors: Parameterized Constructors - Multiple Constructors in a class - Constructors with default arguments - Dynamic initialization of objects - Copy and Dynamic Constructors - Destructors - Operator Overloading - Overloading unary and binary operators – Overloading Using Friend functions – manipulation of Strings using Operators.
  • 4.
    UNIT – IV 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.
  • 5.
    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
  • 6.
    Functions are broadlyclassified as 1. Built-in functions (C++ Library functions) 2. User-defined functions 1. Built-in functions or C++ Library functions Some of the built-in library functions are strlen(), strncpy(), strcmp() pow(),sqrt(),sin(),tan() getch(),clrscr(  available in string.h  available in math.h  available in conio.h
  • 8.
    2. User-definied Functions: FunctionComponents • 1. Function Prototypes (or) Function Declaration • 2. Function Definition(declarator & body) • 3. Function call(actual parameters) • 4. Function Parameters(formal parameters) • 5. return statement
  • 9.
    In C++, themain () 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.
  • 10.
    1. Function DeclarationSyntax 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 }
  • 14.
    3. Function call(actualparameters) Syntax function-name(actual parameters);  function declaration  function call ; a & b are actual parameters eg. void main() { int k; int add-function(int a,int b); ….. ….. k=add-function(int a,int b); ….. }  function definition ; x & y are formal parameters int add-function(int x,int y)
  • 20.
    Types of functionsbased on their return type & parameters 1. function that takes no parameters & doesn’t return any value 2. function that takes parameters & doesn’t return any value 3. function that takes parameters & returns a value 4. function that takes no parameters & returns a value – (rare type)
  • 21.
    1. function thattakes no parameters & doesn’t return any value void main() { void add(); add(); } void add(void) { int a,b,c; cin>>a>>b ; c=a+b;
  • 22.
    2. function thattakes 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 ;
  • 23.
    3. function thattakes 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)
  • 24.
    4. function thattakes 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); }
  • 25.
    Parameter Passing in Functions *actual parameters – * formal parameters – used in the function call used in function declarator & definition
  • 26.
  • 28.
  • 30.
  • 34.
  • 36.
  • 39.
  • 40.
  • 41.
    Functions with defaultarguments * Usually functions should be passed values during function call. * C++ allows function calls with fewer argument values if the remaining arguments are assigned default values
  • 42.
    Example: #include<iostream.h > #include<stdio.h> main() { float amount; floatvalue(float p,int n,float r=15); void printline(char ch=’*’,int len=40); printline( ); amount=value(5000.00,5); cout<<”n final value=”<<amount<<endl; printline(‘=’); //function definitions float value (float p,int n, float r) { float si; si=p+ (p*n*r)/100; return(si); } void printline (char ch,int len) { for(inti=l;i<=len;i+ +) cout<<ch<<endl; } output:- * * * * * * * * * * * * * * * * final value = 8750.00
  • 43.
  • 44.
    INLINE FUNCTION: An inlinefunction is a function that is expanded inline when it is invoked. That is the compiler replaces the function call with the corresponding function code. The inline functions are defined as follows:- inline function-header { function body; } Example: inline int sqr(int num) { return(num*num); }
  • 47.
  • 50.
    Scope & Extentof Variables *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
  • 51.
    Syntax of declaringvariables with storage class
  • 54.
    Recursive Functions *A functioncalling itself repeatedly until a condition is satisfied is called a recursive function
  • 55.
  • 56.
    Using Class inC++ needs 3 steps to be followed 1. Specify the class i. Declaration of class ii. Defintion of member functions 2. Create objects for the class 3. Access the public members of the class using objects
  • 57.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
    Member function definitionOutside the class specification
  • 65.
    Access Specifiers/Visibility Modes: C++provides 3 types of Visibility Modes 1. private 2. public 3. protected
  • 74.
    Two objects ofthe class student
  • 75.
    Client-Server model formessage communication
  • 76.
  • 77.
    Write a simpleprogram 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
  • 78.
  • 79.
  • 85.
    Memory allocation forstatic member
  • 88.
  • 116.
    REFERENCES: 1.E. Balagurusamy, “ObjectOriented 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 3.K.R. Venugopal, Rajkumar, T. Ravishankar, “Mastering C++”, Tata McGraw-Hill Publishing Company Limited 4. Object Oriented Programming With C++ - PowerPoint Presentation by Alok Kumar 5. OOPs Programming Paradigm – PowerPoint Presentation by an Anonymous Author