0% found this document useful (0 votes)
8 views53 pages

Vishnu

The document outlines practical programming exercises using C++ for students at Bhagwan Mahavir Polytechnic, including tasks such as printing messages, performing arithmetic operations, calculating areas of shapes, and using reference variables. Each exercise includes source code, input-output examples, and assessment criteria for evaluating student performance. The document emphasizes structured programming and proper documentation of code.
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)
8 views53 pages

Vishnu

The document outlines practical programming exercises using C++ for students at Bhagwan Mahavir Polytechnic, including tasks such as printing messages, performing arithmetic operations, calculating areas of shapes, and using reference variables. Each exercise includes source code, input-output examples, and assessment criteria for evaluating student performance. The document emphasizes structured programming and proper documentation of code.
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/ 53

BHAGWAN

MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY

Practical 1.1 Develop program using C++ Structure.


No: 1

Aim 1.1.1: Write a program to print “Hello” using C++ structure.


Source Code:
//Write a program to print “Hello”.
#include<iostream>
using namespace std;
int main ()
{
cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;
cout<<"Hello Vishnu";
return 0;
}
Input-Output:
Program Created By Vishnu Rawal [En_No.: 2327010701136]
Hello Vishnu

=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


1
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Aim 1.1.2: Write a program to take user input and perform addition of two
numbers.
Source Code:
//write a program to take user input and perform.
#include<iostream>
using namespace std; int main ()
{

cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;


int Maths,Science, Addition;
cout<<"Enter the Marks of Maths:";
cin>>Maths;
cout<<"Enter the Marks of Science:";
cin>>Science;
Addition= Maths+Science;
cout<<endl<<"Addition of Marks is:"<<Addition;
return 0;
}
Input-Output:
Program Created By Vishnu Rawal [En_No.: 2327010701136]

Enter the Marks of Maths:92


Enter the Marks of Science:83

Addition of Marks is:175

=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


2
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Assessment:

Total Marks
Criteria Exceptional Satisfactory Developing Limited
Marks Obtaine
d
Accurately 1-2 errors / 3-5 errors/ More than 5
Accuracy 3 done mistake mistake errors
(3) (2) (1) (1)
Fully under Partially Partially
Understand
stood and understood understood
Understanding but cannot
3 explain and can and cannot
& Explanation explain
perfectly explain explain
(2)
(3) (1) (1)
Watched other
Present but
Performed students
Performed not
Practical performing
Practical participate
Engagement 2 with other practical but
him/her self in
help not tried him/
(2) performance
(1) her self
(0.5)
(0.5)
Document is Missing
Documented Poor writing,
proper, but output.
properly, no missing
Documentation 1 presentation Improper
error output
is average documentation
(1) (0.25)
(0.5) (0.25)
Complete Complete Work
Submit after 2
within a within two submits after
Time 1 weeks
week weeks 3 weeks.
(0.25)
(1) (0.5) (0.25)

Total

Faculty Signature with Date

BHAGWAN MAHAVIR POLYTECHNIC


3
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Aim 1.1.3: write a program to calculate the area of various shapes using switch
case.
Source Code:
//write a program to calculate the area of various shapes using switch case.
#include <iostream>
#include <cmath> // For using M_PI (for pi value in circle area calculation)
using namespace std;
int main ()
{

cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;

int choice;
float area;
cout << "Choose the shape to calculate the area:\n";
cout << "1. Circle\n";
cout << "2. Triangle\n";
cout << "3. Square\n";
cout << "Enter your choice (1-3): ";
cin >> choice;
switch (choice)
{
case 1:
{
float radius;
cout << "Enter the radius of the circle: ";
cin>> radius;
area = M_PI * radius * radius; // Area = π * r^2
cout<< "The area of the circle is: " << area << endl;
break;
}
case 2:
{
float base, height;
cout << "Enter the base of the triangle: ";
cin>> base;
cout << "Enter the height of the triangle: ";
cin >> height;
area = 0.5 * base * height; // Area = 0.5 * base * height
cout << "The area of the triangle is: " << area << endl;
break;
}
case 3:
{
float side;
cout << "Enter the side length of the square: ";
cin >> side;
area = side * side; // Area = side^2
cout << "The area of the square is: " << area << endl;
break;}
default:
BHAGWAN MAHAVIR POLYTECHNIC
4
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
cout << "Invalid choice! Please enter a valid option (1-3).\n";

}
return 0;

}
Input-Output:
Program Created By Vishnu Rawal [En_No.: 2327010701136]

Choose the shape to calculate the area:


1. Circle
2. Triangle
3. Square
Enter your choice (1-3): 1
Enter the radius of the circle: 10
The area of the circle is: 314.159

=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


5
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Assessment:

Total Marks
Criteria Exceptional Satisfactory Developing Limited
Marks Obtaine
d
Accurately 1-2 errors / 3-5 errors/ More than 5
Accuracy 3 done mistake mistake errors
(3) (2) (1) (1)
Fully under Partially Partially
Understand
stood and understood understood
Understanding but cannot
3 explain and can and cannot
& Explanation explain
perfectly explain explain
(2)
(3) (1) (1)
Watched other
Present but
Performed students
Performed not
Practical performing
Practical participate
Engagement 2 with other practical but
him/her self in
help not tried him/
(2) performance
(1) her self
(0.5)
(0.5)
Document is Missing
Documented Poor writing,
proper, but output.
properly, no missing
Documentation 1 presentation Improper
error output
is average documentation
(1) (0.25)
(0.5) (0.25)
Complete Complete Work
Submit after 2
within a within two submits after
Time 1 weeks
week weeks 3 weeks.
(0.25)
(1) (0.5) (0.25)

