Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment 10 In this assignment, we will work with linked list and operator ove

ID: 3685569 • Letter: A

Question

Assignment 10 In this assignment, we will work with linked list and operator overloading. Define a class LinkedList and making 2 linked lists. Combine the two linked list to make the third linked list. For each node of the linked list, it will contain 2 data type, a string for student name, and a four-digit integer for the RUID (random number). Each node of linked list should also contain the next-pointer to the next node. Overloading the adding operator (+) and the assignment operator () to combine the linked list. For example, the lists are defined using LinkedList class as follow, LinkedList list1, list2, list3; // populate list1 and list2 by adding nodes to the lists list3 list1+ list2; // overloading the adding operator +)to perform this operation Note: we would need to overload the assignment operator () to set the result of (list1+list2) to ist 3 After adding the two list, select the next operation to perform on the resulted linked list only (list3). The operations are adding node to the list, removing node from the list, print the entire list, print one element of the list, sort the list according to RUID number. To print one element of the list, we will need overload the operatorl to print one element of the list using index as shown. You would also need to overload the ostream operator

Explanation / Answer

Solution:

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct student{
char name[100];
char roll[10];
struct student *next;
};
struct student *first=NULL,*last=NULL,*k;
void create(int n)
{
int i;
first=(struct student*)malloc(sizeof(struct student));
printf(" Enter the first name of the student:");
scanf("%s",first->name);
printf(" Enter the roll number of the student:");
scanf("%s",first->roll);
first->next=NULL;
last=first;
for(i=1;i {
k=(struct student*)malloc(sizeof(struct student));
printf(" Enter the first name of the student:");
scanf("%s",k->name);
printf(" Enter the roll number of the student:");
scanf("%s",k->roll);
k->next=NULL;
last->next=k;
last=k;
}
}
void display()
{
struct student *t;
t=first;
while(t!=NULL)

{

printf(" The roll number of the student:%s",t->roll);

printf(" First name of the student:%s",t->name);
t=t->next;
}
}
void insertafter()
{
char r[10];
int flag=0;
printf(" Enter the roll number u wanna insert after that:");
scanf("%s",r);
struct student *t;
t=first;
while(t!=NULL)
{
if(strcmpi(r,t->roll)==0)
{
k=(struct student*)malloc(sizeof(struct student));
printf(" Enter the first name of the student:");
scanf("%s",k->name);
printf(" Enter the roll number of the student:");
scanf("%s",k->roll);
k->next=t->next;
t->next=k;
flag=1;
break;
}
t=t->next;
}
if(flag==0)
printf(" The element not found!!!");
}
void del()
{

struct student *back,*t,*k;
char r[10];
int flag=0;
printf(" Enter the roll number u wanna delete:");
scanf("%s",r);
if(strcmpi(r,first->roll)==0)
{
first=first->next;
flag=1;
}
else
{
back=first;
k=first->next;
while(k!=NULL)
{
if(strcmpi(r,k->roll)==0)
{
back->next=k->next;
flag=1;
break;
}
}
}
if(flag==0)
printf(" The element not found!!!");
}
void search()
{
char r[10];
int flag=0;
printf(" Enter the roll number u wanna search:");
scanf("%s",r);
struct student *t;
t=first;

while(t!=NULL)
{
if(strcmpi(r,t->roll)==0)
{
printf(" The roll number found in the list!!! His name is %s",t->name);
flag=1;
break;
}t=t->next;
}
if(flag==0)
printf(" The roll number not in database!!");
}
int main()
{
int n,o;
while(o!=0){
printf(" MENU ");
printf(" Enter 1 for creating database");
printf(" Enter 2 for displaying database");
printf(" Enter 3 for inserting an record after another");
printf(" Enter 4 for deleting a record");
printf(" Enter 5 for searching a record");
printf(" Enter 0 for exit!");
printf(" Enter the choice:");
scanf("%d",&o);
switch(o)
{
case 1:printf(" Enter the maximum size of the database:");
scanf("%d",&n);
create(n);
break;
case 2:display();break;
case 3:insertafter();break;
case 4:del();break;
case 5:search();break;

case 0:exit(0);break;
default:printf(" You have entered a wrong choice!!!");
}
}
getch();
}