[go: up one dir, main page]

0% found this document useful (0 votes)
185 views17 pages

OOPs USING C++ (202-22) PRACTICAL FILE

OOPS Practical file

Uploaded by

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

OOPs USING C++ (202-22) PRACTICAL FILE

OOPS Practical file

Uploaded by

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

School of Computer Science & Engineering

PRACTICAL FILE
COURSE TITLE: OBJECT ORIENTED PROGRAMMING
USING C++
COURSE CODE: CSE 305

3ND Semester

Bachelor of Technology in Computer Science


and Engineering
(B.Tech CSE)

Submitted To: Submitted By:


Er. Danish Meiraj Anshdeep Chauhan
(Assistant Professor CSE) (72212532)
SUBJECT: OBJECT ORIENTED PROGRAMMING USING C++
(CSE 305)

COURSE OBJECTIVE
The objectives of the course are to have students identify and practice the object-oriented
programming concepts and techniques, practice the use of C++ classes and class libraries,
arrays, inheritance and file I/O stream concepts.

COURSE OUTCOMES
1. Apply object oriented programming techniques and fundamental concepts
to propose solution pertaining to real world problem.
2. Identify and analyze the important concept of classes and object, array,
functions, constructor and destructors
3. Utilize and implement the concepts of method overloading, operator
overloading, in heritance and Pointers.
4. Organize the fundamental concepts and utilize them to implement the
Virtual Functions and Polymorphism.
5. Examine the errors in the developed system and resolve them by applying
the knowledge of exception handling.
6. Design console based, GUI based and web based applications by
implementing various concepts like event handling, applets and database
connectivity
SNO. NAME OF PRACTICAL PAGE
NO.
1. Write a program to find average of two numbers.

2. Write a program to printing results of integer and floating-point division.

3. Write a program to implement various operators.

4. Write a program to find the largest of three numbers.

5. Write a program to check whether a given number is palindrome or not.

6. Write a program to read the enter the elements of an array


and write them.

7. Write a program to perform operations on matrix using


array.

8. Write a program to implement the manipulation of pointer.

9. Write a program to print the cube of a number using function.


10. Write a program to implement the class.

11. Write a program to calculate the sum of two numbers using Constructor and
Destructors.

12. Write a program to implement inheritance.

13. Write a program to implement virtual base class.

14. Write a program to implement operator overloading.

15. Write a program to implement file.


Program No: 1
AIM: Write a program to find average of two numbers.

#include <iostream>
using namespace std;

int main()
{
int num1, num2,sum;
float average;
cout<<"Enter a number: ";
cin>>num1;
cout<<"Enter another number: ";
cin>>num2;
sum=num1+num2;
cout<<"The sum is:\n\n "<< sum << endl;
cout<<endl;
average=(float)sum / 2 ;
cout<<"The average of two number are:\n\n"<<average;
return 0;
}

OUTPUT:

Enter a number: 25
Enter another number: 89
The sum is:
114
The average of two number are:
57
Program No: 2
AIM: Write a program to printing results of integer and floating-point division.

#include <iostream>

using namespace std;

int main()
{
int num1, num2,sum;
float div;
cout<<"Enter a number: ";
cin>>num1;
cout<<"Enter another number: ";
cin>>num2;
sum=num1+num2;
cout<<"The sum is: "<< sum << endl;
cout<<endl;

div=(float)num1 / (float)num2;
cout<<"Division is: ";
cout<<div;
return 0;
}

OUTPUT:

Enter a number: 25
Enter another number: 78
The sum is: 103

Division is: 0.320513


Program No: 3
AIM: Write a program to implement various operators.
#include "iostream"
using namespace std;

