OOPs USING C++ (202-22) PRACTICAL FILE
OOPs USING C++ (202-22) PRACTICAL FILE
PRACTICAL FILE
COURSE TITLE: OBJECT ORIENTED PROGRAMMING
USING C++
COURSE CODE: CSE 305
3ND Semester
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.
11. Write a program to calculate the sum of two numbers using Constructor and
Destructors.
#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>
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
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 ";
}
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"
}
else
{
cout<<temp<<"is not palindrome number";
}
return 0;
}
OUTPUT:
}
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() {
scanf("%d", &r);
scanf("%d", &c);
scanf("%d", &a[i][j]);
scanf("%d", &b[i][j]);
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()
{
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:
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() {
return 0;
}
OUTPUT:
OUTPUT:
x =10
y =20
X + Y =30