Now about lab4 it has a relation with lab3 And Dr upload thi
Solution
#include<iostream>
#include<limits>
#define MAX 100;
using namespace std;
struct date
{
int day;
int month;
int year;
};
struct STUDENT_TYPE
{
string name;
int id;
double GPA;
date DOB;
};
Int i=0;
int main()
{
STUDENT_TYPE student[MAX];
int choice=-1;
while(choice!=0)
{
cout<<”\ 0-Exit\ 1-Insert\ 2-Delete_last\ 3-Display\ 4-Search\ 5-Deletion_particular_record\ 6-Insert_after_record\ 7-Sort(acending)”;
cout<<”Enter your choice:”;
cin>>choice;
switch(choice)
{
case 0: exit(0);
case 1:insert(); break;
case 2:delete(); break;
case 3:display(); break;
case 4:search();break;
case 5:delete2();break;
case 6:insert2();break;
case 7:sort();break;
default: cout<<”Wrong selection”;
}
}
return 0;
}
void insert()
{
cout<<”Enter the student details:”;
cout<<”Student name:”;
cin<<student[i].name;
cout<<”Student ID:”;
cin<<student[i].ID;
cout<<”student GPA:”;
cin>>student[i].GPA;
cout<<”Student DOB”;
cin>>student[i].DOB.day>>student[i].DOB.month>>student[i].DOB.year;
i++;
}
void delete()
{
//assign 0 to last pointed record
student[i].name=0; ;
student[i].ID=0;
student[i].GPA=0;
student[i].DOB.day=0;student[i].DOB.month=0;student[i].DOB.year=0;
i--;
}
Void display()
{
cout<<”Student details are\ ”;
for(int n=0;n<i;n++)
{
cout<< student[n].name<<studend[n].ID<<student[n].GPA<<student[n].DOB.day<<student[n].DOB.month<<student[n].DOB.year;
cout<<”\ ”;
}
}
void search()
{
boolean record=false;
int id;
cout<<”Enter student ID to search in the list:”;
cin>>id;
for(int n=0;n<i;n++)
{
if(student[n].ID==id)
{
cout<<”Student with “<<id<<” is present in the list”;
record = true;
break;
}
}
If(!record)
cout<<”Student with “<<id<<” is not present in the list”;
}
void delete2()
{
int record;
cout<<”Enter the student id u want to delete:”;
cin>>record;
for(int n=0;n<i;n++)
{
if(student[n].ID==record)
{
find=n;
break;
}
}
for(int k=find;k<i;++k)
{//move all the records forward from current position
student[k].name=student[k+1].name;
student[k].ID=student[K+1].ID;
student[k].GPA=student[k+1].GPA
student[k].DOB.day=student[k+1].DOB.day;
student[k].DOB.month=student[k+1].DOB.month;
student[k].DOB.year=student[k+1].DOB.year;
}
}
void insert2()
{
int pos,id;
cout<<”After which student id u want to insert the record:”;
cin>>id;
for(int n=0;n<i;n++) //find the position where u want to insert
{
if(student[n].ID==id)
{
n=pos;
break;
}
}
for(int p=++i;p>pos;p--)
{//move all the record towards right to make space for insertion of new record
student[p].name=student[p-1].name;
student[p].ID=student[p-1].ID;
student[p].GPA=student[p-1].GPA
student[p].DOB.day=student[p-1].DOB.day;
student[p].DOB.month=student[p-1].DOB.month;
student[p].DOB.year=student[p-1].DOB.year;
}
cout<<”Enter the student details:”;
cout<<”Student name:”;
cin<<student[pos].name;
cout<<”Student ID:”;
cin<<student[pos].ID;
cout<<”student GPA:”;
cin>>student[pos].GPA;
cout<<”Student DOB”;
cin>>student[pos].DOB.day>>student[pos].DOB.month>>student[pos].DOB.year;
}
void sort()
{//bubble sorting technique is used
Struct STUDENT_TYPE TEMP[2];
for(int x=0;x<=i;x++)
{
for(int y=0;y<=i-x;y++)
{
If(student[y].ID>student[y+1].ID)
{
//move all the record information to temp and swap them
temp[0].name=student[j].name;
student[j].name=student[j+1].name;
student[j+1].name=temp[0].name;
//the above 3 lines are repeated for all the student fields
}
}
}
}





