0% found this document useful (0 votes)
147 views32 pages

Object Oriented Programming in C++: Guru Nanak Dev Engg College

The document is a practical file for Object Oriented Programming in C++. It contains programs to demonstrate various concepts in C++ like data types, operators, control structures like if-else, switch, loops, functions, arrays and strings. For each concept, it provides the code snippet and corresponding output. There are a total of 19 programs covering key topics in OOP using C++.

Uploaded by

Kumar Ravi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views32 pages

Object Oriented Programming in C++: Guru Nanak Dev Engg College

The document is a practical file for Object Oriented Programming in C++. It contains programs to demonstrate various concepts in C++ like data types, operators, control structures like if-else, switch, loops, functions, arrays and strings. For each concept, it provides the code snippet and corresponding output. There are a total of 19 programs covering key topics in OOP using C++.

Uploaded by

Kumar Ravi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

GURU NANAK DEV ENGG COLLEGE

PRACTICAL FILE

Object Oriented
Programming in C++

c
Dev kumar
URN=2004902
CRN=2021024
D2-ITA1
Contents

1 Program to print name in C++ 1


1.1 Cod e to print name: . 1
1.1.1 Output: 1

2 Program to print size of data types in C++ 1


2.1 Code to print size of data types: . 1
2.1.1 Output: . . . . . . . . . . 1

3 Program to print different types of data types in C++ 2


3.1 Cod e for data types 2
3.1.1 Output: . . . . . 2

4 Program to print different types of operators in C++ 2


4.1 Cod e for A r ith met ic op e rat o rs 2
4.1.1 Output: . . . . . 3

4.2 Cod e for Logi cal o pe ra to r s 3


4.2.1 Output: . . . . . 4

4.3 Cod e for A s si gn me nt o pe r ato r s 4


4.3.1 Output: . . . . . 5

4.4 Cod e for B itw is e ope ra to r s 5


4.4.1 Output: . . . . . 5

4.5 Cod e for U na ry o pe rat o rs 6


4.5.1 Output: . . . . . 6

5 Program for showing Operator precedence in C++ 6


5.1 Cod e for o pe rat o r p rece denc e 7
5.1.1 Output: . . . . . 7

6 Program for showing Typecasting in C++ 7


6.1 Cod e for Implicit typecasting 8
6.1.1 Output: . . . . . 8

6.2 Cod e for Explicit typecasting 8


6.2.1 Output: . . . . . 9
7 Program for printing If-Else statements in C++ 9
7.1 Cod e for If -el se sta men t s 10
7.1.1 Output: . . . . . 10

8 Program for printing If-Else ladder in C++ 10


8.1 Cod e for If -el se l ad der 10
8.1.1 Output: . . . . . 10

9 Program for printing nested If-Else in C++ 11


9.1 Cod e for nested If -el se 11
8.1.1 Output: . . . . . 11

10 Program for printing Switch statements in C++ 12


10.1 Cod e for s wi tch sta teme nt s 12
10.1.1 Output: . . . . . 12

11 Program for printing Loops in C++ 13


11.1 Cod e for D o -w hile lo op 13
11.1.1 Output: . . . . . 13

11.2 Cod e for Wh i le l oo p 17


11.2.1 Output: . . . . . 17

11.3 Cod e for For Lo op 17


11.3.1 Output: . . . . . 18

12 Program for printing Break statements in C++ 18


12.1 Cod e for b re ak s tate me nt s 16
12.1.1 Output: . . . . .

13 Program for printing Continue statement in C++ 16


13.1 Cod e for co nti nue st ate me nt s 16
13.1.1 Output: . . . . .

14 Program for printing Functions in C++ 17


14.1 Cod e for Call by value 17
14.1.1 Output: . . . . .

14.2 Cod e for Call by Reference 18


14.2.1 Output: . . . . . 18
15 Program for conversion from Octal to decimal in C++ 19
15.1 Cod e for co nti nue st ate me nt s 19
15.1.1 Output: . . . . . 20

16 Program for conversion from Binary to decimal in C++ 20


16.1 Cod e for co nti nue st ate me nt s 21
16.1.1 Output: . . . . . 21

17 Program for Arrays statement in C++ 22


17.1 Cod e for p ri nti ng a r r ay s 22
17.1.1 Output: . . . . . 23

