Oops Practical
Oops Practical
INDEX
CONTENT SIGNA
S.N PAG
TURE
O E
No.
1. Write a program in c++ to
find the area and perimeter of
a rectangle.
2. Write a program in c++ to
calculate the square of a
number using math.h header
file
3. Write a program in c++ to
find that a no. is even or odd.
4. Write a program in c++ to
find greater no. between two
no.
5. Write a program in c++ to
display the square series
using loop.
6. Write a program in c++ to
display reverse natural series
using loop.
7. Write a program in c++ to
calculate the factorial of a
given number.
8. Write a program in c++ to
display call by value function.
9. Write a program in c++ to
display function overloading
10. Write a program in c++ to
display the class.
11. Write a program in c++ to
display a class using scope
resolution operator.
12. Write a program in c++
display constructor and
destructor.
13. Write a program in c++ to
display operator overloading .
14. Write a program in c++ to
display single inheritance.
15. Write a program in c++ to
display multiple inheritance.
16. Write a program in c++ to
display virtual function
17. Write a program in c++ for
file handeling.
18. Write a program in c++ to
display template.
19. Write a program in c++ to
display polymorphism .
PROGRAM.1
#include<iostream>
using namespace std;
int areaRectangle(int a, int b)
{
int area = a * b;
return area;
}
int perimeterRectangle(int a, int b)
{
int perimeter = 2*(a + b);
return perimeter;
}
int main()
{
int a = 5;
int b = 6;
cout << "Area = " <<
areaRectangle(a, b) <<
endl;
cout << "Perimeter = " <<
perimeterRectangle(a, b);
return 0;
}
OUTPUT.1
Area = 30
Perimeter = 22
PROGRAM.2
#include <iostream>
#include <cmath>
int main() {
double number, square;
std::cout << "The square of " << number << " is: " << square << std::endl;
return 0;
}
OUTPUT.2
Enter a number: 5
The square of 5 is: 25
PROGRAM.3
#include <iostream>
using namespace std;
int main() {
int n;
if ( n % 2 == 0)
cout << n << " is even.";
else
cout << n << " is odd.";
return 0;
}
OUTPUT.3
Enter an integer: 4
4 is even.
PROGRAM.4
#include <iostream>
int main() {
double num1, num2;
std::cout << "Enter the first number: ";
std::cin >> num1;
return 0;
}
OUTPUT.4
Enter the first number: 50
Enter the second number: 20
50 is the largest number.
PROGRAM.5
#include <iostream>
int main() {
int n;
std::cout << "Enter the number of terms in the square series: ";
std::cin >> n;
return 0;
}
OUTPUT.5
PROGRAM.6
#include<iostream>
using namespace std;
int main()
int number;
cout << "\nPlease Enter Maximum Value to print Natural Numbers = ";
cout << "\nList of Natural Numbers from " << number << " to 1 are\n";
return 0;
OUTPUT.6
Please Enter Maximum Value to print Natural Numbers
= 10
10 9 8 7 6 5 4 3 2 1
PROGRAM.7
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
if (n < 0)
else {
factorial *= i;
cout << "Factorial of " << n << " = " << factorial;
return 0;
OUTPUT.7
PROGRAM.8
#include <iostream>
int t = x;
x = y;
y = t;
int main(){
int x = 1, y = 2;
cout << "x: " << x << ", y: " << y << endl;
swap(x, y);
cout << "x: " << x << ", y: " << y << endl;
return 0;
OUTPUT.8
Before Swapping: x: 1, y: 2
After Swapping in function x: 2, y: 1
After Swapping: x: 1, y: 2
PROGRAM.9
#include <iostream>
using namespace std;
var = -var;
return var;
if (var < 0)
var = -var;
return var;
int main() {
cout << "Absolute value of 5.5 = " << absolute(5.5f) << endl;
return 0;
OUTPUT.9
Absolute value of -5 = 5
Absolute value of 5.5 = 5.5
PROGRAM.10
#include <iostream>
using namespace std;
class Room {
public:
double length;
double breadth;
double height;
double calculateArea() {
double calculateVolume() {
};
int main() {
Room room1;
room1.length = 42.5;
room1.breadth = 30.8;
room1.height = 19.2;
return 0;
OUTPUT.10
PROGRAM.11
#include <iostream>
using namespace std;
class Operate
public:
void fun();
};
int main ()
Operate op;
op.fun();
return 0;
OUTPUT.11
#include <iostream>
using namespace std;
class Line {
public:
private:
double length;
};
Line::Line(void) {
Line::~Line(void) {
length = len;
}
return length;
int main() {
Line line;
line.setLength(6.0);
return 0;
OUTPUT.12
PROGRAM.13
#include <iostream>
using namespace std;
class Count {
private:
int value;
public:
Count() : value(5) {}
void operator ++ () {
++value;
value++;
void display() {
};
int main() {
Count count1;
count1++;
count1.display();
++count1;
count1.display();
return 0;
OUTPUT.13
Count: 6
Count: 7
PROGRAM.14
#include <iostream>
using namespace std;
class Animal {
public:
void eat() {
void sleep() {
};
public:
void bark() {
}
};
int main() {
Dog dog1;
dog1.eat();
dog1.sleep();
dog1.bark();
return 0;
OUTPUT.14
I can eat!
I can sleep!
PROGRAM.15
#include <iostream>
using namespace std;
class A {
protected:
int a;
public:
void get_a(int n) {
a = n;
};
class B {
protected:
int b;
public:
void get_b(int n) {
b = n;
};
public:
void display()
};
int main()
C c;
c.get_a(10);
c.get_b(20);
c.display();
return 0;
OUTPUT.15
The value of a is : 10
The value of b is : 20
Addition of a and b is : 30
PROGRAM.16
#include <iostream>
public:
}};
public:
void print() {
}};
int main() {
Derived derived1;
base1->print();
return 0;
OUTPUT.16
Derived Function
PROGRAM.17
#include<iostream>
#include<fstream>
main()
int rno,fee;
char name[50];
cin>>rno;
cin>>name;
cin>>fee;
ofstream fout("d:/student.doc");
ifstream fin("d:/student.doc");
fin.close();
cout<<endl<<rno<<"\t"<<name<<"\t"<<fee;
return 0;
OUTPUT.17
23 mayank 90000
PROGRAM.18
#include <iostream>
using namespace std;
return (x > y) ? x : y;
int main()
return 0;
OUTPUT.18
7
7
PROGRAM.19
#include <iostream>
int main() {
return 0;
OUTPUT.19
Sum 1 = 11
Sum 2 = 12.1
Sum 3 = 18