Complete this C++ code with the following requirements: Write a program that will allow a user to enter students into a database. The student information should include full name, student ID, GPA and status. The program should allow delete any student based on student ID. Program must use linked list. No vectors or arrays. C++. # include using namespace std; class Node{ string full_name, status; int studentID; float GPA; Node* next; }; Node* head= new Node(); bool check (int x){ if(head==NULL){ return false; } Node* t=new Node(); t=head; while(t!=NULL){ if(t->studentID==x){ return true; t=t->next; } } return false; } void insert(int studentID, string full_name, string status, float GPA){ if(check(student_id)){ cout<<"Student already exists in the record"<studentID=studentID; t->full_name=full_name; t->GPA=GPA; t->status=status; t->next=NULL; /* Insert at beginning */ if(head==NULL||head->studentID>=t->studentID){ t->next=head; head=t; } /* Insert at Middle or End */ else{ Node *c=head; while(c->next!=NULL && c->next->studentIDstudentID){ c=c->next; } t->next=c->next; c->next=t; } cout<<"Record inserted successfully"<studentID==studentID){ cout<<"Student ID: "<studentID<full_name<GPA<status<next; } if (p==NULL){ cout<<"No such record available"<
Types of Linked List
A sequence of data elements connected through links is called a linked list (LL). The elements of a linked list are nodes containing data and a reference to the next node in the list. In a linked list, the elements are stored in a non-contiguous manner and the linear order in maintained by means of a pointer associated with each node in the list which is used to point to the subsequent node in the list.
Linked List
When a set of items is organized sequentially, it is termed as list. Linked list is a list whose order is given by links from one item to the next. It contains a link to the structure containing the next item so we can say that it is a completely different way to represent a list. In linked list, each structure of the list is known as node and it consists of two fields (one for containing the item and other one is for containing the next item address).
Complete this C++ code with the following requirements:
Write a
# include<iostream>
using namespace std;
class Node{
string full_name, status;
int studentID;
float GPA;
Node* next;
};
Node* head= new Node();
bool check (int x){
if(head==NULL){
return false;
}
Node* t=new Node();
t=head;
while(t!=NULL){
if(t->studentID==x){
return true;
t=t->next;
}
}
return false;
}
void insert(int studentID, string full_name, string status, float GPA){
if(check(student_id)){
cout<<"Student already exists in the record"<<endl;
return;
}
Node *t=new Node();
t->studentID=studentID;
t->full_name=full_name;
t->GPA=GPA;
t->status=status;
t->next=NULL;
/* Insert at beginning */
if(head==NULL||head->studentID>=t->studentID){
t->next=head;
head=t;
}
/* Insert at Middle or End */
else{
Node *c=head;
while(c->next!=NULL && c->next->studentID<t->studentID){
c=c->next;
}
t->next=c->next;
c->next=t;
}
cout<<"Record inserted successfully"<<endl;
}
void search(int studentID){
if (!head){
cout<<"No such record available"<<endl;
return;
}
else{
Node *p=head;
while(p){
if(p->studentID==studentID){
cout<<"Student ID: "<<p->studentID<<endl;
cout<<"Student Name: "<<p->full_name<<endl;
cout<<"Student GPA: "<<p->GPA<<endl;
cout<<"Student Status: "<<p->status<<endl;
return;
}
p=p->next;
}
if (p==NULL){
cout<<"No such record available"<<endl;
}
}
}
int main(void){
Studen1 s1;
Student s2;
Student s3;
s1.insert(100050,'John Murphy',3.58,'Pass');
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images