17.2 Cod e for m ult ipl icat ion s o f ma t rice s 24


17.2.1 Output: . . . . . 24

18 Program for Strings statement in C++ 24


18.1 Cod e for p ri nti ng st ring 25
18.1.1 Output: . . . . . 25

18.2 Cod e for finding vowel in a string 26


18.2.1 Output: . . . . . 26

18.3 Cod e for finding palindrome 26


18.3.1 Output: . . . . . 26

18.4 Cod e for finding reverse a string 27


18.4.1 Output: . . . . . 27

18.5 Cod e for printing all duplicate elements 28


18.5.1 Output: . . . . . 28

19 Program printing Constructures and destructures in C++ 29


19.1 Cod e for co n st ruc tu res an d de st r uctu r s 29
19.1.1 Output: . . . . .
OOPs practical GNDEC

1 .Program to print name in C++ :


1.1 Code to print name:
#include<iostream>
using namespace std;
int main()
{
cout << "My name is Dev kumar."<< "\n";
return 0;
}

1.1.1 Output
My name is Dev kumar.

2. Program to print size of Data Types in C++:


1.2 Code to print size of data types:
#include <iostream>
using namespace std;
int main()
{
cout << "Size of int is " << sizeof(int) << endl;
cout << "Size of char is " << sizeof(char) << endl;
cout << "Size of float is " << sizeof(float) << endl;
cout << "Size of double is " << sizeof(double) << endl;
return 0;
}

1.2.1 Output :
Size of int is 4
Size of char is 1
Size of float is 4
Size of double is 8

Dev kumar Page 1


OOPs practical GNDEC
3. Program to print different types of Data types in
C++
3.1 Code for data types:
#include <iostream>
using namespace std;
int main()
{
int a = 6;
float f = 0.43;
double d = 22.432;
char c = 'x';
cout << "Value of a = " << a << endl;
cout << "Value of f = " << f << endl;
cout << "Value of d = " << d << endl;
cout << "Value of c = " << c << endl;
return 0;
}

3.1.1 Output:
Value of a = 6
Value of f = 0.43
Value of d = 22.432
Value of c = x
4 Different types of Operators in C++:
OPERATORS = Operators are symbols used in any language that
tells compiler to do different arithmetic, logical operations etc. on
operands , There are different types of operators used in C/C++.

4.1 ARITHMETIC OPERATORS : These operators are


used to do different mathematical and arithmetic
operation on the operands.

Dev kumar Page 2


OOPs practical GNDEC
4.1.1 Code for arithmetic operators:
#include <iostream>
using namespace std;
int main()
{
int S_I;
float principle = 10000, rate = 0.35, t = 5;

S_I = (principle * rate * t) / 100;


cout << "Simple Interest = " << S_I;
return 0;
}

4.1.1.1 Output :
Simple Interest = 174

4.2 LOGICAL OPERATORS :The logical operators return TRUE or


FALSE, which are defined as 1 and 0, respectively, depending on the
relationship between the parameters

4.2.1 Code:
#include <iostream>
using namespace std;
int main()
{
int num;
cout << "Enter your choice = ";
cin >> num;
if ((num >= 35) && (num <= 100))
cout << "You have passed the exam.";
else
cout << "Don't get demotived , Try your best next time ";
return 0;
}

4.2.1.1: Output
Enter your choice = 100 You have passed the exam.
Dev kumar Page 3
OOPs practical GNDEC
PS C:\Users\Dev
kumar\OneDrive\Desktop\Hackerrank_problem_solving> g++
a.cpp
PS C:\Users\Dev
kumar\OneDrive\Desktop\Hackerrank_problem_solving>
.\a.exe
Enter your choice = 20
Don't get demotived , Try your best next time

4.3 Assignment operators: Assignment operators are


used to assign value to a variable. The left side operand of the
assignment operator is a 3 variable and right-side operand
of the assignment operator is a value.

4.3.1 Code:
#include <iostream>
using namespace std;
int main()
{
int s = 10, b;
b = s;
b += s;
cout << "value of b is " << b << endl;
b /= s;
cout << "value of b is " << b << endl;
return 0;
}

Output :
value of b is 20
value of b is 2

4.4 Bitwise operators: Bitwise operators is used to


Dev kumar Page 4
OOPs practical GNDEC
perform bit- level operations on the operands. The
operators are 1st converted into bits and then
calculations are performed.They are of many types.
4.4.1 Code:
// Bitwise operators
#include <iostream>
using namespace std;
int main()
{
int a = 1, b = 2;
cout << " a = " << a << " , " << " b = " << b << endl;

cout << " a & b = " << (a & b) << endl;


cout << " a | b = " << (a | b) << endl;
cout << " a ^ b = " << (a ^ b) << endl;
cout << " b << 1 = " << (b << 1) << endl;
cout << " b >> 1 = " << (b >> 1) << endl;

return 0;
}

4.4.1.1Output:
a = 1 , b = 2
a & b = 0
a | b = 3
a ^ b = 3
b << 1 = 4
b >> 1 = 1

4.5 Unary Opreators: These operators act on a single


operands, Eg: ++, --, !, sizeof().
4.5.1 Code for Unary operators
#include <iostream>
using namespace std;
int main()
Dev kumar Page 5
OOPs practical GNDEC
{
int a = 10, b = 20;
++a, ++b;
cout << " a = " << a << endl << " b = " << b;
return 0;
}

Output = a = 11
b = 2

4. Program for showing OPEARTOR


PRECEDENCE in C++:
Operator precedence determines which operator operation is
performed first in an expression with more than one operator
with different precedence

5.1 Code for operators precedence:


#include <iostream>
using namespace std;
int main()

{
// declare variables
int a = 10, b = 22, c = 2, x;
x = a + b / c;
// display result
cout << "The result of the expression is = " << x;
return 0;
}

Dev kumar Page 6


OOPs practical GNDEC
5.1.1 Output
The result of the expression is = 21

6. Programming for showing Typecasting in


c++ :
It is basically conversion of one data type to another, it is
also of 2 types.

1. Implicit typecasting : This type of typecasting is done


by compiler by its own, it generally takes place when in an
expression more than one data type is present. In such
condition type conversion (type promotion) takes place to
avoid lose of data.

2. Explicit typecasting : This process of typecasting is user-


defined , here user can typecast the result into a particular
data-type

6.1.1 Program for Implicit Typecasting in C++:

6.1.1.1 Code for impliocit typecasting:


// Implicit typecasting
#include <iostream>
using namespace std;
int main()
{
int a = 10;
char y = 'D';
cout << "a + y = "<<a+y;
Dev kumar Page 7
OOPs practical GNDEC
return 0;
}

6.1.1.1.1
Output:

a + y = 78

6.2.1 Programming for Explicit Typecasting in C++:


6.2.1.1 Code for Explicit typecasting:
// Implicit typecasting
#include <iostream>
using namespace std;
int main()
{
int a = 11.8908;
char y = 'S';
cout << "a + y = " << (int)a + (int)y;
return 0;
}

6.2.1.1.1 Output :
a + y = 94

7. Program for printing If-Else


statements in C++:
7.1 Code for If-else :
#include <iostream>
using namespace std;
int main()
{
int n, i, m = 0, flag = 0;

Dev kumar Page 8


OOPs practical GNDEC
cout << "Enter the Number to check Prime: ";
cin >> n;
m = n / 2;
for (i = 2; i <= m; i++)
{
if (n % i == 0)
{
cout << "Number is not Prime." << endl;
flag = 1;
break;
}
}
if (flag == 0)
cout << "Number is Prime." << endl;
return 0;
}

7.1.1 Output:
Enter the Number to check Prime: 34 Number is not Prime.
Enter the Number to check Prime: 37 Number is Prime.

8. Program for printing If-Else Ladder in


C++:
8.1 Code for if-else ladder:
#include <iostream>
using namespace std;
int main()
{
int c;
cout << "Enter your week's choice = ";
cin >> c;
if (c == 1)
cout << " Day is Sunday." << endl;
else if (c == 2)
cout << " Day is Monday." << endl;
else if (c == 3)
Dev kumar Page 9
OOPs practical GNDEC
cout << " Day is Tuesday." << endl;
else if (c == 4)
cout << " Day is Wednesday." << endl;
else if (c == 5)
cout << " Day is Thrusday." << endl;
else if (c == 6)
cout << " Day is Friday." << endl;
else if (c == 7)
cout << " Day is Saturday." << endl;
return 0;
}

