Question

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. Function main() should be SMALL.

Be sure to use good programming methodology and keep your project modular.

Functions/Methods created and called:

- add student at the end of the list

- add student at the beginning of the list

- remove student from the end of the list

- remove student from the beginning of the list

- remove student by name

- display the list of students

- exit

Please keep main() function small

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream.h>

#include<string.h>

#include<stdio.h>

#include<stdlib.h>

#include<conio.h>

/*

* Node Declaration

*/

struct node

{

int id;

char name[50],course[50];

struct node *next;

}*start;

/*

* Class Declaration

*/

class single_llist

{

public:

node* create_node(int,char [],char []);

void insert_begin();

void insert_pos();

void insert_last();

void delete_name();

void delete_beg();

void delete_last();

void display();

single_llist()

{

start = NULL;

}

};

/*

* Main :contains menu

*/

main()

{

int choice, nodes, element, position, i;

single_llist sl;

start = NULL;

clrscr();

while (1)

{

cout<<endl<<"---------------------------------"<<endl;

cout<<endl<<"Operations on singly linked list"<<endl;

cout<<endl<<"---------------------------------"<<endl;

cout<<"1.Add Student at beginning"<<endl;

cout<<"2.Add Student at last"<<endl;

cout<<"3.Remove Student from Last"<<endl;

cout<<"4.Remove Student from beginning"<<endl;

cout<<"5.Remove Student by name"<<endl;

cout<<"6.Display Linked List"<<endl;

cout<<"7.Exit "<<endl;

cout<<"Enter your choice : ";

cin>>choice;

switch(choice)

{

case 1:

cout<<"Add Student Node at Beginning: "<<endl;

sl.insert_begin();

cout<<endl;

break;

case 2:

cout<<"Add Student Node at Last: "<<endl;

sl.insert_last();

cout<<endl;

break;

case 3:

cout<<"Delete Student from last "<<endl;

sl.delete_last();

break;

case 4:

cout<<"Delete Student from begin "<<endl;

sl.delete_beg();

break;

case 5:

cout<<"Delete Student by name "<<endl;

sl.delete_name();

break;

case 6:

cout<<"Display elements of link list"<<endl;

sl.display();

cout<<endl;

break;

case 7:

cout<<"Exiting..."<<endl;

exit(1);

break;

default:

cout<<"Wrong choice"<<endl;

}

}

}

/*

* Creating Node

*/

node *single_llist::create_node(int value,char n[50],char c[50])

{

struct node *temp, *s;

temp = new(struct node);

if (temp == NULL)

{

cout<<"Memory not allocated "<<endl;

return 0;

}

else

{

temp->id = value;

strcpy(temp->name,n);

strcpy(temp->course,c);

temp->next = NULL;

return temp;

}

}

/*

* Inserting element in beginning

*/

void single_llist::insert_begin()

{

int value;

char n[50],c[50];

cout<<"Enter the Id number to be registered: ";

cin>>value;

cout<<"Enter the name ";

gets(n);

cout<<"\n Enter the course name";

gets(c);

struct node *temp, *p;

temp = create_node(value,n,c);

if (start == NULL)

{

start = temp;

start->next = NULL;

}

else

{

p = start;

start = temp;

start->next = p;

}

cout<<"Element Inserted at beginning"<<endl;

}

/*

* Inserting Node at last

*/

void single_llist::insert_last()

{

int value;

char n[50],c[50];

cout<<"Enter the Id number to be registered: ";

cin>>value;

cout<<"Enter the name ";

gets(n);

cout<<"\n Enter the course name";

gets(c);

struct node *temp, *s;

temp = create_node(value,n,c);

s = start;

while (s->next != NULL)

{

s = s->next;

}

temp->next = NULL;

s->next = temp;

cout<<"Element Inserted at last"<<endl;

}

/*

* Delete when name is given

*/

void single_llist::delete_name()

