SlideShare a Scribd company logo
Gaurav Saxena 
VECC
 C++ is an object oriented programming language. 
 C++ is an extension of C with a major addition of the 
class construct feature. 
 C++ is superset of C. 
 Features like classes, inheritance, function 
overloading, and operator overloading make C++ a 
truly object-oriented language. 
 OO features in C++ allow programmers to build large 
programs with clarity, extensibility and ease of 
maintenance, incorporating the spirit and efficiency of 
C.
/* Simple hello world program*/ 
# include <iostream>// This is include directive 
using namespace std; 
int main() 
{ 
cout << “Hello World!”; //C++ statement 
return 0; 
}
 Average of numbers. 
◦ It will take two numbers from the console and print the 
average of the two numbers.
 Keywords 
 Identifiers 
 Constants 
 Strings 
 Operators
 Keywords 
 Identifiers 
 Constants 
 Strings 
 Operators
 Some words are reserved for implementing the specific C+ 
+ language features. 
 asm, auto, bool, break, case, catch, char, 
class, const, const_cast, continue, 
default, delete, do, double, dynamic_cast, 
else, enum, explicit, export, extern, 
false, float, for, friend, goto, if, 
inline, int, long, mutable, namespace, new, 
operator, private, protected, public, 
register, reinterpret_cast, return, short, 
signed, sizeof, static, static_cast, 
struct, switch, template, this, throw, 
true, try, typedef, typeid, typename, 
union, unsigned, using, virtual, void, 
volatile, wchar_t, while
 Keywords 
 Identifiers 
 Constants 
 Strings 
 Operators
 Identifiers refer to the names of variables, 
functions, arrays, classes , etc. created by the 
programmer. 
 Rules for creating it. 
◦ Only alphabet characters, digits and underscore are 
permitted. 
◦ The name cannot start with digit. 
◦ Uppercase and lowercase letters are distinct. 
◦ A declared keyword cannot be used as a variable.
C++ tutorials
Type Bytes Range 
char 1 -128 to 127 
signed: -128 to 127 
unsigned: 0 to 255 
short int 2 -31768 to 32767 
signed: -32768 to 32767 
unsigned: 0 to 65535 
int 2 -32768 to 32767 
signed: -31768 to 32767 
unsigned: 0 to 65535 
long int 4 -2147483648 to 2147483647 
signed: -2147483648 to 2147483647 
unsigned: 0 to 4294967295 
float 4 3.4E-38 to 3.4E+38 
double 8 1.7E-308 to 1.7E+308 
long double 10 3.4E-4932 to 1.1E+4932
 This program will take different values from 
console and perform various mathematical 
operation on these values and print the result to 
the console.
 Structures and Classes 
◦ Basis for OOP. 
◦ Classes enable to combine data and procedures. 
 Enumerated Data Type 
◦ It provides a way to attaching names to the numbers 
◦ Increase comprehensibility of the code. 
◦ Alternative mean for creating symbolic constants 
◦ Enumerates a list of words by assigning them values 
0,1,2 and so on. 
enum shape {circle, square, triangle}; 
enum colour {red, blue=4, green=8};
 Arrays 
◦ Values of similar type stored in continuous memory 
locations. 
◦ int a[10]; char string[3]=“xyz”; 
 Functions 
◦ Set of statements to perform specific tasks 
 Pointers 
◦ Special variables to store the memory location of other 
variables. 
◦ Used in referencing memory. 
◦ Concept of constant pointer introduced in c++.
 Keywords 
 Identifiers 
 Constants 
 Strings 
 Operators
 Refer to fixed values that do not change in thw 
execution of the program. 
◦ 123 //decimal integer 
◦ 12.34 //floating point integer 
◦ 037 //octal integer 
◦ 0x2 //Hexa decimal 
◦ “C++” //string constant 
◦ ‘A’ //character constant 
◦ L’ab’ //wide-character constant
 Using the qualifier const 
◦ const float pi = 3.14; 
 Using enum 
◦ enum{x,y,z}; 
◦ enum{x=200,y=300,z=400}; 
◦ enum{off,on};
 Keywords 
 Identifiers 
 Constants 
 Strings 
 Operators
 Variables that can store non-numerical values that are 
longer than one single character are known as strings. 
 The C++ language library provides support for strings 
through the standard string class. 
// my first string 
#include <iostream> 
#include <string> 
using namespace std; 
int main () 
{ 
string mystring = "This is a string"; 
cout << mystring; 
return 0; 
}
 Keywords 
 Identifiers 
 Constants 
 Strings 
 Operators
C++ tutorials
 Constant expressions 
 Integral expressions 
 Float expressions 
 Pointer expressions 
 Relational expressions 
 Logical expressions 
 Bitwise expressions
 The if statement 
