12 Thlab

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

C++ CODE:

#include <iostream>
#include <string>
using namespace std;
int main()
{
int i,j,c,d,swap,position,key1,num,date1,choice;
cout<<"Enter the number of records\n";
cin>>num;
char sorted[num][60],key;
int date[num];
char id,swap1;
do
{
cout<<"Enter the option\n1.Do you want to enter the details of the existing
records\n2.Sort the records present by ID\n3.Sort the records present according to date of
renewal\n4.Display the existing records\n5.Exit\n";
cin>>choice;
switch(choice)
{
case 1: for(i=0;i<num;i++)
{
cout<<"Enter the passport ID of the record\n";
cin>>id;
sorted[i][0]=id;
cout<<"Enter the date of renewal\n";
cin>>date1;
date[i]=date1;
}
/*for(i=1;i<count;i++)
for(j=0;j<i;j++)
if(sorted[i]>sorted[j])
{
temp=sorted[i];
for(k=0;k>0;k--)
sorted[k]=sorted[k-1];
sorted[k]=temp;
}*/
break;
case 2: for(i=1;i<num;i++)
{
key=sorted[i][0];
key1=date[i];
j=i-1;
while(j>=0&&sorted[j][0]>key)
{
sorted[j+1][0]=sorted[j][0];
date[j+1]=date[j];
j=j-1;
}
sorted[j+1][0]=key;
date[j+1]=key1;
}
break;
case 3: for(c=0;c<(num-1);c++)
{
position=c;
for(d=c+1;d<num;d++)
{
if (date[position]>date[d])
position=d;
}
if (position!=c)
{
swap = date[c];
date[c]=date[position];
date[position]=swap;
swap1=sorted[c][0];
sorted[c][0]=sorted[position][0];
sorted[position][0]=swap1;
}
}
break;
case 4: for(i=0;i<num;i++)
{
cout<<"Record ID:"<<sorted[i][0]<<"\t";
cout<<"Date of renewal:"<<date[i]<<endl;
}
break;
case 5:break;
}
}while(choice<=4);
return 0;
}
OUTPUT FOR INSERTION SORT:

OUTPUT FOR SELECTION SORT:

THANK YOU!!

You might also like