8.1.1 Output
Enter your week's choice =
6 Day is Friday.

9. Program for Nested If-Else in C++:


9.1 Code for nested if-else :
#include <iostream>
using namespace std;
int main()
{
float marks;
cout << "Enter marks out of 100" << endl;
cin >> marks;
if (marks >= 40)
{
cout << "You passed." << endl;
if (marks >= 80)
{
cout << "Good" << endl;
}
}
else
{
cout << "You failed." << endl;
Dev kumar Page 10
OOPs practical GNDEC
}
return 0;
}

9.1.1 Output
Enter marks out of 100
12
You failed.
Enter marks out of 100
77
You passed.

10. Program for printing Switch


statements in C++:
10.1 Code for switch statement:
#include <iostream>
using namespace std;
int main()
{
char a[20];
int ps;
cout << "Enter name" << endl;
cin >> a;
cout << "Enter password" << endl;
cin >> ps;
switch (ps)
{
case 20:
cout << "Your roll no. is 20" << endl;
break;
default:
cout << "--INCORRECT PASSWORD--" << endl;
break;
}
return 0;
Dev kumar Page 11
OOPs practical GNDEC
}

10.1.1 Output:
Enter name
Dev
Enter password
23
--INCORRECT PASSWORD--

11. Program for printing Loops in C++:

11.1 Program for Do-while loop in C++:

11.1.1 Code for Do-while loops:


#include <iostream>
using namespace std;
int main()
{
int a = 10;
do
{
cout << "value of a: " << a << endl;
a = a + 1;
} while (a < 15);

return 0;
}

11.1.1.1 Output:
value of a: 10

Dev kumar Page 12


OOPs practical GNDEC
value of a: 11
value of a: 12
value of a: 13
value of a: 14

11.2 Program for While loop in C++:


11.2.1 Code for while in C++:
#include <iostream>
using namespace std;
int main()
{
int a = 1;

while (a < 10)


{
cout << "value of a: " << a << endl; a++;
}
return 0;
}

11.2.1.1 Output:
value of a: 1
value of a: 2
value of a: 3
value of a: 4
value of a: 5

11.3 Program for For loop in C++:


Dev kumar Page 13
OOPs practical GNDEC
11.3.1 Code for for loop:
#include<iostream>
using namespace std;
int main()
{
int i, num;
cout << "Enter the number whose table you want to calculate"
<< endl;

cin >> num;


cout << endl;
for (i = 1; i <= 10; i++)
{
cout << num << " X " << i << " = " << num * i << endl;
}
return 0;
}

11.3.1.1 Output :
Enter the number whose table you want to calculate
6

6 X 1 = 6
6 X 2 = 12
6 X 3 = 18
6 X 4 = 24
6 X 5 = 30
6 X 6 = 36
6 X 7 = 42
6 X 8 = 48
6 X 9 = 54
6 X 10 = 60

12. Program for break statement in C++:


The break statement can also be used to jump out of a loop.

Dev kumar Page 14


OOPs practical GNDEC
12.1 Code for break statement:
#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i < 10; i++)
{
if (i == 4)
{
break;
}
cout << i << "\n";
}
}

12.1.1 Output:
0
1
2
3

13. Program for continue statement in C++:


13.1 Code for continue statement:
#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i < 10; i++)
{
if (i == 4)
{
continue;
}
cout << i << "\n";
}
}

13.1.1 Output:
Dev kumar Page 15
OOPs practical GNDEC
0
1
2
3
5
6
7
8
9

14. Program for printing functions in C++:


A function is a set of statements that take inputs, do some specific
computation and produces output.

14.1 Program for call by value in C++


14.1.1 Code for call by value:
#include <iostream>
using namespace std;

// function declaration
void swap(int x, int y)
{
int temp;
temp = x;
x = y;
y = temp;

cout << "After swapping, value of a :" << x << endl;


cout << "After swapping, value of b :" << y << endl;
}

int main()
{
int a = 10;
int b = 12;

cout << "Before swapping, value of a :" << a << endl;

Dev kumar Page 16


OOPs practical GNDEC
cout << "Before swapping, value of b :" << b << endl;

swap(a, b);
return 0;
}