Simple if statement if…..else statement 
if(expression) 
{ 
statement 1; 
} 
statement 2; 
statement 3; 
if(expression) 
{ 
statement 1; 
} 
else 
{ 
statement 2; 
} 
statement 3;
 The switch statement 
switch(expression) 
{ 
case 1: 
statement1; 
break|continue; 
case 2: 
statement2; 
continue|break; 
. 
. 
. 
default: 
statement3; 
} 
statement4;
C++ tutorials
 The do-while statement 
do 
{ 
statement1; 
} 
while(condition); 
statement2;
 The while statement 
while(condition) 
{ 
statement1; 
} 
statement2;
 The for statement 
for (intialization;condition;increment) 
{ 
statement1; 
} 
statement2;
C++ tutorials
 A piece of code that perform specific task. 
 Introduces modularity in the code. 
 Reduces the size of program. 
 C++ has added many new features to the 
functions to make them more reliable and flexible. 
 It can be overloaded.
 Function declaration 
◦ return-type function-name (argument-list); 
◦ void show(); 
◦ float volume(int x,float y,float z); 
 Function definition 
return-type function-name(argument-list) 
{ 
statement1; 
statement2; 
} 
 Function call 
◦ function-name(argument-list); 
◦ volume(a,b,c);
 The main function 
 Returns a value of type int to the operating 
system. 
int main() 
{ 
……… 
……… 
return(0); 
}
 This program will take the values of length, 
breadth and height and prints the volume of the 
cube. It uses the function to calculate it.
 Parameter Passing 
◦ Pass by value 
◦ Pass by reference 
Reference variable Pointers 
void swap (int &a, int &b) 
{ 
int t=a; 
a=b; 
b=t; 
} 
void swap(int *a, int *b) 
{ 
int t; 
t=*a; 
*a=*b; 
*b=t; 
} 
swap(m,n); swap(&m,&n);
 Parameter passing 
◦ Return by reference 
int & max (int &x, int &x) 
{ 
if(x>y) 
return x; 
else 
return y; 
} 
max(a,b)=-1;
 C++ allows to use the same function name to 
create functions that perform a variety of different 
tasks. 
 This is know as function polymorphism in OOP. 
int add (int a, int b); //prototype 1 
int add (int a, int b, int c); //prototype 2 
double add (double x, double y);//prototype 3 
double add (int p, double q);//prototype 4 
double add (double p, int q); //prototype 5 
add(5,10);//uses prototype 1 
add(15,10.0);//uses prototype 4 
add(12.5,7.5); //uses prototype 3 
add(5,10,15); //uses prototype 2 
add(0.75,5); //uses prototype5
 Structures Revisited 
◦ Makes convenient to handle a group of logically related data 
items. 
struct student //declaration 
{ 
char name[20]; 
int roll_number; 
float total_marks; 
}; 
struct student A;// C declaration 
student A; //C++ declaration 
A.roll_number=999; 
A.total_marks=595.5; 
Final_Total=A.total_marks + 5;
 Limitations 
◦ C doesn’t allow it to be treated like built-in data types. 
struct complex{float x; float y;}; 
struct complex c1,c2,c3; 
c3=c1+c2;//Illegal in C 
◦ They do not permit data hiding.
 Can hold variables and functions as members. 
 Can also declare some of its members as 
‘private’. 
 C++ introduces another user-defined type known 
as ‘class’ to incorporate all these extensions.
 Class is a way to bind the data and procedures that 
operates on data. 
 Class declaration: 
class class_name 
{ 
private: 
variable declarations;//class 
function declarations;//members 
public: 
variable declarations;//class 
function declarations;//members 
};//Terminates with a semicolon
 Class members that have been declared as 
private can be accessed only from within the 
class. 
 Public class members can be accessed from 
outside the class also. 
 Supports data-hiding and data encapsulation 
features of OOP.
 Objects are run time instance of a class. 
 Class is a representation of the object, and Object 
is the actual run time entity which holds data and 
function that has been defined in the class. 
 Object declaration: 
class_name obj1; 
class_name obj2,obj3; 
class class_name 
{……}obj1,obj2,obj3;
 Accessing class members 
◦ Object-name.function-name(actual-arguments); 
◦ obj1.setdata(100,34.4); 
 Defining Member Functions 
◦ Outside the class definition. 
return-type class-name::function-name 
(argument declaration) 
{ 
Function body; 
} 
◦ Inside the class definition. 
Same as normal function declaration.
C++ tutorials
 Object as arrays 
class employee 
{ 
char name [30]; 
float age; 
public: 
void getdata(void); 
void putdata(void); 
}; 
employee manager[3];//array of manager 
employee worker[75];//array of worker 
Manager[i].putdata();
 This program will create an array, takes the values 
for each of the element and displays it.
 An object may be used as a function arguments.
 This program creates a ‘time’ class in hour and 
minute format. There is a function called ‘sum’ 
performs the addition of time of two object and 
assign it to the object that has called the function.
 Friend function are used in the situation where two 