int main()
{
int num1, num2,num3;
cout<<"Enter a number: ";
cin>>num1;
cout<<"Enter another number: ";
cin>>num2;
if( num1 > num2 )
{
num3=num1+num2;
cout<<num1<<" "<<"is greater number ";
cout<<num3<<"is addition of two number ";

else
{
num3=num2-num1;
cout<<num3<<" "<<"is greater number " ;
cout<<num3<<"is subtraction of two number ";
}
cout<<endl;
cout<<"after post increment /decrement the value of num1
is:"<<num1++<<" "<<num2--;
cout<<endl;
cout<<"after pre increment /decrement the value of num1
is:"<<++num1<<" "<<--num2;
return 0;
cout<<endl;
}

OUTPUT:

Enter a number: 78
Enter another number: 75
78 is greater number 153is addition of two number
After post increment /decrement the value of num1 is: 78 75
After pre increment /decrement the value of num1 is: 80 73
Program No: 4
AIM: Write a program to find the largest of three numbers..
#include "iostream"
using namespace std;

int main()
{
int num1, num2,num3;
cout<<"Enter a number: ";
cin>>num1;
cout<<"Enter another number: ";
cin>>num2;
cout<<"Enter third number: ";
cin>>num3;
if( (num1 > num2) &&(num1 > num3))
{
cout<<num1<<" "<<"is greater number ";
}

else if(num2 > num3)


{
cout<<num2<<" "<<"is greater number " ;
}
else
{
cout<<num3<<" "<<"is greater number " ;
}
return 0;
}

OUTPUT:

Enter a number: 45
Enter another number: 7
Enter third number: 56
56 is greater number
Program No: 5
AIM: Write a program to check whether a given number is palindrome or
not.
#include "iostream"

using namespace std;


int main()
{
int n,sum=0,temp,r;
cout<<"enter the number";
cin>>n;
temp=n;
while( n > 0)
{
r=n%10;
sum = (sum * 10) + r;
n=n/10;
}
if(temp == sum)
{
cout<<temp<<"is palindrome number";

}
else
{
cout<<temp<<"is not palindrome number";

}
return 0;
}
OUTPUT:

Enter the number353


353 is palindrome number
Program No: 6
AIM: Write a program to read the enter the elements of an array and write
them.
#include "iostream"

using namespace std;


int main()
{
int n,sum=0,temp,r;
cout<<"enter the number";
cin>>n;
temp=n;
while( n > 0)
{
r=n%10;
sum = (sum * 10) + r;
n=n/10;
}
if(temp == sum)
{
cout<<temp<<"is palindrome number";

}
else
{
cout<<temp<<"is not palindrome number";

}
return 0;
}
OUTPUT:

Enter 5 numbers:
45
5
6
78
12
The numbers are: 45 5 6 78 12
Program No:7
AIM: Write a program to perform operations on matrix using array
#include <stdio.h>

int main() {

int r, c, a[100][100], b[100][100], sum[100][100], i, j;

printf("Enter the number of rows (between 1 and 100): ");

scanf("%d", &r);

printf("Enter the number of columns (between 1 and 100): ");

scanf("%d", &c);

printf("\nEnter elements of 1st matrix:\n");

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

for (j = 0; j < c; ++j) {

printf("Enter element a%d%d: ", i + 1, j + 1);

scanf("%d", &a[i][j]);

printf("Enter elements of 2nd matrix:\n");

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

for (j = 0; j < c; ++j) {

printf("Enter element b%d%d: ", i + 1, j + 1);

scanf("%d", &b[i][j]);

// adding two matrices

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


for (j = 0; j < c; ++j) {

sum[i][j] = a[i][j] + b[i][j];

// printing the result

printf("\nSum of two matrices: \n");

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


Enter the number of rows (between 1 and 100): 3
for (j = 0; j < c; ++j) {
Enter the number of columns (between 1 and 100): 3
printf("%d ", sum[i][j]); Enter elements of 1st matrix:
Enter element a11: 1
if (j == c - 1) { 2Enter element a12:
2
printf("\n\n");

} 3Enter element a13: 3


Enter element a21:
} 4

Enter element a22: 8


return 0; Enter element a23: 8
Enter element a31: 9
} Enter element a32: 8
Enter element a33: 8
Enter elements of 2nd matrix:
Enter element b11: 8
Enter element b12:
OUTPUT: 45
Enter element b13:
45
Enter element b21: 9
Enter element b22: 56
Enter element b23: 56
Enter element b31: 56
Enter element b32: 45
Enter element b33: 45
Sum of two matrices:
9 48 48

14 64 64

65 53 53
Program No:8
AIM: Write a program to perform operations on matrix using array
#include <iostream>
using namespace std;
int main()
{
int x = 27;
int *ip;
ip = &x;
cout << "Value of x is : ";
cout << x << endl;
cout << "Value of ip is : ";
cout << ip<< endl;
cout << "Value of *ip is : ";
cout << *ip << endl;
return 0;
}

OUTPUT:

Program No: 9
AIM: Write a program to print the cube of a number using function.
#include<iostream>
using namespace std;
int main()
{

float cube(float); //Function Type is float


float num,cu;

cout<<"Enter Any Number To Find Cube :\t";


cin>>num;

cu=cube(num);
cout<<"Cube Of "<<num<<" is =
"<<cu<<endl<<endl;
return 0;
}

float cube(float a)
{
float cu;
cu=a*a*a;
return(cu);
}
OUTPUT:

Enter Any Number to Find Cube: 9


Cube of 9 is = 729

Program No: 10
AIM: Write a program to implement the class.
#include <iostream>
using namespace std;
class Room {

public:
double length;
double breadth;
double height;

double calculateArea() {
return length * breadth;
}

double calculateVolume() {
return length * breadth *
height;
}
};

int main() {

// create object of Room class


Room room1;
// assign values to data
members
room1.length = 42.5;
room1.breadth = 30.8;
room1.height = 19.2;

// calculate and display the area


and volume of the room
cout << "Area of Room = " <<
room1.calculateArea() << endl;
cout << "Volume of Room = " <<
room1.calculateVolume() << endl;

return 0;
}

OUTPUT:

Area of Room = 1309


Volume of Room = 25132.8
Program No: 11
AIM: Write a program to implement the class.
#include "iostream"
using namespace std;
class point
{
int x, y;
public:
point(int a1, int b1)
{
x = a1;
y = b1;
cout<<“x =” << x <<“\n”;
cout<<“y =” << y <<“\n”;
cout<<“X + Y =” <<x + y;
}
};
int main()
{
point t1 = point(10, 20);
return 0;
}

OUTPUT:

x =10
y =20
X + Y =30

You might also like