{

int i, counter = 0;

char n[50];

if (start == NULL)

{

cout<<"List is empty"<<endl;

return;

}

cout<<"Enter the NAME TO DELETE: ";

gets(n);

struct node *s, *ptr;

s = start;

while (s != NULL)

{

s = s->next;

counter++;

}

s=start;

if(counter==1 && strcmp(n,s->name)==0)

{

start= s->next; free(s);

}

else

{

s=start;

ptr=start->next;

while(s!=NULL)

{

if(strcmp(n,ptr->name)==0)

{

s->next = ptr->next;

free(ptr);

}

else

{

s=s->next;

ptr=ptr->next;

}

}

}

}

/***DELETION OF A STUDENT FROM LAST***********/

void single_llist::delete_last()

{

int pos, i, counter = 0;

if (start == NULL)

{

cout<<"List is empty"<<endl;

return;

}

struct node *s, *ptr;

s = start;

while (s != NULL)

{

s = s->next;

counter++;

}

s = start;

if(counter==1)

{

start= s->next; free(s);

return;

}

cout<<"List having"<<counter<<"number of nodes";

s = start;

for (i = 1;i < counter;i++)

{

ptr = s;

s = s->next;

}

ptr->next = s->next;

free(s);

cout<<"Element Deleted"<<endl;

}

/******DELETE FROM THE BEGINNING***********/

void single_llist::delete_beg()

{

if (start == NULL)

{

cout<<"List is empty"<<endl;

return;

}

struct node *s, *ptr;

s = start;

start = s->next;

free(s);

cout<<"Element Deleted"<<endl;

}

/*

* Display Elements of a link list

*/

void single_llist::display()

{

struct node *temp;

if (start == NULL)

{

cout<<"The List is Empty"<<endl;

return;

}

temp = start;

cout<<"Elements of list are: "<<endl;

while (temp != NULL)

{

cout<<"\n "<<temp->id<<" "<<temp->name<<" "<<temp->course;

temp = temp->next;

}

}

OUTPUT

Operations on singly linked list 1.Add Student at beginning 2.Add Student at last 3. Remove Student from Last 4. Remove Student from begining 5.Remove Student by name 6.Display Linked List 7.Exit Enter your choice 1 Add Student Node at Beginning: Enter the Id number to be reqistered 101 Enter the name JOHN Enter the course nameBBA

Add a comment
Know the answer?
Add Answer to:
Write a C++ program to manage a list of students waiting to register for a course...
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
  • please make sure rubics Program Specifications: Write a C++ program to manage a list of students...

    please make sure rubics Program Specifications: 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....

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

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

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

  • Derive a class called Stack from the linked list described in Assignment 2 (list of Dates)....

    Derive a class called Stack from the linked list described in Assignment 2 (list of Dates). This means the Stack class will inherit all the properties (data and functions) of the linked list. But, since a stack only allows pushing and popping at the front of the list only, you will need to prevent the operations at the back. To do this, derive the Stack class in such a way that the base class (LinkedList) functions become private in the...

  • C++ program Write a C++ program to manage a hospital system, the system mainly uses file...

    C++ program Write a C++ program to manage a hospital system, the system mainly uses file handling to perform basic operations like how to add, edit, search, and delete record. Write the following functions: 1. hospital_menu: This function will display the following menu and prompt the user to enter her/his option. The system will keep showing the menu repeatedly until the user selects option 'e' from the menu. Arkansas Children Hospital a. Add new patient record b. Search record c....

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

  • Write a Python program (remove_first_char.py) that removes the first character from each item in a list...

    Write a Python program (remove_first_char.py) that removes the first character from each item in a list of words. Sometimes, we come across an issue in which we require to delete the first character from each string, that we might have added by mistake and we need to extend this to the whole list. Having shorthands (like this program) to perform this particular job is always a plus. Your program should contain two functions: (1) remove_first(list): This function takes in a...

  • Write in c++ please Imagine you are writing a program to manage a shopping list. Each...

    Write in c++ please Imagine you are writing a program to manage a shopping list. Each shopping list item is represented by a string stored in a container. Your design requires a print function that prints out the contents of the shopping list Using a vector to hold the shopping list items, write a print function to print out the contents of a vector of strings. Test your print function with a main program that does the following: 1. Create...

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