classes want to share a common function. 
 Scientist and manager classes want to share the 
function incometax(). 
 C++ allows the common function to be made 
friendly with both the classes, thereby allowing the 
access to the private data of these classes. This 
function need not to be the member function of 
any of these classes.
 It is not in the scope of the class, hence it cannot 
be called using the object of any class. It can be 
invoked normally. 
 It cannot access member names directly, but with 
the help of an object. Eg obj1.x 
 It can be declare either in the public or the private 
part of a class without affecting its meaning. 
 Usually, it has the objects as arguments.
 This program declares a function ‘max’ as friend 
to two classes and demonstrate how to use them.
 In order to behave like built-in data types, the 
derived-data types such as ‘objects’ should 
automatically initialize when created and destroys 
when goes out of scope. 
 For this reason C++ introduces a special member 
functions called constructor and destructor to 
automatically initialize and destroy the objects.
 Name is same as that of class. 
 Invoked when ever an object of its associated 
class is created. 
class integer 
{ 
int m,n; 
public: 
integer(void); 
…. 
…. 
}; 
integer :: integer(void){ m=0;n=0;}
 Declared in the public section. 
 Invoked automatically when the objects are created. 
 Do not have return type. 
 Cannot be inherited. Though a derived class can call 
the base class constructor. 
 Can have default arguments. 
 Cannot be virtual. 
 We cannot refer to their addresses. 
 An object with a constructor (or destructor) cannot be 
used as a member of a union. 
 They make ‘implicit calls’ to the operators ‘new’ and 
‘delete’ when memory allocation is required.
 Parameterized Constructors 
class integer 
{ 
int m,n; 
public: 
integer(int x, int y); 
…. 
…. 
}; 
integer :: integer(int x,int y){ m=x;n=y;} 
integer num1 = integer(0,100);//explicit 
call 
int num1(0,100);//implicit call
 Multiple Constructors 
class integer 
{ 
int m,n; 
public: 
integer(void); 
integer(int x, int y); 
…. 
…. 
}; 
integer :: integer(void){ m=0;n=0;} 
integer :: integer(int x,int y){ m=x;n=y;}
 Program demonstrate the use of constructors.
 Dynamic initialization of Objects 
cin>> real>>imag; 
Obj1=complex(real,imag); 
 Copy Constructor. 
class integer 
{ 
int m,n; 
public: 
integer(integer &i){m=i.m;n=i.n;}; 
…. 
}; 
integer num1(num2);
 Is used to destroy the objects that have been 
created. 
~complex(){} 
 Never takes any arguments nor does return any 
value.
C++ tutorials
 C++ tries to make the user-defined data types 
behave in much the same way as the built-in data 
types. 
 In built-in data types we have: 
◦ c=a+b//a,b and c are of type ‘int’. 
 We can also have in C++: 
◦ object1=object2+object3; 
 C++ has the ability to provide the operators with a 
special meaning for a data type. This mechanism 
is known as operator overloading.
 return-type class-name::operator op (arglist) 
 Operator functions must be either member 
functions or friend functions. 
◦ vector operator+(vector); 
◦ vector operator-(); 
◦ friend vector operator+(vector,vector); 
◦ friend vector operator-(vector); 
◦ int operator==(vector); 
◦ friend int operator==(vector,vector);
C++ tutorials
C++ tutorials
friend void operator-(space &s); 
void operator-(space &s) 
{ 
s.x=-s.x; 
s.y=-s.y; 
s.x=-s.z; 
}
 a, b and c are objects of class ‘complex’ 
 c=a.sum(b);//functional notation, 
function ‘sum’ is member function. 
 c=sum(a,b);//functional notation, 
function ‘sum’ is friend function. 
 c=a+b; // arithmetic notation, can be 
defined in both the ways (member 
function and friend function).
 Using member functions 
complex complex::operator+(complex c) 
{ 
complex temp; 
temp.x=x+c.x; 
temp.y=y+c.y; 
return(temp); 
}
 Using friend function. 
friend complex operator+(complex, complex); 
//declaration 
complex operator+(complex a, complex b) 
{return complex ((a.x+b.x),(a.y+b.y));} 
//defination
 C++ strongly support the concept of reusability. 
 C++ classes can be reused in several ways. 
 Creating new classes by reusing the properties of 
existing once. 
 The reuse of a class that has already been tested, 
debugged and used many times can save us the 
effort of developing and testing the same again. 
 Mechanism is Inheritance. 
 Base class ---Derived class
C++ tutorials
class derived-class-name : visibility-mode base-class-name 
{………}; 
 Visibility mode is optional.(by default: private) 
 Visibility mode specifies whether the features of 
