PG OOPS
PG OOPS
PG OOPS
WOMEN
Avaniyapuram
Madurai-12
CLASS :I-M.SC(CS)
SUBJECT : OOPS LAB
SUBJECTCODE :
YEAR : 2023 - 2024
NMS SERMATHAI VASAN COLLEGE FOR WOMEN
Avaniyapuram
Madurai-12
BONAFIDE CERTIFICATE
Date: StaffIncharge
ExternalExaminer ExternalExaminer
INDEX
S.NO DATE TOPIC PAGE NO SIGNATURE
1 Stack using array
3 Merge short
6 Heap tree
7 Tree traversal
8 Greedy method
9 2 Queen attack
10 Friend function
11 Inline function
12 Virtual function
13 Function overloading
14 Single inheritance
15 Multilevel inheritance
16 Multiple inheritance
17 Hierarchical inheritance
18 Constructor
19 Electricity bill
EX NO : 1
SOURCE CODE :
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class stack
{
int stack1[10];
int top;
public:
stack()
{
Top=-1;
}
void push(int x)
{
if(top>4)
{
Cout<<”stack over flow”;
return;
}
stack1[++top]=x;
cout<<”Inserted”<<x;
}
void pop()
{
if(top<0)
{
Cout<<”stack under flow”;
return;
cout<<”deleted”<<stack1[top--];
}
Void display()
{
if(top<0)
{
Cout<<”stack is empty”;
return;
}
For(int i=top;i>=0;i--)
{
Cout<<stack[i]<<””;
}
}
};
Void main()
{
Int ch;
Stack s;
Clrscr();
While(1)
{
Cout<<”\n 1.push\n 2.pop\n 3.display\n 4.exit\n”;
Cout<<”enter your choice”;
Cin>>ch;
Switch(ch)
{
Case 1:cout<<”Enter the element”;
Cin>>ch;
s.push(ch);
break;
case2:s.pop();
break;
case3:s.display();
break;
case4:exit(0);
break;
}
}
getch();
}
OUTPUT :
1. Push
2. Pop
3. Display
4. Exit
Enter Your Choice : 1
Enter The Element : 12
Inserted 12
1.Push
2.Pop
3.Display
4.Exit
Enter Your Choice : 1
Entr The Element : 23
Inserted 23
1.Push
2.Pop
3.Display
4.Exit
Enter Your Choice : 3
23 12
1. Push
2.Pop
3.Display
4.Exit
Enter Your Choice : 2
Deleted 23
1.Push
2.Pop
3.Display
4.Exit
Enter Your Choice : 3
12
1.Push
2.Pop
3.Display
4.Exit
Enter Your Choice : 4
RESULT :
SOURCE CODE :
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
Struct node
{
Int data;
Struct node*next;
};
Class stack
{
Struct node*top;
Public:
Stack()
{
Top=NULL;
}
Void push();
Void pop();
Void show();
};
Void stack::push()
{
Int value;
Struct node*ptr;
Cou<<”PUSH OPERATION”;
Cout<<”NULL\n”;
}
Void main()
{
Int ch;
Stack s;
Clrscr();
While(1)
{
Cout<<”\n 1.push\n 2.pop\n 3.display\n 4.exit\n”;
Cout<<”enter your choice”;
Cin>>ch;
Switch(ch)
{
Case 1: s.push(ch);
break;
case2:s.pop();
break;
case3:s.display();
break;
case4:exit(0);
break;
}
} getch();
OUTPUT :
1. Push
2. Pop
3. Display
4. Exit
Enter Your Choice : 1
PUSH OPERATION
Enter The Element to Insert : 12
New item is inserted to the stack
1.Push
2.Pop
3.Display
4.Exit
Enter Your Choice : 1
PUSH OPERATION
Enter The Element to Insert : 23
New item is inserted to the stack
1.Push
2.Pop
3.Display
4.Exit
Enter Your Choice : 3
PUSH OPERATION
Enter The Element to Insert : 34
New item is inserted to the stack
1. Push
2.Pop
3.Display
4.Exit
Enter Your Choice : 3
The stack is:
34 -> 23-> 12 -> NULL
1.Push
2.Pop
3.Display
4.Exit
Enter Your Choice : 2
Poped value is :34
1.Push
2.Pop
3.Display
4.Exit
Enter Your Choice : 3
The stack is :
23 -> 12 -> NULL
1.Push
2.Pop
3.Display
4.Exit
Enter Your Choice : 4
RESULT :
MERGE SHORT
AIM :
To write a python program for merge short.
SOURCE CODE :
EX NO :4
QUEUE USING ARRAY
AIM:
To write a c++ program for queue using array.
SOURCE CODE :
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class queue
{
int queue1[10];
int rear,front;
public:
queue()
{
rear=-1;
front=-1;
}
void insert(int x)
{
if(rear>4)
{
Cout<<”queue over flow”;
Front=rear=-1;
return;
}
queue1[++rear]=x;
cout<<”Inserted”<<x;
}
void delete()
{
if(front==rear)
{
cout<<”queue under flow”;
return;
cout<<”deleted”<<queue1[++front];
}
void display()
{
if(rear==front)
{
cout<<”queue is empty”;
return;
}
for(int i=frony;i<=rear;i++)
{
cout<<queue1[i]<<””;
}
}
};
void main()
{
int ch;
queue q;
clrscr();
while(1)
{
cout<<”\n 1.insert\n 2.delete\n 3.display\n 4.exit\n”;
cout<<”enter your choice”;
cin>>ch;
switch(ch)
{
case 1:cout<<”enter the element”;
cin>>ch;
q.insert(ch);
break;
case2:q.delete();
break;
case3:q.display();
break;
case4:exit(0);
break;
}
}
getch();
}
OUTPUT :
1. Insert
2. Delete
3. Display
4. Exit
Enter Your Choice : 1
Enter The Element : 12
Inserted 12
1.Insert
2.Delete
3.Display
4.Exit
Enter Your Choice : 1
Entr The Element : 23
Inserted 23
1.Push
2.Pop
3.Display
4.Exit
Enter Your Choice : 3
23 12
1. Push
2.Pop
3.Display
4.Exit
Enter Your Choice : 2
Deleted 23
1.Push
2.Pop
3.Display
4.Exit
Enter Your Choice : 3
12
1.Push
2.Pop
3.Display
4.Exit
Enter Your Choice : 4
RESULT :
SOURCE CODE :
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
Struct node
{
Int data;
Struct node*next;
};
Struct node*rear,*front;
Public:
queue()
{
rear=NULL;
front=NULL;
}
Void insert();
Void delete();
Void show();
};
Void queue::insert()
{
Int value;
Struct node*ptr;
Cou<<”INSERT OPERATION”;
Cin>>value;
Ptr=new node;
Ptr->data=value;
Pytr->next=NULL;
If(front==NULL)
front=ptr;
else
rear->next=ptr;
rear=ptr;
Cout<<”\n new item is inserted to the queue”;
}
Void queue::deleted()
{
Struct node*temp;
If(front==NULL)
{
Cout<<”\n the queue is empty!!”;
}
Else
{
Temp=front;
front=temp->next;
cout<<”DELETE OPERATION\n”;
Cout<<”delete value is “<<temp->data;
Delete temp;
}
Void queue::show()
{
Struct node*ptr1=front;
Cout<<”\n the queue is:\n”;
While(ptr1!=NULL)
{
Cout<<”ptr1->data<<”->”;
Ptr1=ptr1->next;
}
Cout<<”NULL\n”;
}
Void main()
{
Int ch;
Queue q;
Clrscr();
While(1)
{
Cout<<”\n 1.INSERT\n 2.DELETE\n 3.DISPLAY\n 4.EXIT\n”;
Cout<<”enter your choice”;
Cin>>ch;
Switch(ch)
{
Case1:q.insert();
break;
case2:q.delete();
break;
case3:q.display();
break;
case4:exit(0);
break;
}
}
getch();
}
OUTPUT :
1.insert
2.delete
3.show
4.exit
INSERT OPERATION
1.insert
2.delete
3.show
4.exit
DELETE OPERATION
Delete value is : 22
1.insert
2.delete
3.show
4.exit
SHOW OPERATION
The queue is NULL
1.insert
2.delete
3.show
4.exit
RESULT :
SOURCE CODE :
#include<iostdio.h>
#include<conio.h>
void heapsort(iont[],int);
void buildheap(int[],int);
void satidsfyheap(int[],int,int);
void main()
{
clrscr();
int a[10],i,size;
cout<<"Enter the size of List\n";
cin>>size;
cout<<"Enter"<<size<<"element \n";
for(i=0;i<size;i++)
{
cin>>a[i];
}
heapsort
getch();
void heapsort(int a[],int length)
{
buildheap(a,length);
int heapsize,i,temp;
heapsize=length-1;
for(i=heapsize;i>=0;i--)
{
tem=1[0]
a[0]=a[heapsize];
a[heapsize]=temp;
heapsize--;
satisfyheap(a,o,heapsize);
}
for(i=0;i<length;i++)
{
cout<<"\t'<<a[i];
}
}
void buildheap(int a[],int length)
{
int i,heapsize;
heapsize=length-1;
for(i=(length/2);i>=0;i--)
{
satisfyheap(a,i,heapsize);
}
}
void satisfyheap(int a[],int i,int heapsize)
{
int l,r,largerst,temp;
L=2*i;
r=2*i=1;
if(1<heapsize && a[1]>a[i])
{
Largerst=1;
}
else
{
Largerst=i;
}
if(r<=heapsize && a[r]>a[Largert])
{
Largerst=r;
}
if(Largerst!=i)
{
temp=a[i];
a[i]=a[Largest];
a[Largerst]=temp;
satisfyheap(a,Largerst,heapsize);
}
}
OUTPUT :
Enter the sze of list
Enter 6 elements
34
65
54
78
23
12
78 65 54 34 23 12
RESULT :
TREE TRAVERSAL
AIM :
To write a python program for tree traversal.
SOURCE CODE :
EX NO : 10
FRIEND FUNCTION
AIM :
To write a c++ program for friend function.
SOURCE CODE :
#include<iostream.h>
#include<conio.h>
class mean
{
int x,y;
public:
void assign(int a,int b);
friend int output(mean m);
};
void mean :: assign(int a,int b)
{
x=a;
y=b;
}
int output(mean m)
{
int z;
z=(m.x+m.y)/2;
return(z);
}
void main()
{
int a. b;
mean m;
clrscr();
cout<<endl<<”Enter two value to find mean”<<endl;
cout<<endl<<”Number 1”<<endl;
cin>>a;
cout<<endl<<”Number 2”<<endl;
cin>>b;
m.assign(a,b);
cout<<”mean of two numbers:”<<a<<”and”<<b<<”=”<<output(m);
getch();
}
OUTPUT :
RESULT :
AIM :
SOURCE CODE :
#include<iostream.h>
#include<conio.h>
inline int add(int a1,int b1)
{
return(a1+b1);
}
inline float mul(float x1,float y1)
{
return(x1*y1);
}
inline doublediv(double p1,double q1)
{
return(p1/q1);
}
void main()
{
int a,b;
float x,y;
double p,q;
clrscr();
cout<<”Enter the value of addition\n”;
cin>>a>>b;
cout<<”Enter the value of multiplication\n”;
cin>>x>>y;
cout<<”Enter the value of division\n”;
cin>>p>>q;
cout<<”Addition=”<<add(a,b)<<”\n”;
cout<<”Multiplication=”<<mul(x,y)<<”\n”;
cout<<”Division=”<<div(p,q)<<”\n”;
getch();
}
OUTPUT :
10 40
45.6 70.4
12345 56789
Addition=50
Multiplication=3210.23999
Division=0.217384
RESULT :
AIM :
SOURCE CODE :
#include<iostream.h>
#include<conio.h>
class colour
{
public:
vritual void print()
{
cout<<”blue color”<<endl;
}
};
class d;public color
{
public:
void print()
{
cout<<”pinck color”<<endl;
}
};
int main()
{
clrscr();
color*b1;
D d;
b1=&d;
b1->print();
getch();
return 0;
}
OUTPUT :
Pinck color
RESULT :
FUNCTION OVERLOADING
AIM :
SOURCE CODE :
#include<iostream.h>
#include<conio.h>
float area(int a)
{
return a*a;
}
float area(float rad)
{
return 3.14*(rad*rad);
}
float area(int l,int b)
{
return l*b;
}
void main()
{
int ch,a,l,b;
float r;
clrscr();
cout<<”1.square\n2.circle\n3.rectangle\n”;
cout<<”Enter choice:”;
cin>>ch;
if(ch==1)
{
cout<<”enter the value:”;
cin>>a;
cout<<”\nArea of square:”<<area(a);
}
else if(ch==2)
{
cout<<”Enter radius for circle:”;
cin>>r;
cout<<”\nArea of circle is:”<<area(r);
}
else
{
cout<<”Enter length:”;
cin>>l;
cout<<”Enter breadth:”;
cin>>b;
cout<<”Area of rectangle is:”<<area(l,b);
}
getch();
}
OUTPUT:
1.square
2.circle
3.rectangle
Enter choice:1
Enter a value:10
Area of square:100
RESULT :
SINGLE INHERITANCE
AIM :
SOURCE CODE :
#include<iostream.h>
#include<conio.h>
class base
{
int reg no;
public:
char course[10];
int no;
void assign();
};
class derived: public base
{
int m1,m2,m3,tot;
public:
void input();
void display();
};
void base::assign()
{
cout<<”enter reg no”<<endl;
cin>>reg no;
no= reg no;
cout<<”enter course”<<endl;
cin>>course;
}
void derived::input()
{
cout<<”enter the marks”;
cin>>m1>>m2>>m3;
}
void derived::display()
{
cout<<”reg.no=”<<no<<endl;
cout<<”course=”<<course<<endl;
cout<<”mark1=”<<m1<<endl;
cout<<”mark2=”<<m2<<endl;
cout<<”mark3=”<<m3<<endl;
cout<<”total=”<<m1+m2+m3;
}
void main()
{
clrscr();
derived d;
d.assign();
d.input();
d.display();
getch();
}
OUTPUT :
Enter reg no:
Enter course:
99
100
reg no=3
course=6
mark1=98
mark2=99
mark3=100
total=287
RESULT :
Thus the program was executed successfully.
EX NO :15
MULTILEVEL INHERITANCE
AIM :
SOURCE CODE :
#include<iostream.h>
#include<conio.h>
class invent
{
public:
int ino,pri,qty;
char ina[20];
void get()
{
cout<<”\n item number”;
cin>>ino;
cout<<”\n item name”;
cin>>ina;
cout<<”\n item price”;
cin>>pri;
cout<<”\n quantity”;
cin>>qty;
}
};
class discount:public invent
{
public:
int dis,amt,p;
void calc()
{
if(pri<100)
dis=(pri*10)/100;
else
dis=(pri*20)/100;
p=pri-dis;
amt=p*qty;
}
};
class display:public discount
{
public:
void print()
{
cout<<”\t item number \t price\t quantity\t discount\t amount\n\n”;
cout<<”\t”<<ino<<”\t\t”<<ina<<”\t\t”<<pri<<”\t\t”<<qty<<”\t\t”<<(dis*qty)<<”\t\t”<<amt;
}
};
void main()
{
display d;
clrscr();
d.get();
d.calc();
d.print();
getch();
}
OUTPUT :
Item number 1
Item prices 20
Quantity 500
RESULT :
MULTIPLE INHERITANCE
AIM :
SOURCE CODE :
#include<iostream.h>
#include<conio.h>
class base1
{
public:
int reg;
char name[10];
void get()
{
cout<<”\n register number:’;
cin>>reg;
cout<<”\n name:”;
cin>>name;
}
};
class base2
{
public:
int m1,m2;
void read()
{
cout<<”\n enter marks:\n”;
cin>>m1>>m2;
}
};
class derived:public base1,public base2
{
int tot,avg;
public:
void process()
{
tot=m1+m2;
avg=tot/2;
}
void display()
}
cout<<”\n register number:”<<reg;
cout<<”\n name:”<<name;
cout<<”\n mark1:”<<m1;
cout<<”\n mark2:”<<m2;
cout<<”\n total:”<<tot;
cout<<”\n average:”<<avg;
}
};
void main()
{
derived d;
clrscr();
d.get():
d.read();
d.process();
d.display();
getch();
}
OUTPUT :
register number: 1
name : rathi
enter mark: 90
99
Register number : 1
Name : rathi
Mark1 : 90
Mark2 : 99
Total : 189
Average : 94
RESULT :
Thus the program was executed successfully.
EX NO :17
HIERARCHICAL INHERITANCE.
AIM :
To write a c++ program for employee details using hierarchical inheritance.
SOURCE CODE :
#include<iostream.h>
#include<conio.h>
long int g,d;
class base-emp
{
protected:
long int empno,basic;
char empna[10];
public:
void get()
{
cout<<endl<<”employee number:”;
cin>>empno;
cout<<endl<<”employee name:”;
cin>>empna;
cout<<endl<<”basic pay:”;
cin>>basic;
}
};
class pay-calc:public base-emp
{
public:
long int da,hra,pf,b;
void calc()
{
b=basic;
da=(b*60)/100;
hra=(b*40)/100;
pf=(b*20)/100;
g=b+da+hra;
d=g-bf;
}
};
class grs::public pay-calc
{
public:
void put()
{
cout<<”\n\n gross pay”<<g;
}
};
class net:public pay-calc
{
public:
void display()
{
cout<<”\n\n net pay”<<d;
}
};
class emp-ded:public pay-calc
{
public:
void display()
{
cout<<endl<<”\n\n employee number:”<<empno;
cout<<endl<<”\n\n employee name:”<<empna;
cout<<endl<<”\n\n basic salary:”<<basic;
cout<<endl<<”\n\n dearness allowaness:”<<da;
cout<<endl<<”\n\n house rebt allowaness:”<<hra;
cout<<endl<<”\n\n provident fund:”<<pf;
}
};
void main()
{
grs g;
net n;
emp-det e;
clrscr();
e.get():
e.calc();
e.display():
g.put();
n.display();
getch():
}
OUTPUT :
Employee number : 4
Employee number : 4
RESULT :
Thus the program was executed successfully.
Ex No: 18
CONSTRUCTOR
AIM :
To write a c++ program for constructor.
SOURCE CODE :
#include<iostream.h>
#include<conio.h>
int cnt=0;
class demo
{
public:
demo()
{
cnt++;
cout<”\n constructor”<<cnt;
getch();
}
~demo()
{
cout<<”\n destructor”<<cnt;
cnt--;
getch();
}
};
void main()
{
clrscr();
demo d()
demo d2;
demo d3;
demo d4;
getch();
}
OUTPUT :
Constructor 1
Constructor 2
Constructor 3
Constructor 4
destructor 4
destructor 3
destructor 2
destructor 1
RESULT :
Thus the program was executed successfully.
EX. NO: 19
ELECTRICITY BILL
AIM:
To write a c++ program for electricity bill using binary file concept.
SOURCE CODE :
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<iomanip.h>
#include<string.h>
class electric
{
char cat[20];
int eb-no,cr,pr,unit;
float amt;
public:
void readdata(void);
void calc(void);
void display(void);
};
void electric::readdata();
{
cout<<”\n”<<”enter Eb number:”;
cin>>eb-no;
cout<<”\n”<<”enter category:”;
cin>>cat;
cout<<”\n “<<”enter current reading:”;
cin>>cr;
void main()
{
electric e;
clrscr();
ofstream outfile;
out file.open(“BILL.Dat”,ios::binary);
e.readdata();
e.calc();
out file.write((char*)&e,sizeof(e));
outfile.close();
ofstream infile;
infile.open(“BILL.Dat”,ios::binary);
infile.write((char*)&e,sizeof(e));
e.display();
infile.close();
getch();
}
OUTPUT :
Eb number : 100
Amount : 1600
Unit : 200
RESULT :
Thus the program was executed successfully.