Oops Practical
Oops Practical
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
int main() {
int n;
std::cout << "Enter the number of terms in the square series: ";
std::cin >> n;
return 0;
}
OUTPUT.5
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
10 9 8 7 6 5 4 3 2 1
PROGRAM.7
#include <iostream>
int main() {
int n;
cin >> n;
if (n < 0)
else {
factorial *= i;
cout << "Factorial of " << n << " = " << factorial;
return 0;
}
OUTPUT.7
Factorial of 5 = 120
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: x: 1, y: 2
PROGRAM.9
#include <iostream>
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
#include <iostream>
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
#include <iostream>
class Operate
public:
void fun();
};
int main ()
Operate op;
op.fun();
return 0;
}
OUTPUT.11
#include <iostream>
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
Object is being created
Length of line : 6
PROGRAM.13
#include <iostream>
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>
class Animal {
public:
void eat() {
void sleep() {
};
public:
void bark() {
cout << "I can bark! Woof woof!!" << endl;
};
int main() {
Dog dog1;
dog1.eat();
dog1.sleep();
dog1.bark();
return 0;
OUTPUT.14
I can eat!
I can sleep!
PROGRAM.15
#include <iostream>
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>
class Base {
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");
fout<<rno<<"\t"<<name<<"\t"<<fee; //write data to the file student
fout.close();
ifstream fin("d:/student.doc");
fin.close();
cout<<endl<<rno<<"\t"<<name<<"\t"<<fee;
return 0;
OUTPUT.17
Enter the Roll Number:23
23 mayank 90000
PROGRAM.18
#include <iostream>
return (x > y) ? x : y;
int main()
return 0;
OUTPUT.18
7
PROGRAM.19
#include <iostream>
int main() {
return 0;
OUTPUT.19
Sum 1 = 11
Sum 2 = 12.1
Sum 3 = 18