the base class are privately derived or publicly 
derived.
C++ tutorials
C++ tutorials
C++ tutorials
d.get_ab(); 
d.get_a(); 
d.show(); 
Will not work. 
void mul() void display() 
{ { 
get_ab(); show_a(); 
c=b*get_a(); cout<<“b=“<<b<<“n” 
} <<“c=”<<“nn”; 
}
 Inside the class. 
class alpha 
{ 
private://optional 
…………//visible inside this class only 
protected://visible inside this class 
…………//and its immediate derived class 
public://visible to all 
………… 
};
C++ tutorials
 Multilevel Inheritance 
class A{…}; 
Class B : public A{…}; 
Class C : public B{…}; 
 Multiple Inheritance 
class P : public M, public N{…};
C++ tutorials
Ad

More Related Content

What's hot (20)

Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
rehan16091997
 
Object-Oriented Programming Using C++
Object-Oriented Programming Using C++Object-Oriented Programming Using C++
Object-Oriented Programming Using C++
Salahaddin University-Erbil
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
Pranali Chaudhari
 
C++ oop
C++ oopC++ oop
C++ oop
Sunil OS
 
java tutorial 2
 java tutorial 2 java tutorial 2
java tutorial 2
Tushar Desarda
 
Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4
University College of Engineering Kakinada, JNTUK - Kakinada, India
 
java tutorial 3
 java tutorial 3 java tutorial 3
java tutorial 3
Tushar Desarda
 
Object Oriented Programming Short Notes for Preperation of Exams
Object Oriented Programming Short Notes for Preperation of ExamsObject Oriented Programming Short Notes for Preperation of Exams
Object Oriented Programming Short Notes for Preperation of Exams
MuhammadTalha436
 
Object Oriented Programming using C++ - Part 5
Object Oriented Programming using C++ - Part 5Object Oriented Programming using C++ - Part 5
Object Oriented Programming using C++ - Part 5
University College of Engineering Kakinada, JNTUK - Kakinada, India
 
Object Oriented Programming using C++ - Part 1
Object Oriented Programming using C++ - Part 1Object Oriented Programming using C++ - Part 1
Object Oriented Programming using C++ - Part 1
University College of Engineering Kakinada, JNTUK - Kakinada, India
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
FALLEE31188
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUAL
Prabhu D
 
Intake 38 3
Intake 38 3Intake 38 3
Intake 38 3
Mahmoud Ouf
 
Bc0037
Bc0037Bc0037
Bc0037
hayerpa
 
Inheritance
InheritanceInheritance
Inheritance
Pranali Chaudhari
 
C++ language
C++ languageC++ language
C++ language
Hamza Asif
 
C sharp chap5
C sharp chap5C sharp chap5
C sharp chap5
Mukesh Tekwani
 
classes & objects in cpp overview
classes & objects in cpp overviewclasses & objects in cpp overview
classes & objects in cpp overview
gourav kottawar
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objects
Rai University
 
C++ Object Oriented Programming
C++  Object Oriented ProgrammingC++  Object Oriented Programming
C++ Object Oriented Programming
Gamindu Udayanga
 

Viewers also liked (11)

C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
akreyi
 
Основы ооп на языке C#. Часть 2. базовый синтаксис.
Основы ооп на языке C#. Часть 2. базовый синтаксис.Основы ооп на языке C#. Часть 2. базовый синтаксис.
Основы ооп на языке C#. Часть 2. базовый синтаксис.
YakubovichDA
 
основы ооп на языке C#. часть 1. введение в программирование
основы ооп на языке C#. часть 1. введение в программированиеосновы ооп на языке C#. часть 1. введение в программирование
основы ооп на языке C#. часть 1. введение в программирование
YakubovichDA
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
kailash454
 
Web-программирование и жизнь.
Web-программирование и жизнь.Web-программирование и жизнь.
Web-программирование и жизнь.
Alex Mamonchik
 
Обобщенные классы в C#
Обобщенные классы в C#Обобщенные классы в C#
Обобщенные классы в C#
REX-MDK
 
Лекция #6. Введение в Django web-framework
Лекция #6. Введение в Django web-frameworkЛекция #6. Введение в Django web-framework
Лекция #6. Введение в Django web-framework
Яковенко Кирилл
 
Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)
mujeeb memon
 
Лекция #4. Каскадные таблицы стилей
Лекция #4. Каскадные таблицы стилейЛекция #4. Каскадные таблицы стилей
Лекция #4. Каскадные таблицы стилей
Яковенко Кирилл
 
Programming in c
Programming in cProgramming in c
Programming in c
indra Kishor
 
10 tips for learning Russian
10 tips for learning Russian10 tips for learning Russian
10 tips for learning Russian
Steve Kaufmann
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
akreyi
 
Основы ооп на языке C#. Часть 2. базовый синтаксис.
Основы ооп на языке C#. Часть 2. базовый синтаксис.Основы ооп на языке C#. Часть 2. базовый синтаксис.
Основы ооп на языке C#. Часть 2. базовый синтаксис.
YakubovichDA
 