Total

Faculty Signature with Date

BHAGWAN MAHAVIR POLYTECHNIC


6
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Practical No: 2.1 Develop programs using reference variables.
2

Aim 2.1.1: Write a program to display the variable value before addition and after addition using
reference variable.
Source Code:
// Write a program to display the variable value before addition and after addition using reference variable.
#include <iostream>
using namespace std;

// Function to modify the number


void modifyNumber(int &num) {
num += 10; // Modify the value (e.g., add 10)
}
int main() {
cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;
int number; // Variable to hold the input number
cout << "Enter a number: ";
cin >> number;
modifyNumber(number); // Pass the number by reference
cout << "Final value in main: " << number << endl; // Modified value is reflected here return 0;
}
Input-output:
Program Created By Vishnu Rawal [En_No.: 2327010701136]
Enter a number: 10
Final value in main: 20

=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


7
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY

BHAGWAN MAHAVIR POLYTECHNIC


8
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Assessment:

Total Marks
Criteria Exceptional Satisfactory Developing Limited
Marks Obtaine
d
Accurately 1-2 errors / 3-5 errors/ More than 5
Accuracy 3 done mistake mistake errors
(3) (2) (1) (1)
Fully under Partially Partially
Understand
stood and understood understood
Understanding but cannot
3 explain and can and cannot
& Explanation explain
perfectly explain explain
(2)
(3) (1) (1)
Watched other
Present but
Performed students
Performed not
Practical performing
Practical participate
Engagement 2 with other practical but
him/her self in
help not tried him/
(2) performance
(1) her self
(0.5)
(0.5)
Document is Missing
Documented Poor writing,
proper, but output.
properly, no missing
Documentation 1 presentation Improper
error output
is average documentation
(1) (0.25)
(0.5) (0.25)
Complete Complete Work
Submit after 2
within a within two submits after
Time 1 weeks
week weeks 3 weeks.
(0.25)
(1) (0.5) (0.25)

Total

Faculty Signature with Date

BHAGWAN MAHAVIR POLYTECHNIC


9
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Practical No: 3.1 Develop programs using formatted and unformatted i/o functions.
3

Aim 3.1.1: Write a program which takes string as input and read its character and display it
using getline and write functions.
Source Code:
//Write a program which takes string as input and read its character and display it using
getline and write functions.
#include<iostream>
#include<cstring>
#include <iomanip>
using namespace std;

int main()
{
cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;
char str[20];
int i,n;
cout<<"Enter some String"<<endl; cin.getline(str,20);
n = 15;
cout<<n<<endl;
for( i = 0 ; i < n ; i++)
{
cout.write(str,i); cout<<endl;
}
return 0;
}

Input-Output:

BHAGWAN MAHAVIR POLYTECHNIC


10
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Program Created By Vishnu Rawal [En_No.: 2327010701136]

Enter some String


Hello World
15

H
He
Hel
Hell
Hello
Hello
Hello W
Hello Wo
Hello Wor
Hello Worl
Hello World
Hello World
=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


11
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Assessment:

Total Marks
Criteria Exceptional Satisfactory Developing Limited
Marks Obtaine
d
Accurately 1-2 errors / 3-5 errors/ More than 5
Accuracy 3 done mistake mistake errors
(3) (2) (1) (1)
Fully under Partially Partially
Understand
stood and understood understood
Understanding but cannot
3 explain and can and cannot
& Explanation explain
perfectly explain explain
(2)
(3) (1) (1)
Watched other
Present but
Performed students
Performed not
Practical performing
Practical participate
Engagement 2 with other practical but
him/her self in
help not tried him/
(2) performance
(1) her self
(0.5)
(0.5)
Document is Missing
Documented Poor writing,
proper, but output.
properly, no missing
Documentation 1 presentation Improper
error output
is average documentation
(1) (0.25)
(0.5) (0.25)
Complete Complete Work
Submit after 2
within a within two submits after
Time 1 weeks
week weeks 3 weeks.
(0.25)
(1) (0.5) (0.25)

Total

Faculty Signature with Date

BHAGWAN MAHAVIR POLYTECHNIC


12
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Aim 3.1.2: Write a program which reads user input and display it as formatted output
using setfill,setw function.
Source Code:
//Write a program which reads user input and display it as formatted output using setfill,setw function.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;

string name;
int age;
// Input
cout << "Enter your name: ";
getline(cin, name);
cout << "Enter your age: ";
cin >> age;
// Output formatted
cout << string(20, '-') << "\n"; // Print a line of dashes for better output structure
cout << left << setw(10) << "Name:" << name << "\n";
cout << left << setw(10) << "Age:" << age << "\n";
cout << string(20, '*') << "\n"; // Print a line of asterisks for separation
return 0;
}
Input-Output:
Program Created By Vishnu Rawal [En_No.: 2327010701136]

