II PU Lab Mannual 2023
II PU Lab Mannual 2023
II PU Lab Mannual 2023
Output 1:
Enter the size of the array
5
Enter the array elements
10 20 30 20 40
Enter the element to find frequency
20
Frequency of element is=2
Output 2:
Enter the size of the array
5
Enter the array elements
10 20 30 40 50
Enter the element to find frequency
99
Element does not exist
Output 1:
Enter the size of the array
5
Enter the array elements
10 20 30 40 50
Enter the position to insert
2
Enter the element to insert
99
Array elements after insertion
10
20
99
30
40
50
Output 2:
Enter the size of the array
5
Enter the array elements
10 20 30 40 50
Enter the position to insert
7
Enter the element to insert
99
Array out of bond
3. Write a C++ program to delete an element from an array from a given position.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class Deletion
{
private: int i,n,a[10],pos;
Output 1:
Enter the size of the array
5
Enter the array elements
10 20 30 40 50
Enter the position to delete
2
Array elemets after deletion
10
20
40
50
Output 2:
Enter the size of the array
5
Enter the array elements
10 20 30 40 50
Enter the position to delete
8
Array out of bond
4. Write a C++ program to sort the element of an array in ascending order using insertion
sort.
#include<iostream.h>
#include<conio.h>
class Sorting
{
private: int i,n,a[10],j,temp;
Output:
Enter the size of the array
5
Enter the array elements
10 50 30 20 40
Array elements after sorting
10
20
30
40
50
5. Write a C++ program to search for a given element in an array using binary search
method.
#include<conio.h>
#include<iostream.h>
class Binary
{
private: int i,n,a[10],ele,low,high,mid,loc;
Output 1:
Enter the size of array
5
Enter the array elements
10 20 30 40 50
Enter the element to search
20
Element found at position 2
Output 2:
Enter the size of array
5
Enter the array elements
10 20 30 40 50
Enter the element to search
7
Element does not exist
Output:
Enter principle amount
1000
Enter Rate of intrest
20
Enter time
2
Principle amount=1000
Rate of intrest=20
Time=2
Simple intrest=400
Total amount=1400
Output 1:
Enter the value of a,b,c
1 2 1
Root=-1
Output 2:
Enter the value of a,b,c
2 6 2
Root 1=-0.381966
Root 2=-2.618034
Output 3:
Enter the value of a,b,c
2 1 2
Imaginary Roots
Output 1:
Enter the value of A
10
Cube of a number is= 1000
Output 2:
Enter the value of A
20
Cube of a number is= 8000
Output:
Enter the base value
2
Enter the exponential value
4
Sum of series=31
void compute()
{
tot=m1+m2;
cout<<"Total marks="<<tot<<endl;
}
};
void main()
{
Derived d;
clrscr();
d.readdata();
d.readmarks();
d.display();
d.compute();
getch();
}
Output:
Enter reg.no & Name
123
Bapuji
Enter the 2 sub marks
90
80
Reg. No=123
<<Name=Bapuji
Total marks=170
Output:
Enter reg.no & Name
123
Bapuji
Reg. No=123
Name=Bapuji
void display()
{
if(top==-1)
{
cout<<"Stack underflow"<<endl;
}
else
{
cout<<"Stack elemets are:"<<endl;
for(i=0;i<=top;i++)
{
cout<<stack[i]<<endl;
}
}
}
};
void main()
{
int ele,ch;
Stackop s;
clrscr();
while(1)
{
cout<<"1: for Push"<<endl;
cout<<"2: for Display"<<endl;
cout<<"3: for Exit"<<endl;
cin>>ch;
switch(ch)
{
case 1: cout<<"Enter the element to insert"<<endl;
cin>>ele;
s.push(ele);
break;
case 2: s.display();
break;
case 3: cout<<"Program ended"<<endl;
getch();
exit(0);
default: cout<<"Inavlid choice"<<endl;
}
getch();
}
}
Output:
1: for Push
2: for Display
3: for Exit
1
Enter the element to insert
10
1: for Push
2: for Display
3: for Exit
1
Enter the element to insert
20
1: for Push
2: for Display
3: for Exit
1
Enter the element to insert
30
1: for Push
2: for Display
3: for Exit
1
Enter the element to insert
40
Stack overflow
1: for Push
2: for Display
3: for Exit
2
Stack elemets are:
10
20
30
1: for Push
2: for Display
3: for Exit
3
program ended
public: Stackop()
{
top=-1;
}
void push(int item)
{
if(top==MAX-1)
{
cout<<"Stack overflow"<<endl;
}
else
{
top=top+1;
stack[top]=item;
}
}
void pop()
{
if(top==-1)
{
cout<<"Stack Underflow"<<endl;
}
else
{
cout<<"Element popped="<<stack[top];
top=top-1;
}
}
void display()
{
if(top==-1)
{
cout<<"Stack underflow"<<endl;
}
else
{
cout<<"Stack elemets are:"<<endl;
for(i=0;i<=top;i++)
{
cout<<stack[i]<<endl;
}
}
}
};
void main()
{
int ele,ch;
Stackop s;
clrscr();
while(1)
{
cout<<"1; for Push"<<endl;
cout<<"2: for Pop"<<endl;
cout<<"3: for Display"<<endl;
cout<<"4: for Exit"<<endl;
cin>>ch;
switch(ch)
{
case 1: cout<<"Enter the element to insert"<<endl;
cin>>ele;
s.push(ele);
break;
case 2: s.pop();
break;
case 3: s.display();
break;
case 4: cout<<"Program ended"<<endl;
getch();
exit(0);
default: cout<<"Inavlid choice"<<endl;
}
getch();
}
}
Output:
1: for Push
2: for Pop
3: for Display
4: for Exit
1
Enter the element to insert
10
1: for Push
2: for Pop
3: for Display
4: for Exit
1
Enter the element to insert
20
1: for Push
2: for Pop
3: for Display
4: for Exit
1
Enter the element to insert
3
1: for Push
2: for Pop
3: for Display
4: for Exit
1
Enter the element to insert
40
Stack overflow
1: for Push
2: for Pop
3: for Display
4: for Exit
3
Stack elemets are:
10
20
30
1: for Push
2: for Pop
3: for Display
4: for Exit
2
Element popped=30
1; for Push
2: for Pop
3: for Display
4: for Exit
2
Element popped=20
1; for Push
2: for Pop
3: for Display
4: for Exit
2
Element popped=10
1; for Push
2: for Pop
3: for Display
4: for Exit
2
Stack Underflow
1; for Push
2: for Pop
3: for Display
4: for Exit
4
Program ended