Question

Program Specifications: Write a C++ program to manage a list of students waiting to register for a course using a linked list

please make sure rubics

... AT&T 12:41 PM 65% < Back Project 5 Rubrics Output is attractive with appropriate white space 5 points Program executes wi
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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);
}

Add a comment
Know the answer?
Add Answer to:
please make sure rubics Program Specifications: Write a C++ program to manage a list of students...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program to manage a list of students waiting to register for a course...

    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...

    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...

  • In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, t...

    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...

    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....

    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...

    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...

    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...

    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...

  • C# Write a program that takes a list of information and grades of the students of...

    C# Write a program that takes a list of information and grades of the students of a class and perform some processing. Take the following steps to write the program. The program must give the user two options such as a menu. At the beginning of the program must ask the following from the user: Which task you want to do (choose an option between 1-2), 1- Entering new information 2- Searching a student If the user types something rather...

  • Please use C++ CS3358 Insert and delete a node Programming Project 2: The linked list -...

    Please use C++ CS3358 Insert and delete a node Programming Project 2: The linked list - Reference: chapter 18: Create an array of 15 student records that should not be sorted Create a liked list of 15 student record nodes. Each node is a node of one student record from the above unsorted array. The list of student records should be sorted by student ID. (Insert function without sort function to create a linked list.) (If you insert correctly, the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT