Practical File All Program
Practical File All Program
Practical File All Program
1.To Print The Given Numbers In Ascending Order Using Bubble Sort:
#include<iostream.h>
#include<conio.h>
void bubblesort(int[],int);
void main()
{
clrscr();
int a[50],n,i;
cout<<"enter size of array:";
cin>>n;
cout<<"enter array elements \n";
for(i=0;i<n;i++)
{ cin>>a[i];}
bubblesort(a,n);
cout<<"the sorted array is shown\n";
for(i=0;i<n;i++)
{ cout<<a[i]<<" ";}
cout<<endl;
getch();
}
void bubblesort(int a[],int n)
{
int tmp,cnt=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<(n-1);j++)
{
if(a[j]>a[j+1])
{
tmp=a[j];
a[j]=a[j+1];
a[j+1]=tmp;
}
}
cout<<"the array after loop-"<<++cnt<<"is:";
for(int k=0;k<n;k++)
cout<<a[k]<<" ";
cout<<endl;
}
}
Page |2
2.To Print The Given Numbers In Descending Order Using Bubble Sort:
#include<iostream.h>
#include<conio.h>
void bubblesort(int[],int);
void main()
{
clrscr();
int a[50],n,i;
cout<<"enter size of array:";
cin>>n;
cout<<"enter array elements \n";
for(i=0;i<n;i++)
{ cin>>a[i];}
bubblesort(a,n);
cout<<"the sorted array is shown\n";
for(i=0;i<n;i++)
{ cout<<a[i]<<" ";}
cout<<endl;
getch();
}
void bubblesort(int a[],int n)
{
int tmp,cnt=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<(n-1);j++)
{
if(a[j]<a[j+1])
{
tmp=a[j];
a[j]=a[j+1];
a[j+1]=tmp;
}
}
cout<<"the array after loop-"<<++cnt<<"is:";
for(int k=0;k<n;k++)
cout<<a[k]<<" ";
cout<<endl;
}
}
Page |4
3.To Print The Given Numbers In Ascending Order Using Insertion Sort
#include<iostream.h>
#include<conio.h>
#include<process.h>
int findpos(int[],int,int);
void main()
{
clrscr();
int a[50],n,item,index,i;
char ch='y';
cout<<"enter the size of array:";
cin>>n;
cout<<"\n enter array elements";
for(i=0;i<n;i++)
{ cin>>a[i];}
while(ch=='y'||ch=='Y')
{
cout<<"\n enter the elements to be inserted....";
cin>>item;
if(n==50)
{
cout<<"overflown!";
exit(1);
}
index=findpos(a,n,item);
for(i=n;i>index;i--)
{ a[i]=a[i-1];}
a[index]=item;
n+=1;
cout<<"want to insert more elements ?(y\n)";
cin>>ch;
}
cout<<"the array now is as shown below....\n";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
getch();
}
int findpos(int a[],int size,int item)
{
int pos;
Page |6
if(item<a[0])
pos=0;
else
{
for(int i=0;i<size-1;i++)
{
if(a[i]<=item&&item<a[i+1])
{
pos=i+1;
break;
}
if(i==size-1)
pos=size;
}
}
return pos;
}
OUTPUT OF THE FOLLOWING PROGRAM:
Page |7
5.To Merge The Two Arrays Element And Print The Same In Ascending
Order Using Merge Sort:
#include<iostream.h>
#include<conio.h>
void mergeit(int A[],int m,int B[],int n,int C[]);
void main()
{
clrscr();
int A[50],B[50],C[50],m,n,mn=0,i;
cout<<"enter size of first array:";
cin>>m;
cout<<"enter the elements ascending order:\n";
for(i=0;i<m;i++)
{ cin>>A[i]; }
cout<<"enter the size of 2nd array:";
cin>>n;
mn=m+n;
cout<<"enter the elements of 2nd array in descending order\n";
for(i=0;i<n;i++)
{ cin>>B[i]; }
mergeit(A,m,B,n,C);
for(i=0;i<mn;i++)
cout<<C[i]<<" ";
cout<<"\n";
getch();
}
void mergeit(int A[],int m,int B[],int n,int C[])
{
int a,b,c;
for(a=0,b=n-1,c=0;a<m&&b>=0;)
{ if(A[a]<=B[b])
C[c++]=A[a++];
else
C[c++]=B[b--];
}
if(a<m)
{
while(a<m)
C[c++]=A[a++]; }
else
{
P a g e | 10
while(b>=0)
C[c++]=B[b++]; }
}
OUTPUT OF THE FOLLOWING PROGRAM:
P a g e | 11
6.To Merge The Two Arrays Element And Print The Same In Descending
Order Using Merge Sort:
#include<iostream.h>
#include<conio.h>
void mergeit(int A[],int m,int B[],int n,int C[]);
void main()
{
clrscr();
int A[50],B[50],C[50],m,n,mn=0,i;
cout<<"enter the size of 1st array:";
cin>>m;
cout<<"enter the elements in ascending order:\n";
for(i=0;i<m;i++)
{ cin>>A[i];}
cout<<"enter the size of the 2nd array:";
cin>>n;
mn=m+n;
cout<<"enter the elements in descending order:\n";
for(i=0;i<n;i++)
{ cin>>B[i]; }
mergeit(A,m,B,n,C);
for(i=mn-1;i>=0;i--)
cout<<C[i]<<" ";
cout<<"\n";
getch();
}
void mergeit(int A[],int m,int B[],int n,int C[])
{ int a,b,c;
for(a=0,b=n-1,c=0;a<m&&b>=0;)
{ if(A[a]<=B[b])
C[c++]=A[a++];
else
C[c++]=B[b--];
}
if(a<m)
{ while(a<m)
C[c++]=A[a++];
}
else
{
while(b>=0)
P a g e | 12
C[c++]=B[b++];
}
}
OUTPUT OF THE FOLLOWING PROGRAM:
P a g e | 13
}
void stack::display()
{node*temp=top;
while(temp!=NULL)
{
cout<<temp->country<<"->";
temp=temp->link;
}
cout<<"!!!\n";
}
stack::~stack()
{
node*temp;
while(top!=NULL)
{temp=top;
top=top->link;
delete temp;
}
}
void main()
{
stack st;
int ch;
while(1)
{cout<<"menu:\n1)push\n2)pop\n3)display\n4)exit\n";
cout<<"enter choice:";
cin>>ch;
switch(ch)
{
case 1:st.push(); break;
case 2:st.pop(); break;
case 3:st.display(); break;
case 4:exit(0);
default:cout<<"wrong choice entered";
}
}
}
P a g e | 22
else
{
node*ptr=front;
cout<<front->city<<"delete/n";
front=front->link;
delete ptr;
if(front==NULL)
rear=NULL;
}
}
void queue::display()
{
node*temp=front;
while(temp!=NULL)
{
cout<<temp->city<<"-";
temp=temp->link;
}
cout<<"===>\n";
}
queue::~queue()
{
node*temp;
while(front!=NULL)
{
temp=front;
front=front->link;
delete temp;}
}
void main()
{
queue qt;
int ch;
while(1)
{
cout<<"Menu:\n1)push\n2)pop\n3)display\n4)Exit\n";
cout<<"enter your choice:";
cin>>ch;
switch(ch)
{
case 1:qt.push(); break;
case 2:qt.pop(); break;
P a g e | 25
}
OUTPUT OF THE FOLLOWING PROGRAM:
P a g e | 28
getch();
}
OUTPUT OF THE FOLLOWING PROGRAM:
P a g e | 30
}
void main()
{
clrscr();
D d;
d.mul();
d.display();
d.mul();
d.display();
getch();
}
OUTPUT OF THE FOLLOWING PROGRAM:
P a g e | 32
}
OUTPUT OF THE FOLLOWING PROGRAM:
P a g e | 40
clrscr();
deposit d1,d2(2000,2,0.07f),d3(4000,1),d4(3000,0.12f);
d1.calc_amt();
d2.calc_amt();
d3.calc_amt();
d4.calc_amt();
cout<<"object 1\n";
d1.display();
cout<<"object 2\n";
d2.display();
cout<<"object 3\n";
d3.display();
cout<<"object 4\n";
d4.display();
getch();
}
OUTPUT OF THE FOLLOWING PROGRAM:
P a g e | 42
Q.24:Consider the Consignor & Consignee table & give SQL commands
TABLE : CONSIGNOR
Q.25:Consider the Sender & Receipent table & give SQL commands.
TABLE : SENDER
SenderID SenderName Sender Address Sender City
ND01 R jain 2,ABC Appts New Delhi
MU02 H sinha 12,Newton Mumbai
MU15 S haj 27/A Park Street New Delhi
ND50 T Prasad 122.K,SDA Mumbai
TABLE : RECIPIENT
ReeID SenderID ReName ReeAddress ReCCity
KO05 ND01 RBajpayee 5,Central Aveneu Kolkata
ND08 MU02 S Mahajam H6,A Vihar New Delhi
MU19 ND01 H Sing 2A,Andheri Mumbai
MU32 MU15 PK Swamy B5,CS Mumbai
ND48 ND50 S Triputhi 13,B1D Mayor Vihar New Delhi