основы ооп на языке C#. часть 1. введение в программирование
основы ооп на языке C#. часть 1. введение в программированиеосновы ооп на языке C#. часть 1. введение в программирование
основы ооп на языке C#. часть 1. введение в программирование
YakubovichDA
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
kailash454
 
Web-программирование и жизнь.
Web-программирование и жизнь.Web-программирование и жизнь.
Web-программирование и жизнь.
Alex Mamonchik
 
Обобщенные классы в C#
Обобщенные классы в C#Обобщенные классы в C#
Обобщенные классы в C#
REX-MDK
 
Лекция #6. Введение в Django web-framework
Лекция #6. Введение в Django web-frameworkЛекция #6. Введение в Django web-framework
Лекция #6. Введение в Django web-framework
Яковенко Кирилл
 
Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)
mujeeb memon
 
Лекция #4. Каскадные таблицы стилей
Лекция #4. Каскадные таблицы стилейЛекция #4. Каскадные таблицы стилей
Лекция #4. Каскадные таблицы стилей
Яковенко Кирилл
 
10 tips for learning Russian
10 tips for learning Russian10 tips for learning Russian
10 tips for learning Russian
Steve Kaufmann
 
Ad

Similar to C++ tutorials (20)

Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
WondimuBantihun1
 
Ppt of c vs c#
Ppt of c vs c#Ppt of c vs c#
Ppt of c vs c#
shubhra chauhan
 
14 operator overloading
14 operator overloading14 operator overloading
14 operator overloading
Docent Education
 
C++ theory
C++ theoryC++ theory
C++ theory
Shyam Khant
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
1HK19CS090MOHAMMEDSA
 
22 scheme OOPs with C++ BCS306B_module2.pdfmodule2.pdf
22 scheme  OOPs with C++ BCS306B_module2.pdfmodule2.pdf22 scheme  OOPs with C++ BCS306B_module2.pdfmodule2.pdf
22 scheme OOPs with C++ BCS306B_module2.pdfmodule2.pdf
sindhus795217
 
Nitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptxNitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptx
shivam460694
 
C#2
C#2C#2
C#2
Sudhriti Gupta
 
C++ Interview Questions and Answers PDF By ScholarHat
C++ Interview Questions and Answers PDF By ScholarHatC++ Interview Questions and Answers PDF By ScholarHat
C++ Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
PriyadarshiniS28
 
C++ tutorial assignment - 23MTS5730.pptx
C++ tutorial assignment  - 23MTS5730.pptxC++ tutorial assignment  - 23MTS5730.pptx
C++ tutorial assignment - 23MTS5730.pptx
sp1312004
 
C Programming - Basics of c -history of c
C Programming - Basics of c -history of cC Programming - Basics of c -history of c
C Programming - Basics of c -history of c
DHIVYAB17
 
Object Oriented Programming (OOP) using C++ - Lecture 1
Object Oriented Programming (OOP) using C++ - Lecture 1Object Oriented Programming (OOP) using C++ - Lecture 1
Object Oriented Programming (OOP) using C++ - Lecture 1
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
UNIT - 1- Ood ddnwkjfnewcsdkjnjkfnskfn.pptx
UNIT - 1-  Ood ddnwkjfnewcsdkjnjkfnskfn.pptxUNIT - 1-  Ood ddnwkjfnewcsdkjnjkfnskfn.pptx
UNIT - 1- Ood ddnwkjfnewcsdkjnjkfnskfn.pptx
crazysamarth927
 
Basics _of_Operator Overloading_Somesh_Kumar_SSTC
Basics _of_Operator Overloading_Somesh_Kumar_SSTCBasics _of_Operator Overloading_Somesh_Kumar_SSTC
Basics _of_Operator Overloading_Somesh_Kumar_SSTC
drsomeshdewangan
 
PRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptxPRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptx
SajalKesharwani2
 
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxINTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
DeepasCSE
 
introductory concepts
introductory conceptsintroductory concepts
introductory concepts
Walepak Ubi
 
Object Oriented Programming using C++ Unit 1
Object Oriented Programming using C++ Unit 1Object Oriented Programming using C++ Unit 1
Object Oriented Programming using C++ Unit 1
NageshPratapSingh2
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
HCMUTE
 
22 scheme OOPs with C++ BCS306B_module2.pdfmodule2.pdf
22 scheme  OOPs with C++ BCS306B_module2.pdfmodule2.pdf22 scheme  OOPs with C++ BCS306B_module2.pdfmodule2.pdf
22 scheme OOPs with C++ BCS306B_module2.pdfmodule2.pdf
sindhus795217
 
Nitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptxNitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptx
shivam460694
 