Enter your name: Vishnu


Enter your age: 18
--------------------
Name: Vishnu
Age: 18
********************

=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


13
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Assessment:

Total Marks
Criteria Exceptional Satisfactory Developing Limited
Marks Obtaine
d
Accurately 1-2 errors / 3-5 errors/ More than 5
Accuracy 3 done mistake mistake errors
(3) (2) (1) (1)
Fully under Partially Partially
Understand
stood and understood understood
Understanding but cannot
3 explain and can and cannot
& Explanation explain
perfectly explain explain
(2)
(3) (1) (1)
Watched other
Present but
Performed students
Performed not
Practical performing
Practical participate
Engagement 2 with other practical but
him/her self in
help not tried him/
(2) performance
(1) her self
(0.5)
(0.5)
Document is Missing
Documented Poor writing,
proper, but output.
properly, no missing
Documentation 1 presentation Improper
error output
is average documentation
(1) (0.25)
(0.5) (0.25)
Complete Complete Work
Submit after 2
within a within two submits after
Time 1 weeks
week weeks 3 weeks.
(0.25)
(1) (0.5) (0.25)

Total

Faculty Signature with Date

BHAGWAN MAHAVIR POLYTECHNIC


14
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Practical No: 4.1 Develop programs using call by reference and return by reference.
4

Aim 4.1.1: Write a program to swap two numbers value using “ Call by Reference”
Source Code:
//Write a program to swap the value of two numbers using call by reference
#include <iostream>
using namespace std;
// Function to swap two numbers using reference variables
void Call_by_Reference (int &a, int &b) {
int temp = a;
a = b;
b = temp;
}
void Call_by_value (int a, int b) { int temp = a;
a = b;
b = temp;
}
int main ()
{
cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;

int num1, num2;


// Input numbers
cout << "Enter the first number: ";
cin >> num1;
cout << "Enter the second number: ";
cin >> num2;
// Display numbers before swapping
cout << "\nBefore swapping:\n";
cout << "Number 1: " << num1 << endl;

cout << "Number 2: " << num2 << endl;


// Call the swap function Call_by_Reference(num1, num2);
// Display numbers after swapping
cout << "\nUsing Call By Reference:\n";
cout << "Number 1: " << num1 << endl;
cout << "Number 2: " << num2 << endl;

Call_by_value(num1, num2);
// Display numbers after swapping
cout << "\nUsing Call By Value:\n";
cout << "Number 1: " << num1 << endl; cout << "Number 2: " << num2 << endl;
return 0;
}

Input-output:

BHAGWAN MAHAVIR POLYTECHNIC


15
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Program Created By Vishnu Rawal [En_No.: 2327010701136]

Enter the first number: 10


Enter the second number: 20

Before swapping:
Number 1: 10
Number 2: 20

Using Call By Reference:


Number 1: 10
Number 2: 20

Using Call By Value:


Number 1: 10
Number 2: 20

=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


16
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Assessment:

Total Marks
Criteria Exceptional Satisfactory Developing Limited
Marks Obtaine
d
Accurately 1-2 errors / 3-5 errors/ More than 5
Accuracy 3 done mistake mistake errors
(3) (2) (1) (1)
Fully under Partially Partially
Understand
stood and understood understood
Understanding but cannot
3 explain and can and cannot
& Explanation explain
perfectly explain explain
(2)
(3) (1) (1)
Watched other
Present but
Performed students
Performed not
Practical performing
Practical participate
Engagement 2 with other practical but
him/her self in
help not tried him/
(2) performance
(1) her self
(0.5)
(0.5)
Document is Missing
Documented Poor writing,
proper, but output.
properly, no missing
Documentation 1 presentation Improper
error output
is average documentation
(1) (0.25)
(0.5) (0.25)
Complete Complete Work
Submit after 2
within a within two submits after
Time 1 weeks
week weeks 3 weeks.
(0.25)
(1) (0.5) (0.25)

Total

Faculty Signature with Date

BHAGWAN MAHAVIR POLYTECHNIC


17
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Aim 4.1.2: Write a program to add two number and display the output using “Return By Value.
Source Code:
// Write a program to add two number and display the output using “Return By Value.
#include <iostream>
using namespace std;
// Function to add two numbers and return the result
int add(int a, int b)
{
return a + b;
// Return the sum of a and b
}
int main()
{
cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;
int num1, num2;
// Input numbers
cout << "Enter the first number: "; cin >> num1;
cout << "Enter the second number: "; cin >> num2;
// Call the add function and store the result
int sum = add(num1, num2);
// Display the result
cout << "\nThe sum of " << num1 << " and " << num2 << " is: " << sum << endl;
return 0;
}
Input-output:
Program Created By Vishnu Rawal [En_No.: 2327010701136]
Enter the first number: 10
Enter the second number: 20
The sum of 10 and 20 is: 30

=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


18
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY

BHAGWAN MAHAVIR POLYTECHNIC


19
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Assessment:

Total Marks
Criteria Exceptional Satisfactory Developing Limited
Marks Obtaine
d
Accurately 1-2 errors / 3-5 errors/ More than 5
Accuracy 3 done mistake mistake errors
(3) (2) (1) (1)
Fully under Partially Partially
Understand
stood and understood understood
Understanding but cannot
3 explain and can and cannot
& Explanation explain
perfectly explain explain
(2)
(3) (1) (1)
Watched other
Present but
Performed students
Performed not
Practical performing
Practical participate
Engagement 2 with other practical but
him/her self in
help not tried him/
(2) performance
(1) her self
(0.5)
(0.5)
Document is Missing
Documented Poor writing,
proper, but output.
properly, no missing
Documentation 1 presentation Improper
error output
is average documentation
(1) (0.25)
(0.5) (0.25)
Complete Complete Work
Submit after 2
within a within two submits after
Time 1 weeks
week weeks 3 weeks.
(0.25)
(1) (0.5) (0.25)

Total

Faculty Signature with Date

BHAGWAN MAHAVIR POLYTECHNIC


20
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Aim 4.1.3: Write a program to do arithmetic calculation on user entered number and
display the updated value using “Return By Reference”.
Source Code:
// Write a program to do arithmetic calculation on user entered number and display the updated value using
“Return By Reference”.
#include<iostream>
using namespace std;
int& manipulateData(int &a,int &b)
{
a=a+b;
b=a-b;
return a;
}
int main(){

cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;


int num1 , num2 , z;
cout<<"Enter First Number:";
cin>>num1;
cout<<"Enter Second Number:";
cin>>num2;
cout<<endl<<"Before manipulation:"<<endl;
cout<<"Number 1:"<<num1<<endl;
cout<<"Number 2:"<<num2<<endl;
z=manipulateData(num1,num2);
cout<<endl<<"After manipulation:"<<endl;
cout<<"Number 1:"<<num1<<endl;
cout<<"Number 2:"<<num2<<endl;
return 0;
}

BHAGWAN MAHAVIR POLYTECHNIC


21
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Input-Output:
Program Created By Vishnu Rawal [En_No.: 2327010701136]

Enter First Number:10


Enter Second Number:20
Before manipulation:

Number 1:10
Number 2:20
After manipulation:
Number 1:30
Number 2:10

=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


22
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Assessment:

Total Marks
Criteria Exceptional Satisfactory Developing Limited
Marks Obtaine
d
Accurately 1-2 errors / 3-5 errors/ More than 5
Accuracy 3 done mistake mistake errors
(3) (2) (1) (1)
Fully under Partially Partially
Understand
stood and understood understood
Understanding but cannot
3 explain and can and cannot
& Explanation explain
perfectly explain explain
(2)
(3) (1) (1)
Watched other
Present but
Performed students
Performed not
Practical performing
Practical participate
Engagement 2 with other practical but
him/her self in
help not tried him/
(2) performance
(1) her self
(0.5)
(0.5)
Document is Missing
Documented Poor writing,
proper, but output.
properly, no missing
Documentation 1 presentation Improper
error output
is average documentation
(1) (0.25)
(0.5) (0.25)
Complete Complete Work
Submit after 2
within a within two submits after
Time 1 weeks
week weeks 3 weeks.
(0.25)
(1) (0.5) (0.25)

Total

Faculty Signature with Date

BHAGWAN MAHAVIR POLYTECHNIC


23
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Assessment:

Total Marks
Criteria Exceptional Satisfactory Developing Limited
Marks Obtaine
d
Accurately 1-2 errors / 3-5 errors/ More than 5
Accuracy 3 done mistake mistake errors
(3) (2) (1) (1)
Fully under Partially Partially
Understand
stood and understood understood
Understanding but cannot
3 explain and can and cannot
& Explanation explain
perfectly explain explain
(2)
(3) (1) (1)
Watched other
Present but
Performed students
Performed not
Practical performing
Practical participate
Engagement 2 with other practical but
him/her self in
help not tried him/
(2) performance
(1) her self
(0.5)
(0.5)
Document is Missing
Documented Poor writing,
proper, but output.
properly, no missing
Documentation 1 presentation Improper
error output
is average documentation
(1) (0.25)
(0.5) (0.25)
Complete Complete Work
Submit after 2
within a within two submits after
Time 1 weeks
week weeks 3 weeks.
(0.25)
(1) (0.5) (0.25)

Total

Faculty Signature with Date

BHAGWAN MAHAVIR POLYTECHNIC


24
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Practical No: 5.1 Define minimum 3 different classes (such as student, distance, shape, and
5 employee etc) and test those classes functionality.

Aim 5.1.1: Create Student (student name and age/enrollment number),Employee(Employee


Name,Job Title/age/Department),Shape(Rectange/Circle/Square ,Area caluclation) classes
with given attribute and test.

Source Code:
// Create Student (student name and age/enrollment number),Employee(Employee Name,Job
Title/age/Department),Shape(Rectange/Circle/Square ,Area caluclation) classes with given attribute
and test.
#include <iostream>
#include <string>
using namespace std;

class student {
int rollNo;
string name;
public:
void getDetails() {
cout << "Student Information:" << endl;
cout << "Enter Name: ";
cin.ignore(); // Clear input buffer before using getline
getline(cin, name); // Use getline to allow spaces in the name
cout << "Enter Roll Number: ";
cin >> rollNo;
}
void displayDetails() {
cout << "\nStudent Details:" << endl;
cout << "Roll Number: " << rollNo << endl;
cout << "Name: " << name << endl;
}
};