14.1.1.1 Output:
Before swapping, value of a :10
Before swapping, value of b :12
After swapping, value of a :12
After swapping, value of b :10

14.2 Program for call by reference in C++:


14.2.1 Code for call by reference
#include <iostream>

using namespace std;

void addition(int &a, int &b)


{
a = a + 10;
b = b + 10;
cout << "Value of a = " << a << endl;
cout << "Value of b = " << b << endl;
}

int main()
{

int x = 9;
int y = 2;

additon(x, y);

cout << "Value of x = " << x << endl;


cout << "Value of y = " << y << endl;

return 0;
}
Dev kumar Page 17
OOPs practical GNDEC

14.2.1.1 Output
Value of a = 19
Value of b = 12
Value of x = 19
Value of y = 12

15. Program for conversion from Octal to


Decimal:
15.1 Code for octal to decimal
// C++ program to convert octal to decimal
#include <iostream>
using namespace std;
int octal_To_Decimal(int n)
{
int num = n;
int dec_value = 0;
int base = 1;
int temp = num;
while (temp)
{
int last_digit = temp % 10;
temp = temp / 10;
dec_value += last_digit * base;
base = base * 8;
}

return dec_value;
}

int main()
{
int num = 1020;
cout << octal_To_Decimal(num) << endl;
}

15.1.1 Output
Dev kumar Page 18
OOPs practical GNDEC
528

16. Program for conversion from Binary to


Decimal:
16.1 Code for binary to decimal
// C++ program to convert binary to decimal
#include <iostream>
using namespace std;
int binary_To_Decimal(int n)
{
int num = n;
int dec_value = 0;

int base = 1;

int temp = num;


while (temp) {
int last_digit = temp % 10;
temp = temp / 10;
dec_value += last_digit * base;
base = base * 2;
}
return dec_value;
}

int main()
{
int num = 1010100001;
cout << binary_To_Decimal(num) << endl;
}

16.2.1.1 Output
673

17. Arrays in C++


Dev kumar Page 19
OOPs practical GNDEC
17.1 Program to print all distinct elements
of array in C++:
17.1.1 Code for printing elements of array
#include <bits/stdc++.h>
using namespace std;

void print(int arr[], int n)


{

for (int i = 0; i < n; i++)


{
int j;
for (j = 0; j < i; j++)
if (arr[i] == arr[j])
break;

if (i == j)
cout << arr[i] << " ";
}
}
int main()
{
int arr[] = {1, 2, 45, 3, 2, 4, 3, 2, 12, 100};
int n = sizeof(arr) / sizeof(arr[0]);
print(arr, n);
return 0;
}

17.1.1.1 Output
1 2 45 3 4 12 100

17.2 Program to multiply two matrices in


C++:
17.2.1 Code to multiply two matrices:
#include <iostream>
Dev kumar Page 20
OOPs practical GNDEC
using namespace std;

#define R1 4
#define C1 4
#define R2 4
#define C2 4

void mulMat(int mat1[][C1], int mat2[][C2]) {


int rslt[R1][C2];

cout << "Multiplication of given two matrices is:\n" << endl;

for (int i = 0; i < R1; i++) {


for (int j = 0; j < C2; j++) {
rslt[i][j] = 0;

for (int k = 0; k < R2; k++) {


rslt[i][j] += mat1[i][k] * mat2[k][j];
}

cout << rslt[i][j] << "\t";


}
cout << endl;
}
}

int main(void) {
int mat1[R1][C1] = {
{1, 1, 1, 1},{2, 2, 2, 2}, {3, 3, 3, 3},
{4, 4, 4, 4}
};

int mat2[R2][C2] = {
{1, 1, 1, 1},{2, 2, 2, 2},{3, 3, 3, 3},
{4, 4, 4, 4}
};

if (C1 != R2) {
cout << "The number of columns in Matrix-1 must be equal
to the number of rows in "
"Matrix-2" << endl;
Dev kumar Page 21
OOPs practical GNDEC
cout << "Please update MACROs according to your array
dimension in #define section"
<< endl;

exit(EXIT_FAILURE);
}
mulMat(mat1, mat2);

return 0;
}

17.2.1.1 Output
Multiplication of given two matrices is:

10 10 10 10
20 20 20 20
30 30 30 30
40 40 40 40

18. String in C++:

18.1 Print a string in C++:


18.1.1 Code to print a string:
#include <iostream>
using namespace std;
int main()
{
char str[20];
cout << "Enter Your First Name: ";

cin >> str;


cout << "\nHello, " << str;
cout << endl;
return 0;
}

Dev kumar Page 22


OOPs practical GNDEC
18.1.1.1 Output
Enter Your First Name: Dev
Hello, Dev

18.2 Program to count number of vowels in


a string C++
18.2.1 Code to count number of vowels
#include <iostream>
using namespace std;
int vowelCount(char *sptr)
{
int count = 0;

while ((*sptr) != '\0') {

if (*sptr == 'a' || *sptr == 'e' || *sptr == 'i'


|| *sptr == 'o' || *sptr == 'u') {

count++;
}
sptr++;
}
return count;
}

int main()
{
char str[] = "object oriented programming";

cout << "Vowels in above string: " << vowelCount(str);

return 0;
}

18.2.1.1 Output
Vowels in above string: 9

Dev kumar Page 23


OOPs practical GNDEC
18.3 Program to check weather a given
string is a palindrome:
18.3.1 Code to check palindrome
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char str[100];
int i, length;
int flag = 0;

cout << "\n Enter String : ";


cin >> str;

length = strlen(str);

for (i = 0; i < length; i++)


{
if (str[i] != str[length - i - 1])
{
flag = 1;
break;
}
}
if (flag)
{
cout << " " << str << " is not a palindrome" << endl;
}
else
{
cout << " " << str << " is a palindrome" << endl;
}
return 0;
}

21.3.1.1 Output
Enter String : divid
Dev kumar Page 24
OOPs practical GNDEC
divid is a palindrome

18.4 Program to reverse a string in C++


18.4.1 Code to reverse a string
#include <bits/stdc++.h>
using namespace std;

void reverseStr(string& str)


{
int n = str.length();
for (int i = 0; i < n / 2; i++)
swap(str[i], str[n - i - 1]);
}

int main()
{
string str = "Praidime";
reverseStr(str);
cout << str;
return 0;
}

18.4.1.1 Output
emidiarP

18.5 Program to print all duplicate


characters in C++
18.5.1 Code for duplicate char
#include <bits/stdc++.h>
#define NO_OF_CHARS 256
using namespace std;
void printDuplicates(string s)
{
int count[NO_OF_CHARS] = {};
for (int i = 0; i < s.size(); i++)
count[s[i]]++;
Dev kumar Page 25
OOPs practical GNDEC
for (int i = 0; i < s.size(); i++)
if (count[s[i]] > 1) //
{
cout << s[i] << " count = " << count[s[i]] << endl;
count[s[i]] = 0;
}
}
int main()
{
string s = "Worldcupaustralia";
cout << "Input string is " << s << endl;
printDuplicates(s);
}

18.5.1.1 Output
r count = 2
l count = 2
u count = 2
a count = 3

22.1 Write a C++ program to calculate the area of


rectangle using constructors and destructres:
22.1.1 Code for costructures:
#include <iostream>
using namespace std;

class Rectangle{
float length;
float breadth;

public:
void set_parameters(int l,int b){
if(l>=0 && b>=0){
length=l;
breadth=b;
}
}
Dev kumar Page 26
OOPs practical GNDEC
float area(){
return length*breadth;
}
float perimeter(){
return 2*(length+breadth);
}
/* NON Parametrized Constructor */
Rectangle(){
length=0;
breadth=0;
cout<<"Non parametrized constructor called "<<endl;
}
/* Parametrized constructor */
Rectangle(int a,int b){
length=a;
breadth=b;
cout<<"Parametrized constructor called "<<endl;
}
/* Copy Constructor */
Rectangle(Rectangle &rect){
length= rect.length;
breadth =rect.breadth;
cout<<"Copy constructor called "<<endl;
}

//destructor
~Rectangle(){
cout<<"destructor called"<<endl;
}
};

int main(){
Rectangle r1;
Rectangle r2(3,10);
Rectangle r3(r2);
return 0;
}

22.1.1.1 Output
Non parametrized constructor called
Dev kumar Page 27
OOPs practical GNDEC
Parametrized constructor called
Copy constructor called
destructor called
destructor called
destructor called

Dev kumar Page 28

You might also like