C++ Interview Questions and Answers PDF By ScholarHat
C++ Interview Questions and Answers PDF By ScholarHatC++ Interview Questions and Answers PDF By ScholarHat
C++ Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
C++ tutorial assignment - 23MTS5730.pptx
C++ tutorial assignment  - 23MTS5730.pptxC++ tutorial assignment  - 23MTS5730.pptx
C++ tutorial assignment - 23MTS5730.pptx
sp1312004
 
C Programming - Basics of c -history of c
C Programming - Basics of c -history of cC Programming - Basics of c -history of c
C Programming - Basics of c -history of c
DHIVYAB17
 
UNIT - 1- Ood ddnwkjfnewcsdkjnjkfnskfn.pptx
UNIT - 1-  Ood ddnwkjfnewcsdkjnjkfnskfn.pptxUNIT - 1-  Ood ddnwkjfnewcsdkjnjkfnskfn.pptx
UNIT - 1- Ood ddnwkjfnewcsdkjnjkfnskfn.pptx
crazysamarth927
 
Basics _of_Operator Overloading_Somesh_Kumar_SSTC
Basics _of_Operator Overloading_Somesh_Kumar_SSTCBasics _of_Operator Overloading_Somesh_Kumar_SSTC
Basics _of_Operator Overloading_Somesh_Kumar_SSTC
drsomeshdewangan
 
PRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptxPRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptx
SajalKesharwani2
 
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxINTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
DeepasCSE
 
introductory concepts
introductory conceptsintroductory concepts
introductory concepts
Walepak Ubi
 
Object Oriented Programming using C++ Unit 1
Object Oriented Programming using C++ Unit 1Object Oriented Programming using C++ Unit 1
Object Oriented Programming using C++ Unit 1
NageshPratapSingh2
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
HCMUTE
 
Ad

Recently uploaded (20)

Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 

