The following program will contain a class node with a data member data which contains the name of the student. If you need to hold other records of a student, please add more members here. Since no restrictions were made, I’ve declared all members to be public. (You may also use a struct, if you prefer that.)
I have tried to keep the program as modular as possible. I have commented wherever I have deemed necessary.
Please find the code below:
#include<iostream>
using namespace std;
class node
{
public:
string data; //here data is the student's name
node * link;
};
node *head=NULL,*tail=NULL;
void insertAtStart(string y)
{
node *x=new node;
x->data=y;
x->link=head;
if(head==NULL&&tail==NULL) //update tail if
initially empty list
tail=x;
head=x; // new head
}
void insertAtEnd(string y)
{
node *x=new node;
x->data=y;
x->link=NULL;
if(head==NULL&&tail==NULL) //update tail if
initially empty list
head=tail=x;
else{
tail->link=x;
tail=x; //new tail
}
}
void deleteFromStart()
{
if(head==NULL)
cout<<"Can't delete; empty
list!"<<endl;
else
{
if(head==tail)
tail=NULL; //
set tail to null also if list will be empty after delete
head=head->link;
}
}
void deleteFromEnd()
{
if(tail==NULL)
cout<<"Can't delete; empty
list!"<<endl;
else
{
node *x=head;
if(head==tail) // if there's only
one node
{
head=NULL;
tail=NULL;
}
else // for more nodes
{
while((x->link)->link!=NULL) // traverse until next node is
last node
x=x->link;
x->link=NULL;
tail=x;
}
}
}
void deleteByName(string name)
{
if(head==NULL)
cout<<"Empty
list!"<<endl;
else
{
node *x=head;
bool r = 0;
if(head==tail &&
name==x->data) // if there's only one node and it matches
name
{
head=NULL;
tail=NULL;
r=1;
}
else if(x->data==name){//>1
nodes but head matches name
deleteFromStart();
r=1;
}
else{
do{
if(name==(x->link)->data)
{
x->link=(x->link)->link;
r=1;
break;
}
x=x->link;
}while(x->link!=NULL);
}
if(r==1)
cout<<"Removed!"<<endl;
else
cout<<"Name not found"<<endl;
}
}
void display()
{
node *x=head;
cout<<"The current list is: ";
if(head==NULL&&tail==NULL)
cout<<"empty!"<<endl;
else{
do{
cout<<x->data<<" -> ";
x=x->link;
}while(x!=NULL);
}
delete x;
cout<<endl;
}
int main()
{
int x=37; //random number not 0
do{
cout<<"Press"<<endl<<
"1 to insert at
end"<<endl<<
"2 to insert at
beginning"<<endl<<
"3 to remove from
end"<<endl<<
"4 to remove from
beginning"<<endl<<
"5 to remove by
name"<<endl<<
"0 to exit"<<endl;
cin>>x;
if(x==1){
cout<<"Enter name of student"<<endl;
string
name;
cin>>name;
//you can also use gets() for whitespaces in names
insertAtEnd(name);
display();
}
else if(x==2){
cout<<"Enter name of student"<<endl;
string
name;
cin>>name;
//you can also use gets() for whitespaces in names
insertAtStart(name);
display();
}
else if(x==3){
deleteFromEnd();
display();
}
else if(x==4){
deleteFromStart();
display();
}
else if(x==5){
cout<<"Enter name of student"<<endl;
string
name;
cin>>name;
//you can also use gets() for whitespaces in names
deleteByName(name);
display();
}
else{
cout<<"Invalid response!"<<endl;
}
}while(x!=0);
}
please make sure rubics Program Specifications: Write a C++ program to manage a list of students...
Write a C++ program to manage a list of students waiting to register for a course using a linked list. Operations should include adding a new student at the end of the list, adding a new student at the beginning of the list, removing a student from the beginning of the list, removing a student from the end of the list, and removing a student by name. Allow the user an option to exit. NOTE: Functions/Methods must used throughout program....
Write a C++ program to manage a list of inventory items using a linked list. Operations should include adding a new inventory item at the end of the list, adding a new inventory item at the beginning of the list, removing an inventory item from the beginning of the list, removing an inventory item from the end of the list, removing an inventory item by name, and display the current list of inventory items. Allow the user an option to...
Help in JAVA please Write a program that reads a list of students (first names only) from a file. It is possible for the names to be in unsorted order in the file but they have to be placed in sorted order within the linked list. The program should use a doubly linked list. Each node in the doubly linked list should have the student’s name, a pointer to the next student, and a pointer to the previous student. Here...
Write a c/c++ program to read a list of students from a file and create a list. The program should use a linked list for implementation. Each node in the linked list should have the student’s name, a pointer to the next student, and a pointer to a linked list of scores. There may be up to four scores for each student.
In C++
Write a menu driven C++ program to read a file containing
information for a list of Students, process the data, then present
a menu to the user, and at the end print a final report shown
below. You may(should) use the structures you developed for the
previous assignment to make it easier to complete this assignment,
but it is not required.
Required Menu Operations are:
Read Students’ data from a file to update the list (refer to
sample...
C++ Data Structure Write a program to read a list of students from a file and create a list. The program should use a linked list for implementation. Each node in the linked list should have the student’s name, a pointer to the next student, and a pointer to a linked list of scores. There may be up to four scores for each student.
In C++ syntax please
Write a program that implements and demonstrates a linked list using functions. Your program should first dehne a node that stores an integer and then your program will include the following functions appendo- This function accepts the head pointer (by reference) of a linked list and an integer as it's only arguments. It then creates a node, stores the integer argument in the node, and adds it to the end of the list. findo-This function accepts...
please use the c language
Assignment 12 The program to write in this assignment is a program that calculates score statistics and manages the grades of the students. First, the student list and are given in a file named "student.dat" as in the following: 이성우 77 홍길동 88 scores 201 1710086 2012700091 This program reads the input file "student.dat" and keeps this data in a linear linked list. Each node must be a struct which contains the following: student id...
Assignment Write a menu-driven C++ program to manage a class roster of student names that can grow and shrink dynamically. It should work something like this (user input highlighted in blue): Array size: 0, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: a[ENTER] Enter the student name to add: Jonas-Gunnar Iversen[ENTER] Array size: 1, capacity: 2 MENU A Add a student D Delete a student L List all students...
Write a menu-driven C++ program to manage a class roster of student names that can grow and shrink dynamically. It should work something like this (user input highlighted in blue): Array size: 0, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: a[ENTER] Enter the student name to add: Jonas-Gunnar Iversen[ENTER] Array size: 1, capacity: 2 MENU A Add a student D Delete a student L List all students Q...