class employee {
string name;
string department;
string role;

public:
void getDetailsemp() {
cout << "\nEmployee Information:" << endl;
cout << "Enter Name: ";
cin.ignore(); // Clear input buffer before using getline
getline(cin, name); // Use getline to allow spaces in the name
cout << "Enter Department: ";
getline(cin, department); // Use getline to allow spaces in department
cout << "Enter Job Type: ";
getline(cin, role); // Use getline to allow spaces in job type
}

BHAGWAN MAHAVIR POLYTECHNIC


25
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
void displayDetailsemp() {
cout << "\nEmployee Details:" << endl;
cout << "Name: " << name << endl;
cout << "Department: " << department << endl;
cout << "Job Type: " << role << endl;
}
};
class shap {
float base, height, area;
public:
void getDetailsshap() {
cout << "\nTriangle Information:" << endl;
cout << "Enter Base of Triangle: ";
cin >> base;
cout << "Enter Height of Triangle: ";
cin >> height;
area = 0.5 * base * height;
}

void displayDetailsshap() {
cout << "\nShape Details:" << endl;
cout << "The area of the triangle is: " << area << endl;
}
};

int main() {

cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;


student s1;
s1.getDetails();
s1.displayDetails();

employee e1;
e1.getDetailsemp();
e1.displayDetailsemp();
shap t1;
t1.getDetailsshap();
t1.displayDetailsshap();
return 0;
}

BHAGWAN MAHAVIR POLYTECHNIC


26
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Input-Output:

Program Created By Vishnu Rawal [En_No.: 2327010701136]

Student Information:
Enter Name: Vishnu rawal
Enter Roll Number: 136

Student Details:
Roll Number: 136
Name: ishnu rawal

Employee Information:
Enter Name: Vishnu rawal
Enter Department: IT
Enter Job Type: Software Engineer

Employee Details:
Name: Vishnu rawal
Department: IT
Job Type: Software Engineer

Triangle Information:
Enter Base of Triangle: 5
Enter Height of Triangle: 6

Shape Details:
The area of the triangle is: 15

=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


27
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY

BHAGWAN MAHAVIR POLYTECHNIC


28
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Assessment:

Total Marks
Criteria Exceptional Satisfactory Developing Limited
Marks Obtaine
d
Accurately 1-2 errors / 3-5 errors/ More than 5
Accuracy 3 done mistake mistake errors
(3) (2) (1) (1)
Fully under Partially Partially
Understand
stood and understood understood
Understanding but cannot
3 explain and can and cannot
& Explanation explain
perfectly explain explain
(2)
(3) (1) (1)
Watched other
Present but
Performed students
Performed not
Practical performing
Practical participate
Engagement 2 with other practical but
him/her self in
help not tried him/
(2) performance
(1) her self
(0.5)
(0.5)
Document is Missing
Documented Poor writing,
proper, but output.
properly, no missing
Documentation 1 presentation Improper
error output
is average documentation
(1) (0.25)
(0.5) (0.25)
Complete Complete Work
Submit after 2
within a within two submits after
Time 1 weeks
week weeks 3 weeks.
(0.25)
(1) (0.5) (0.25)

Total

Faculty Signature with Date

BHAGWAN MAHAVIR POLYTECHNIC


29
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Practical No: 6.1 Develop programs using arrays of objects and static member functions.
6

Aim 6.1.1: Write a program to create Vehicle class and create three different types of vehicles entries
which should have details like color, model, and transmission type.
Source Code:
// Write a program to create Vehicle class and create three different types of vehicles entries which
should have details like color, model, and transmission type.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
// Define a Vehicle class
class Vehicle {
public:
string name; string color; double price;
// Function to display vehicle details
void display() {
cout << "Name: " << name << endl;
cout << "Color: " << color << endl;
cout << "Price: "<<fixed << setprecision(2) << price << endl;
cout << "----------------" << endl;
}
};
int main() {
cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;
int numVehicles = 3; // Number of vehicles
Vehicle vehicles[numVehicles]; // Array of Vehicle objects
// Input details for each vehicle
for (int i = 0; i < numVehicles; i++) {

cout << "Enter the Name of vehicle " << (i + 1) << ": ";

cin >> vehicles[i].name;


cout << "Enter the Color of vehicle " << (i + 1) << ": ";
cin >> vehicles[i].color;
cout << "Enter the Price of vehicle " << (i + 1) << ": ";
cin >> vehicles[i].price;
cout << endl;
}
// Display the vehicle details
cout << "Vehicle Details:" << endl;
for (int i = 0; i < numVehicles; i++) {
cout << "Vehicle " << (i + 1) << ":" << endl;
BHAGWAN MAHAVIR POLYTECHNIC
30
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
vehicles[i].display();
}
return 0;
}
Input-Output:
Program Created By Vishnu Rawal [En_No.: 2327010701136]

Enter the Name of vehicle 1: Swift


Enter the Color of vehicle 1: black
Enter the Price of vehicle 1: 200000

Enter the Name of vehicle 2: Creta


Enter the Color of vehicle 2: red
Enter the Price of vehicle 2: 300000

Enter the Name of vehicle 3: Glanza


Enter the Color of vehicle 3: White
Enter the Price of vehicle 3: 500000