C++ tutorials

  • 2.  C++ is an object oriented programming language.  C++ is an extension of C with a major addition of the class construct feature.  C++ is superset of C.  Features like classes, inheritance, function overloading, and operator overloading make C++ a truly object-oriented language.  OO features in C++ allow programmers to build large programs with clarity, extensibility and ease of maintenance, incorporating the spirit and efficiency of C.
  • 3. /* Simple hello world program*/ # include <iostream>// This is include directive using namespace std; int main() { cout << “Hello World!”; //C++ statement return 0; }
  • 4.  Average of numbers. ◦ It will take two numbers from the console and print the average of the two numbers.
  • 5.  Keywords  Identifiers  Constants  Strings  Operators
  • 6.  Keywords  Identifiers  Constants  Strings  Operators
  • 7.  Some words are reserved for implementing the specific C+ + language features.  asm, auto, bool, break, case, catch, char, class, const, const_cast, continue, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, operator, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_cast, struct, switch, template, this, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while
  • 8.  Keywords  Identifiers  Constants  Strings  Operators
  • 9.  Identifiers refer to the names of variables, functions, arrays, classes , etc. created by the programmer.  Rules for creating it. ◦ Only alphabet characters, digits and underscore are permitted. ◦ The name cannot start with digit. ◦ Uppercase and lowercase letters are distinct. ◦ A declared keyword cannot be used as a variable.
  • 11. Type Bytes Range char 1 -128 to 127 signed: -128 to 127 unsigned: 0 to 255 short int 2 -31768 to 32767 signed: -32768 to 32767 unsigned: 0 to 65535 int 2 -32768 to 32767 signed: -31768 to 32767 unsigned: 0 to 65535 long int 4 -2147483648 to 2147483647 signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 float 4 3.4E-38 to 3.4E+38 double 8 1.7E-308 to 1.7E+308 long double 10 3.4E-4932 to 1.1E+4932
  • 12.  This program will take different values from console and perform various mathematical operation on these values and print the result to the console.
  • 13.  Structures and Classes ◦ Basis for OOP. ◦ Classes enable to combine data and procedures.  Enumerated Data Type ◦ It provides a way to attaching names to the numbers ◦ Increase comprehensibility of the code. ◦ Alternative mean for creating symbolic constants ◦ Enumerates a list of words by assigning them values 0,1,2 and so on. enum shape {circle, square, triangle}; enum colour {red, blue=4, green=8};
  • 14.  Arrays ◦ Values of similar type stored in continuous memory locations. ◦ int a[10]; char string[3]=“xyz”;  Functions ◦ Set of statements to perform specific tasks  Pointers ◦ Special variables to store the memory location of other variables. ◦ Used in referencing memory. ◦ Concept of constant pointer introduced in c++.
  • 15.  Keywords  Identifiers  Constants  Strings  Operators
  • 16.  Refer to fixed values that do not change in thw execution of the program. ◦ 123 //decimal integer ◦ 12.34 //floating point integer ◦ 037 //octal integer ◦ 0x2 //Hexa decimal ◦ “C++” //string constant ◦ ‘A’ //character constant ◦ L’ab’ //wide-character constant
  • 17.  Using the qualifier const ◦ const float pi = 3.14;  Using enum ◦ enum{x,y,z}; ◦ enum{x=200,y=300,z=400}; ◦ enum{off,on};
  • 18.  Keywords  Identifiers  Constants  Strings  Operators
  • 19.  Variables that can store non-numerical values that are longer than one single character are known as strings.  The C++ language library provides support for strings through the standard string class. // my first string #include <iostream> #include <string> using namespace std; int main () { string mystring = "This is a string"; cout << mystring; return 0; }
  • 20.  Keywords  Identifiers  Constants  Strings  Operators
  • 22.  Constant expressions  Integral expressions  Float expressions  Pointer expressions  Relational expressions  Logical expressions  Bitwise expressions
  • 23.  The if statement Simple if statement if…..else statement if(expression) { statement 1; } statement 2; statement 3; if(expression) { statement 1; } else { statement 2; } statement 3;
  • 24.  The switch statement switch(expression) { case 1: statement1; break|continue; case 2: statement2; continue|break; . . . default: statement3; } statement4;
  • 26.  The do-while statement do { statement1; } while(condition); statement2;
  • 27.  The while statement while(condition) { statement1; } statement2;
  • 28.  The for statement for (intialization;condition;increment) { statement1; } statement2;
  • 30.  A piece of code that perform specific task.  Introduces modularity in the code.  Reduces the size of program.  C++ has added many new features to the functions to make them more reliable and flexible.  It can be overloaded.
  • 31.  Function declaration ◦ return-type function-name (argument-list); ◦ void show(); ◦ float volume(int x,float y,float z);  Function definition return-type function-name(argument-list) { statement1; statement2; }  Function call ◦ function-name(argument-list); ◦ volume(a,b,c);
  • 32.  The main function  Returns a value of type int to the operating system. int main() { ……… ……… return(0); }
  • 33.  This program will take the values of length, breadth and height and prints the volume of the cube. It uses the function to calculate it.
  • 34.  Parameter Passing ◦ Pass by value ◦ Pass by reference Reference variable Pointers void swap (int &a, int &b) { int t=a; a=b; b=t; } void swap(int *a, int *b) { int t; t=*a; *a=*b; *b=t; } swap(m,n); swap(&m,&n);
  • 35.  Parameter passing ◦ Return by reference int & max (int &x, int &x) { if(x>y) return x; else return y; } max(a,b)=-1;
  • 36.  C++ allows to use the same function name to create functions that perform a variety of different tasks.  This is know as function polymorphism in OOP. int add (int a, int b); //prototype 1 int add (int a, int b, int c); //prototype 2 double add (double x, double y);//prototype 3 double add (int p, double q);//prototype 4 double add (double p, int q); //prototype 5 add(5,10);//uses prototype 1 add(15,10.0);//uses prototype 4 add(12.5,7.5); //uses prototype 3 add(5,10,15); //uses prototype 2 add(0.75,5); //uses prototype5
  • 37.  Structures Revisited ◦ Makes convenient to handle a group of logically related data items. struct student //declaration { char name[20]; int roll_number; float total_marks; }; struct student A;// C declaration student A; //C++ declaration A.roll_number=999; A.total_marks=595.5; Final_Total=A.total_marks + 5;
  • 38.  Limitations ◦ C doesn’t allow it to be treated like built-in data types. struct complex{float x; float y;}; struct complex c1,c2,c3; c3=c1+c2;//Illegal in C ◦ They do not permit data hiding.
  • 39.  Can hold variables and functions as members.  Can also declare some of its members as ‘private’.  C++ introduces another user-defined type known as ‘class’ to incorporate all these extensions.
  • 40.  Class is a way to bind the data and procedures that operates on data.  Class declaration: class class_name { private: variable declarations;//class function declarations;//members public: variable declarations;//class function declarations;//members };//Terminates with a semicolon
  • 41.  Class members that have been declared as private can be accessed only from within the class.  Public class members can be accessed from outside the class also.  Supports data-hiding and data encapsulation features of OOP.
  • 42.  Objects are run time instance of a class.  Class is a representation of the object, and Object is the actual run time entity which holds data and function that has been defined in the class.  Object declaration: class_name obj1; class_name obj2,obj3; class class_name {……}obj1,obj2,obj3;
  • 43.  Accessing class members ◦ Object-name.function-name(actual-arguments); ◦ obj1.setdata(100,34.4);  Defining Member Functions ◦ Outside the class definition. return-type class-name::function-name (argument declaration) { Function body; } ◦ Inside the class definition. Same as normal function declaration.
  • 45.  Object as arrays class employee { char name [30]; float age; public: void getdata(void); void putdata(void); }; employee manager[3];//array of manager employee worker[75];//array of worker Manager[i].putdata();
  • 46.  This program will create an array, takes the values for each of the element and displays it.
  • 47.  An object may be used as a function arguments.
  • 48.  This program creates a ‘time’ class in hour and minute format. There is a function called ‘sum’ performs the addition of time of two object and assign it to the object that has called the function.
  • 49.  Friend function are used in the situation where two classes want to share a common function.  Scientist and manager classes want to share the function incometax().  C++ allows the common function to be made friendly with both the classes, thereby allowing the access to the private data of these classes. This function need not to be the member function of any of these classes.
  • 50.  It is not in the scope of the class, hence it cannot be called using the object of any class. It can be invoked normally.  It cannot access member names directly, but with the help of an object. Eg obj1.x  It can be declare either in the public or the private part of a class without affecting its meaning.  Usually, it has the objects as arguments.
  • 51.  This program declares a function ‘max’ as friend to two classes and demonstrate how to use them.
  • 52.  In order to behave like built-in data types, the derived-data types such as ‘objects’ should automatically initialize when created and destroys when goes out of scope.  For this reason C++ introduces a special member functions called constructor and destructor to automatically initialize and destroy the objects.
  • 53.  Name is same as that of class.  Invoked when ever an object of its associated class is created. class integer { int m,n; public: integer(void); …. …. }; integer :: integer(void){ m=0;n=0;}
  • 54.  Declared in the public section.  Invoked automatically when the objects are created.  Do not have return type.  Cannot be inherited. Though a derived class can call the base class constructor.  Can have default arguments.  Cannot be virtual.  We cannot refer to their addresses.  An object with a constructor (or destructor) cannot be used as a member of a union.  They make ‘implicit calls’ to the operators ‘new’ and ‘delete’ when memory allocation is required.
  • 55.  Parameterized Constructors class integer { int m,n; public: integer(int x, int y); …. …. }; integer :: integer(int x,int y){ m=x;n=y;} integer num1 = integer(0,100);//explicit call int num1(0,100);//implicit call
  • 56.  Multiple Constructors class integer { int m,n; public: integer(void); integer(int x, int y); …. …. }; integer :: integer(void){ m=0;n=0;} integer :: integer(int x,int y){ m=x;n=y;}
  • 57.  Program demonstrate the use of constructors.
  • 58.  Dynamic initialization of Objects cin>> real>>imag; Obj1=complex(real,imag);  Copy Constructor. class integer { int m,n; public: integer(integer &i){m=i.m;n=i.n;}; …. }; integer num1(num2);
  • 59.  Is used to destroy the objects that have been created. ~complex(){}  Never takes any arguments nor does return any value.
  • 61.  C++ tries to make the user-defined data types behave in much the same way as the built-in data types.  In built-in data types we have: ◦ c=a+b//a,b and c are of type ‘int’.  We can also have in C++: ◦ object1=object2+object3;  C++ has the ability to provide the operators with a special meaning for a data type. This mechanism is known as operator overloading.
  • 62.  return-type class-name::operator op (arglist)  Operator functions must be either member functions or friend functions. ◦ vector operator+(vector); ◦ vector operator-(); ◦ friend vector operator+(vector,vector); ◦ friend vector operator-(vector); ◦ int operator==(vector); ◦ friend int operator==(vector,vector);
  • 65. friend void operator-(space &s); void operator-(space &s) { s.x=-s.x; s.y=-s.y; s.x=-s.z; }
  • 66.  a, b and c are objects of class ‘complex’  c=a.sum(b);//functional notation, function ‘sum’ is member function.  c=sum(a,b);//functional notation, function ‘sum’ is friend function.  c=a+b; // arithmetic notation, can be defined in both the ways (member function and friend function).
  • 67.  Using member functions complex complex::operator+(complex c) { complex temp; temp.x=x+c.x; temp.y=y+c.y; return(temp); }
  • 68.  Using friend function. friend complex operator+(complex, complex); //declaration complex operator+(complex a, complex b) {return complex ((a.x+b.x),(a.y+b.y));} //defination
  • 69.  C++ strongly support the concept of reusability.  C++ classes can be reused in several ways.  Creating new classes by reusing the properties of existing once.  The reuse of a class that has already been tested, debugged and used many times can save us the effort of developing and testing the same again.  Mechanism is Inheritance.  Base class ---Derived class
  • 71. class derived-class-name : visibility-mode base-class-name {………};  Visibility mode is optional.(by default: private)  Visibility mode specifies whether the features of the base class are privately derived or publicly derived.
  • 75. d.get_ab(); d.get_a(); d.show(); Will not work. void mul() void display() { { get_ab(); show_a(); c=b*get_a(); cout<<“b=“<<b<<“n” } <<“c=”<<“nn”; }
  • 76.  Inside the class. class alpha { private://optional …………//visible inside this class only protected://visible inside this class …………//and its immediate derived class public://visible to all ………… };
  • 78.  Multilevel Inheritance class A{…}; Class B : public A{…}; Class C : public B{…};  Multiple Inheritance class P : public M, public N{…};