Oops File Demo
Oops File Demo
Class/Section : CSE-C
Program -1
Code :
#include<iostream>
int main()
int x, y;
int sum;
cin >> y;
sum = x + y;
return 0;
}
Output :
Program -2
Code :
#include<iostream>
int main()
{
int integerType;
char charType;
float floatType;
double doubleType;
cout << "Size of int is: " <<
sizeof(integerType) <<"\n";
sizeof(charType) <<"\n";
sizeof(floatType) <<"\n";
sizeof(doubleType) <<"\n";
return 0;
}
Output:
Program -3
Code :
#include<iostream>
Using namespace std;
int main()
{
int n, reverse=0, rem;
cout<<"Enter a number: ";
cin>>n;
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}
cout<<"Reversed Number: "<<reverse<<endl;
return 0;
Output:
Program -4
Aim : C++ Program to generate all the prime no. between 1 to n,where n is the
value by user.
Code :
#include<iostream>
int main()
cout << endl << "All prime numbers upto " << upto << " are : " << endl;
if(num % i == 0)
i = num;
break;
if(i != num)
return 0;
}
Output:
Program -5
Aim : C++ Program to find both the largest and smallest number in a list of
integers.
Code :
#include<iostream>
int main ()
cin >> n;
max = arr[0];
max = arr[i];
min = arr[0];
min = arr[i];
return 0;
OUTPUT:
Program -6
Code :
#include <iostream>
int main()
int x,y,sum;
float average;
cout << "Enter 2 integers : " << endl;
cin>>x>>y;
sum=x+y;
average=sum/2;
cout << "The sum of " << x << " and " << y << " is " << sum << "." << endl;
cout << "The average of " << x << " and " << y << " is " << average << "." << endl;
OUTPUT :
Program -7
Aim : Program for swapping of two numbers without using third variable.
Code :
#include <iostream>
using namespace std;
int main()
return 0;
OUTPUT :
Program -8
Code :
#include <iostream>
// Drivers code
int main()
return 0;
OUTPUT :
Program -9
Code :
#include <iostream>
int main()
cin >> n;
m=n/2;
{
if(n % i == 0)
flag=1;
break;
if (flag==0)
return 0;
OUTPUT :
Program -10
Aim : Program for switch case having :
1 .Factorial of a number.
Code :
#include <iostream>
int main()
int i,fact=1,number;
cin>>number;
for(i=1;i<=number;i++){
fact=fact*i;
return 0;
OUTPUT :
2.Even and odd number
Code :
#include <iostream>
int main()
int num1=452;
int num2=591;
case 0:
break;
case 1:
return 0;
OUTPUT :
Code :
#include<iostream>
int year;
int main()
{
switch (year % 4)
case 0:
if (year % 100 == 0)
if (year % 400 == 0)
else
cout << " " << year << " isn't a leap year." << endl;
else
break;
case 3:
cout << year << " isn't a leap year." << endl;
break;
OUTPUT :
4.Exit
Code :
#include<iostream>
#include<stdlib.h>
char ch;
while(true)
cout<<"enter choice"<<endl;
cin>>ch;
switch(ch)
case 'l':
break;
case 'c':
break;
case 'q':
exit(0);
default:
return 0;
}
OUTPUT :
Program -11
Code :
#include <iostream>
#include <string>
int main() {
myObj.myNum = 15;
// Print values
return 0;
OUTPUT :
Program -12
Code :
#include <iostream>
class Box {
public:
double getVolume(void);
};
double Box::getVolume(void) {
}
void Box::setLength( double len ) {
length = len;
breadth = bre;
height = hei;
int main() {
// box 1 specification
Box1.setLength(6.0);
Box1.setBreadth(7.0);
Box1.setHeight(5.0);
// box 2 specification
Box2.setLength(12.0);
Box2.setBreadth(13.0);
Box2.setHeight(10.0);
// volume of box 1
volume = Box1.getVolume();
// volume of box 2
volume = Box2.getVolume();
return 0;
OUTPUT :
Program -13
Code :
#include<iostream>
int main()
int i;
for (i=0;i<6;i++)
return 0;
OUTPUT :
Program -14
Code :
#include <iostream>
int main()
cin >> r;
cin >> c;
cout << endl << "Enter elements of 1st matrix: " << endl;
cout << "Enter element a" << i + 1 << j + 1 << " : ";
cout << endl << "Enter elements of 2nd matrix: " << endl;
cout << "Enter element b" << i + 1 << j + 1 << " : ";
cout << endl << "Sum of two matrix is: " << endl;
if(j == c - 1)
return 0;
OUTPUT :
Program -15
Code :
#include <iostream>
class Demo
private:
static int X;
static int Y;
public:
};
int main()
Demo OB;
OB.Print();
Demo::Print();
return 0;
OUTPUT :
Program -16
Aim : Program for implementing static data member inside the class.
Code :
#include <iostream>
#include<string.h>
class Student {
private:
int rollNo;
char name[10];
int marks;
public:
Student() {
objectCount++;
void getdata() {
void putdata() {
cout<<endl;
};
int Student::objectCount = 0;
int main(void) {
Student s1;
s1.getdata();
s1.putdata();
Student s2;
s2.getdata();
s2.putdata();
Student s3;
s3.getdata();
s3.putdata();
cout << "Total objects created = " << Student::objectCount << endl;
return 0;
OUTPUT :
Program -17
Code :
#include <iostream>
class Rectangle
public:
int length;
int breadth;
length = l;
breadth = b;
int printArea()
};
int main()
Rectangle rt1( 7, 4 );
Rectangle rt2( 4, 5 );
cout << "Area of first rectangle " << rt1.printArea() << endl;
cout << "Area of second rectangle " << rt2.printArea() << endl;
return 0;
OUTPUT :
Program -18
Code :
#include<iostream>
//Create a class
class MyClass{
}
};
int main() {
return 0;
}
OUTPUT :
Program -19
Code :
#include<iostream>
//Function Declaration
int main() {
int a=100;// Variable Declaration
int b=200;
return 0;
}
void swap(int x, int y){
int temp;
temp=x;
x=y;
y=temp;
return ;
}
OUTPUT :
Program -20
Code :
#include<iostream>
swap = *x;
*x = *y;
*y = swap ;
}
int main()
{
int x = 500, y = 100;
swap(&x,&y);// passing value to function
return 0 ;
}
OUTPUT :
Program -21
Code :
#include<iostream>
int main()
{
int x = 5;
return 0;
}
OUTPUT :
Program -24
Code :
#include<iostream>
displayNum(5);
displayNum(8);
displayNum(666);
return 0;
OUTPUT :
Program -25
Aim : Program for implementing addition of two numbers with the help of
multiple inheritance.
Code :
#include <iostream
class input1
public:
int a;
void getinput1()
cin>>a;
}
};
class input2
public:
int b;
void getinput2()
cin>>b;
};
public:
int c,d,e;
void sum()
c=a+b;
void product()
{
d=a*b;
void divide()
e=a/b;
};
int main()
addition a1;
a1.getinput1();
a1.getinput2();
a1.sum();
a1.product();
return 0;
OUTPUT :
Program -26
Code :
#include<iostream>
class Time
int hour;
int minute;
public :
int main( )
OUTPUT :
Program -27
Code :
#include <iostream>
class DemoDC {
private:
public:
DemoDC() {
num1 = 10;
num2 = 20;
}
void display() {
};
int main() {
DemoDC obj;
obj.display();
return 0;
OUTPUT :
Program -28
Code :
#include <iostream>
class ParamA {
private:
int b, c;
public:
b = b1;
c = c1;
int getX ()
return b;
int getY ()
return c;
};
int main ()
return 0;
OUTPUT :
Program -29
Code :
#include <iostream>
class A
public:
int x;
A(int a) // parameterized constructor.
x=a;
x = i.x;
};
int main()
cout<<a2.x;
return 0;
OUTPUT :
Program -30
Code :
#include <iostream>
class Person {
private:
int age;
public:
Person() {
age = 20;
}
Person(int a) {
age = a;
int getAge() {
return age;
};
int main() {
return 0;
OUTPUT :
Program -31
Code :
#include<iostream>
class demo
private:
int a;
float b;
public:
demo();
};
demo::demo()
{
cout<<"Enter the value of a and b :";
cin>>a>>b;
cout<<"a = "<<a<<endl;
cout<<"b = "<<b<<endl;
int main()
demo d1;
OUTPUT :
Program -32
Code :
#include<iostream>
void fun()
public:
void method() {
};
Test t;
t.method();
int main()
fun();
return 0;
}
OUTPUT :
Program -38
Code :
#include <iostream>
public:
int x;
void getdata()
{
};
private:
int y;
public:
void readdata()
void product()
};
int main()
a.getdata();
a.readdata();
a.product();
return 0;
} //end of program
OUTPUT :
Program -39
Code :
#include <iostream>
class A
public:
void display()
{
cout<<"Base class content.";
};
class B : public A
};
class C : public B
};
int main()
C obj;
obj.display();
return 0;
OUTPUT :
Program -40
Code :
#include <iostream>
class Mammal {
public:
Mammal()
};
class WingedAnimal {
public:
WingedAnimal()
};
};
int main()
Bat b1;
return 0;
OUTPUT :
Program -41
Code :
#include <iostream>
public:
int x, y;
void getdata()
};
class B : public A //B is derived from class base
public:
void product()
};
public:
void sum()
};
int main()
obj1.getdata();
obj1.product();
obj2.getdata();
obj2.sum();
return 0;
} //end of program
OUTPUT :
Program -42
Code :
#include<iostream>
#include<string>
class student
public:
student()
{
cout<<"Hello I am a student"<<endl;
};
public:
student1()
cout<<"Student of CSE-C"<<endl;
string name="Yashi";
};
class student2
public:
void display()
cout<<"Rollno 50"<<endl;
};
class student3:public student2
};
};
int main()
student1 obj;
student2 obj1;
cout<<"Name:"<<obj.name<<endl;
cout<<"collegeName:"<<obj.collegeName<<endl;
obj1.display();
return 0;
OUTPUT :
Program -43
Code :
#include <iostream>
// base class
class Parent
public:
Parent()
};
// sub class
public:
Child()
};
// main function
int main() {
Child obj;
return 0;
OUTPUT :
Program -44
Code :
#include <iostream>
class over
public:
int get(int,int,int);
float get(float,float,float);
float get(int,int,float);
};
{
if(a>b&&a>c)
return a;
else
if(b>a&&b>c)
return b;
else
return c;
if(a>b&&b>c)
return a;
else
if(b>a&&b>c)
return b;
else
return c;
{
if(a>b&&a>c)
return a;
else
if(b>a&&b>c)
return b;
else
return c;
int main()
int n1,n2,n3,t;
float x,y,z;
over obj;
cin>>n1>>n2>>n3;
t=obj.get(n1,n2,n3);
cin>>x>>y>>z;
float temp=obj.get(x,y,z);
return 0;
}
OUTPUT :
Program -45
Code :
#include <iostream>
class demo
public:
int a,b;
demo()
{}
demo(int p,int q)
a=p;
b=q;
void show()
cout<<"\nvalue of a="<<a;
cout<<"/nvalue of b="<<b;
dp.a=a+dx.a;
dp.b=b+dx.b;
return dp;
a=++a;
b=++b;
a=a++;
b=b++;
};
int main()
demo d1(1,2),d2(3,4),d3;
d3=d1+d2;
d3.show();
++d3;
d3.show();
d3++;
d3.show();
return 0;
}
OUTPUT :
Program -47
Code :
#include <iostream>
class A {
public:
void disp(){
};
class B: public A{
public:
void disp(){
};
int main() {
A obj;
obj.disp();
B obj2;
obj2.disp();
return 0;
OUTPUT :
Program -48
Code :
#include <iostream>
class gshape
public:
float ar,pr;
};
public:
void getarea(float r)
ar=3.14*r*r;
void getperi(float r)
pr=2*3.14*r;
void showar()
{
void showpr()
};
public:
ar=l*b;
pr=2*l+2*b;
void showar()
}
void showpr()
};
int main(void)
gshape *gptr;
circle c;
gptr=&c;
c.getarea(2);
c.getperi(3);
gptr->showar();
gptr->showpr();
Rectangle r;
gptr=&r;
r.getarea(6,7);
r.getperi(2,2);
gptr->showar();
gptr->showpr();
return 0;
}
OUTPUT :
Program -49
Aim : Program for implementing addition of two numbers with the help of
multilevel inheritance.
Code :
#include <iostream>
#include<cmath>
class input
{
public:
int a,b;
void getinput()
cin>>a>>b;
};
public:
int c;
void sum()
c=a+b;
};
public:
int s;
void sqr()
{
s=c*c;
};
public:
int r;
void root()
r=sqrt(s);
};
int main()
squareroot a1;
a1.getinput();
a1.sum();
a1.sqr();
a1.root();
return 0;
}
OUTPUT :
Program -50
class over
public:
int get(int,int,int);
float get(float,float,float);
float get(int,int,float);
};
if(a>b&&a>c)
return a;
else
if(b>a&&b>c)
return b;
else
return c;
if(a>b&&b>c)
return a;
else
if(b>a&&b>c)
return b;
else
return c;
if(a>b&&a>c)
return a;
else
if(b>a&&b>c)
return b;
else
return c;
int main()
int n1,n2,n3,t;
float x,y,z;
over obj;
cin>>n1>>n2>>n3;
t=obj.get(n1,n2,n3);
cin>>x>>y>>z;
float temp=obj.get(x,y,z);
return 0;
OUTPUT :