Vehicle Details:
Vehicle 1:
Name: Swift
Color: black
Price: 200000.00
----------------
Vehicle 2:
Name: Creta
Color: red
Price: 300000.00
----------------
Vehicle 3:
Name: Glanza
Color: White
Price: 500000.00
----------------

=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


31
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY

BHAGWAN MAHAVIR POLYTECHNIC


32
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Assessment:

Total Marks
Criteria Exceptional Satisfactory Developing Limited
Marks Obtaine
d
Accurately 1-2 errors / 3-5 errors/ More than 5
Accuracy 3 done mistake mistake errors
(3) (2) (1) (1)
Fully under Partially Partially
Understand
stood and understood understood
Understanding but cannot
3 explain and can and cannot
& Explanation explain
perfectly explain explain
(2)
(3) (1) (1)
Watched other
Present but
Performed students
Performed not
Practical performing
Practical participate
Engagement 2 with other practical but
him/her self in
help not tried him/
(2) performance
(1) her self
(0.5)
(0.5)
Document is Missing
Documented Poor writing,
proper, but output.
properly, no missing
Documentation 1 presentation Improper
error output
is average documentation
(1) (0.25)
(0.5) (0.25)
Complete Complete Work
Submit after 2
within a within two submits after
Time 1 weeks
week weeks 3 weeks.
(0.25)
(1) (0.5) (0.25)

Total

Faculty Signature with Date

BHAGWAN MAHAVIR POLYTECHNIC


33
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Aim 6.1.2: Write a program to display the static variable updated value while its used by
different objects of class.
Source Code:
// Write a program to display the static variable updated value while its used by different objects of class.
#include <iostream>
using namespace std;
class StaticMember
{ private:
static int count;
public:
static void check()
{
count++;
}
static void displayCount() {
cout << "Final Static Count is: " << count << endl;
}
};
int StaticMember::count = 0;
int main() {
cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;
StaticMember obj1, obj2, obj3, obj4;
obj1.check();
obj2.check();
obj1.check();
obj4.check();
obj1.check(); StaticMember::displayCount();
return 0;
}

BHAGWAN MAHAVIR POLYTECHNIC


34
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Input-Output:
Program Created By Vishnu Rawal [En_No.: 2327010701136]
Final Static Count is: 5
=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


35
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Assessment:

Total Marks
Criteria Exceptional Satisfactory Developing Limited
Marks Obtaine
d
Accurately 1-2 errors / 3-5 errors/ More than 5
Accuracy 3 done mistake mistake errors
(3) (2) (1) (1)
Fully under Partially Partially
Understand
stood and understood understood
Understanding but cannot
3 explain and can and cannot
& Explanation explain
perfectly explain explain
(2)
(3) (1) (1)
Watched other
Present but
Performed students
Performed not
Practical performing
Practical participate
Engagement 2 with other practical but
him/her self in
help not tried him/
(2) performance
(1) her self
(0.5)
(0.5)
Document is Missing
Documented Poor writing,
proper, but output.
properly, no missing
Documentation 1 presentation Improper
error output
is average documentation
(1) (0.25)
(0.5) (0.25)
Complete Complete Work
Submit after 2
within a within two submits after
Time 1 weeks
week weeks 3 weeks.
(0.25)
(1) (0.5) (0.25)

Total

Faculty Signature with Date

BHAGWAN MAHAVIR POLYTECHNIC


36
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Practical No: 7.1 Develop programs to pass objects as an argument and return objects.
7

Aim 7.1.1: Write a program to add the numbers of two objects by passing object as argument and
return the sum as output in third object.
Source Code:
// Write a program to add the numbers of two objects by passing object as argument and return the sum as
output in third object.
#include <iostream>
using namespace std;
class Student
{
public:
int mark;
Student addAndReturn(Student a) { Student temp;
temp.mark = mark + a.mark; return temp;
}
};
int main() {

cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;

Student mark1, mark2, result;


cout << "Enter the mark for object 1: "; cin >> mark1.mark;
cout << "Enter the mark for object 2: "; cin >> mark2.mark;
cout << endl << "Initial values: " << endl;
cout << "Value of object 1: " << mark1.mark << endl;
cout << "Value of object 2: " << mark2.mark << endl;

result = mark1.addAndReturn(mark2);
cout << endl << "After using addAndReturn() (returning an object): " << endl;

BHAGWAN MAHAVIR POLYTECHNIC


37
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
cout << "Value of result object: " << result.mark << endl;
return 0;
}
Input-Output:
Program Created By Vishnu Rawal [En_No.: 2327010701136]

Enter the mark for object 1: 10


Enter the mark for object 2: 20

Initial values:
Value of object 1: 10
Value of object 2: 20

After using addAndReturn() (returning an object):


Value of result object: 30

=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


38
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Assessment:

Total Marks
Criteria Exceptional Satisfactory Developing Limited
Marks Obtaine
d
Accurately 1-2 errors / 3-5 errors/ More than 5
Accuracy 3 done mistake mistake errors
(3) (2) (1) (1)
Fully under Partially Partially
Understand
stood and understood understood
Understanding but cannot
3 explain and can and cannot
& Explanation explain
perfectly explain explain
(2)
(3) (1) (1)
Watched other
Present but
Performed students
Performed not
Practical performing
Practical participate
Engagement 2 with other practical but
him/her self in
help not tried him/
(2) performance
(1) her self
(0.5)
(0.5)
Document is Missing
Documented Poor writing,
proper, but output.
properly, no missing
Documentation 1 presentation Improper
error output
is average documentation
(1) (0.25)
(0.5) (0.25)
Complete Complete Work
Submit after 2
within a within two submits after
Time 1 weeks
week weeks 3 weeks.
(0.25)
(1) (0.5) (0.25)

Total

Faculty Signature with Date

BHAGWAN MAHAVIR POLYTECHNIC


39
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Practical 8.1 Develop programs that define the concept of operator overloading.
No: 8

Aim 8.1.1: Write a program to add two complex numbers using + operator overloading.

Source Code:
// Write a program to add two complex numbers using + operator overloading.
#include<iostream>
using namespace std;
class Complex {
private:
int real, imag;
public:
Complex(int r = 0, int i = 0)
{
real = r;
imag = i;
}
Complex operator + (Complex const &obj)
{
Complex res;
res.real = real + obj.real;
res.imag = imag + obj.imag;
return res;
}
void print() {
cout << real << " + " << imag << "i" << endl; }
};
int main() {

cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;


Complex c1(4, 9), c2(2, 8);
Complex c3 = c1 + c2; c3.print();
}
Input-Output:
Program Created By Vishnu Rawal [En_No.: 2327010701136]

6 + 17i

=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


40
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY

BHAGWAN MAHAVIR POLYTECHNIC


41
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Assessment:

Total Marks
Criteria Exceptional Satisfactory Developing Limited
Marks Obtaine
d
Accurately 1-2 errors / 3-5 errors/ More than 5
Accuracy 3 done mistake mistake errors
(3) (2) (1) (1)
Fully under Partially Partially
Understand
stood and understood understood
Understanding but cannot
3 explain and can and cannot
& Explanation explain
perfectly explain explain
(2)
(3) (1) (1)
Watched other
Present but
Performed students
Performed not
Practical performing
Practical participate
Engagement 2 with other practical but
him/her self in
help not tried him/
(2) performance
(1) her self
(0.5)
(0.5)
Document is Missing
Documented Poor writing,
proper, but output.
properly, no missing
Documentation 1 presentation Improper
error output
is average documentation
(1) (0.25)
(0.5) (0.25)
Complete Complete Work
Submit after 2
within a within two submits after
Time 1 weeks
week weeks 3 weeks.
(0.25)
(1) (0.5) (0.25)

Total

Faculty Signature with Date

BHAGWAN MAHAVIR POLYTECHNIC


42
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Practical 9.1 Develop a program using Scope Resolution Operators.
No: 9

Aim 9.1.1: Write a program to print the Global Variables value using Scope Resolution (::) operator.

Source Code:
//Write a program to print the Global Variables value using Scope Resolution (::) operator
#include <iostream>
using namespace std;
int value = 100;
int main()
{
cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;
int value = 50;
cout << "Local value: " << value << endl;
cout << "Global value: " << ::value << endl;
return 0;
}
Input-Ouput:
Program Created By Vishnu Rawal [En_No.: 2327010701136]

Local value: 50
Global value: 100

=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


43
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Assessment:

Total Marks
Criteria Exceptional Satisfactory Developing Limited
Marks Obtaine
d
Accurately 1-2 errors / 3-5 errors/ More than 5
Accuracy 3 done mistake mistake errors
(3) (2) (1) (1)
Fully under Partially Partially
Understand
stood and understood understood
Understanding but cannot
3 explain and can and cannot
& Explanation explain
perfectly explain explain
(2)
(3) (1) (1)
Watched other
Present but
Performed students
Performed not
Practical performing
Practical participate
Engagement 2 with other practical but
him/her self in
help not tried him/
(2) performance
(1) her self
(0.5)
(0.5)
Document is Missing
Documented Poor writing,
proper, but output.
properly, no missing
Documentation 1 presentation Improper
error output
is average documentation
(1) (0.25)
(0.5) (0.25)
Complete Complete Work
Submit after 2
within a within two submits after
Time 1 weeks
week weeks 3 weeks.
(0.25)
(1) (0.5) (0.25)

Total

Faculty Signature with Date

BHAGWAN MAHAVIR POLYTECHNIC


44
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Practical No: 10.1 Develop a program using various types of constructors and destructors.
10

Aim 10.1.1: Write a program to set Person name and age by using Default Constructor.
Source Code:
// Write a program to set person name and age by using default constructor.
#include<iostream>
using namespace std;

class Person
{
private:
string name; int age;
public:
Person(){

name = "Vishnu";
age = 17;
}
void getdetail(){
cout<<"Name:"<<name<<endl;
cout<<"Age:"<<age;
}
};
int main(){
cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;
Person person_1,person_2;
cout<<"Default Constructor:"<<endl;
person_1.getdetail();
return 0;
}

Input-Output:
Program Created By Vishnu Rawal [En_No.: 2327010701136]

Default Constructor:
Name:Vishnu
Age:17

=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


45
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY

BHAGWAN MAHAVIR POLYTECHNIC


46
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Assessment:

Total Marks
Criteria Exceptional Satisfactory Developing Limited
Marks Obtaine
d
Accurately 1-2 errors / 3-5 errors/ More than 5
Accuracy 3 done mistake mistake errors
(3) (2) (1) (1)
Fully under Partially Partially
Understand
stood and understood understood
Understanding but cannot
3 explain and can and cannot
& Explanation explain
perfectly explain explain
(2)
(3) (1) (1)
Watched other
Present but
Performed students
Performed not
Practical performing
Practical participate
Engagement 2 with other practical but
him/her self in
help not tried him/
(2) performance
(1) her self
(0.5)
(0.5)
Document is Missing
Documented Poor writing,
proper, but output.
properly, no missing
Documentation 1 presentation Improper
error output
is average documentation
(1) (0.25)
(0.5) (0.25)
Complete Complete Work
Submit after 2
within a within two submits after
Time 1 weeks
week weeks 3 weeks.
(0.25)
(1) (0.5) (0.25)

Total

Faculty Signature with Date

BHAGWAN MAHAVIR POLYTECHNIC


47
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Aim 10.1.2: Write a program to set Person name and age by using Parameterized Constructor

Source Code:
// Write a program to set person name and age by using Parameterized constructor.
#include<iostream>
using namespace std;

class Person
{
private:
string name;
int age; public:
Person(string person_name,
int person_age){
name = person_name;
age = person_age;
}
void getdetail(){
cout<<"Name:"<<name<<endl;
cout<<"Age:"<<age;
}
};
int main(){
cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;
Person person_1("Vishnu",17);
cout<<endl<<"Parameterize constructor:"<<endl;
person_1.getdetail();
return 0;
}
Input-Output:
Program Created By Vishnu Rawal [En_No.: 2327010701136]

Parameterize constructor:
Name:Vishnu
Age:17

=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


48
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Aim 10.1.3: Write a program to set Person name and age by using Copy Constructor
Source Code:
//Write a program to set Person name and age by using Copy Constructor
#include <iostream>
using namespace std;
class Person {
private:
string name;
int age;
public:
// Parameterized constructor
Person(string person_name, int person_age)
{
name = person_name;
age = person_age;
}
// Copy constructor
Person(const Person &obj) {
name = obj.name;
age = obj.age;
}
void getdetail() {
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
}
};
int main() {

cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;


cout << "Parameterized constructor:" << endl;
Person person_1("Vishnu", 17);
person_1.getdetail();
cout << endl << "Copy Constructor:" << endl;
Person person_2 = person_1;
person_2.getdetail();
return 0;
}
Input-Output:
Program Created By Vishnu Rawal [En_No.: 2327010701136]

Parameterized constructor:
Name: Vishnu
Age: 17

Copy Constructor:
Name: Vishnu
Age: 17

=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


49
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY

BHAGWAN MAHAVIR POLYTECHNIC


50
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Assessment:

Total Marks
Criteria Exceptional Satisfactory Developing Limited
Marks Obtaine
d
Accurately 1-2 errors / 3-5 errors/ More than 5
Accuracy 3 done mistake mistake errors
(3) (2) (1) (1)
Fully under Partially Partially
Understand
stood and understood understood
Understanding but cannot
3 explain and can and cannot
& Explanation explain
perfectly explain explain
(2)
(3) (1) (1)
Watched other
Present but
Performed students
Performed not
Practical performing
Practical participate
Engagement 2 with other practical but
him/her self in
help not tried him/
(2) performance
(1) her self
(0.5)
(0.5)
Document is Missing
Documented Poor writing,
proper, but output.
properly, no missing
Documentation 1 presentation Improper
error output
is average documentation
(1) (0.25)
(0.5) (0.25)
Complete Complete Work
Submit after 2
within a within two submits after
Time 1 weeks
week weeks 3 weeks.
(0.25)
(1) (0.5) (0.25)

Total

Faculty Signature with Date

BHAGWAN MAHAVIR POLYTECHNIC


51
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY
Aim 10.1.4: Write a program to test the functionalities of Destructor.
Source Code:
//Write a program to test the functionalities of Destructor.
#include <iostream>
using namespace std;

class Person {
private:
string name;
int age;
public:
Person(){
cout<<"Default Constructor:"<<endl;
}
// Parameterized constructor
Person(string person_name, int person_age) {
name = person_name;
age = person_age;
}
// Destructor
void getdetail() {
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
}
~Person() {
cout<< "Object is destroyed."<<endl;
}
};
int main()
{

cout<<"Program Created By Vishnu Rawal [En_No.: 2327010701136]"<<endl<<endl;


cout << "Parameterized constructor:" << endl;

Person person1, person_2("Vishnu", 17);


person_2.getdetail();
return 0;
}
Input-Output:
Program Created By Vishnu Rawal [En_No.: 2327010701136]

Parameterized constructor:
Default Constructor:
Name: Vishnu
Age: 17
Object is destroyed.
Object is destroyed.

=== Code Execution Successful ===

BHAGWAN MAHAVIR POLYTECHNIC


52
I.T. ENGINEERING
BHAGWAN
MAHAVIR
Object Oriented Programming- Practical (2030107302)
UNIVERSITY

BHAGWAN MAHAVIR POLYTECHNIC


53
I.T. ENGINEERING

You might also like