1 answer

Write a C++ program to manage a list of students waiting to register for a course...

Question:

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


Answers

#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

.

Similar Solved Questions

1 answer
Which of the following elements is being oxidized in the reaction below? Cu (s) + 2AgNO3...
Which of the following elements is being oxidized in the reaction below? Cu (s) + 2AgNO3 (aq) + 2Ag (s) + Cu(NO3)2 (aq) Cu(NO3)2 Ag o Cu ON...
1 answer
汐 what is the nursing care plan for apetiol' Complaining of Rain in left knee? ai
汐 what is the nursing care plan for apetiol' Complaining of Rain in left knee? ai...
1 answer
Find all functions #f : R# \ #{-1} -> R# such that #[f(x)f(z)]/[y+1] = [f(y)f(z)]/[x+1]# whenever #x,y# and #z# do not equal #-1#?
Find all functions #f : R# \ #{-1} -> R# such that #[f(x)f(z)]/[y+1] = [f(y)f(z)]/[x+1]# whenever #x,y# and #z# do not equal #-1#?...
1 answer
Consider the reaction: #P_(4(s))+3NaOH_((aq))+3H_2O_((l))rarrPH_(3(g))+3H_2PO_(2(aq)# Is this an oxidation reaction or a reduction reaction ?
Consider the reaction: #P_(4(s))+3NaOH_((aq))+3H_2O_((l))rarrPH_(3(g))+3H_2PO_(2(aq)# Is this an oxidation reaction or a reduction reaction ?...
1 answer
Given your age (28 years & 11 months), and assume average stock market return is 10%...
Given your age (28 years & 11 months), and assume average stock market return is 10% per year; how much per month you should save (In IRA or IRA type, tax defer) in order to accumulate $1,000,000.00 when you get to 67 retirement age?...
1 answer
In the Problem of Social Cost, Professor Coase describes how liability rules and property rights can be used to efficien...
In the Problem of Social Cost, Professor Coase describes how liability rules and property rights can be used to efficiently resolve inefficient disputes over resource use if there were no costs associated with market transactions. What are some examples of the costs of market transactions and what d...
1 answer
High Country, Inc., produces and sells many recreational products. The company has just opened a new...
High Country, Inc., produces and sells many recreational products. The company has just opened a new plant to produce a folding camp cot that will be marketed throughout the United States. The following cost and revenue data relate to May, the first month of the plant’s operation: Begi...
1 answer
Low carb n=77 average weight loss 4.7kg standard deviation7.2kg low fat n=79 average weight loss 2.6kg...
low carb n=77 average weight loss 4.7kg standard deviation7.2kg low fat n=79 average weight loss 2.6kg standard deviation5.9kg For this problem, the degrees of freedom is 147, which gives the critical t-value for a 95% confidence interval to be TC = 1.992. Use this value and the values in the ...
1 answer
78) All of the followings are parts of a needle except? A. Plunger B. Bevel C....
78) All of the followings are parts of a needle except? A. Plunger B. Bevel C. Hilt D. Hub 79) The smallest filter that can be used to withdraw medications is a A. Filter straw B. Filter needle C. 5 micrometer filter D. 0.22 micrometer filter...
1 answer
Need help with all blanks! B My Ne ColFunPhys1 6.P.018. 5. -/1 points How far above...
need help with all blanks! B My Ne ColFunPhys1 6.P.018. 5. -/1 points How far above the surface of the earth would you have to be before your weight is reduced by 12.42%? D My No 6. ColFunPhys1 6.P.020. 2/4 points Previous Answers (a) A 1.03 kg mass is at the center of a uniform spherical shell o...
1 answer
On December 31, 2021, Newton LeaseCorp. leased equipment to Worcester Construction for a four-year period ending...
On December 31, 2021, Newton LeaseCorp. leased equipment to Worcester Construction for a four-year period ending December 31, 2025, at which time possession of the leased asset will revert back to Newton LeaseCorp. The equipment cost Newton LeaseCorp. $347,516 and has an expected useful life of six ...
1 answer
Eggplants in Thailand are 1.24 baht per kilogram, where one dollar is worth 1.37 baht
Eggplants in Thailand are 1.24 baht per kilogram, where one dollar is worth 1.37 baht. What is the price of eggplants in dollars per pound?...
1 answer
What does it mean for an electronic health system to be interoperable? Your answers to the...
What does it mean for an electronic health system to be interoperable? Your answers to the questions should be at least more 50 words and should be based on your own words and understanding...
1 answer
3 is represented as a power series: (1 point) The function f(x) 1+36x2 Σ f(x) -...
3 is represented as a power series: (1 point) The function f(x) 1+36x2 Σ f(x) - n-0 Find the first few coefficients in the power series. CO CI C2 C3 CA Find the radius of convergence R of the series R =...
1 answer
If y varies inversely as x, find the constant of variation and the inverse variation equation given y=110 and x=6?
If y varies inversely as x, find the constant of variation and the inverse variation equation given y=110 and x=6?...
1 answer
Can someone explain the Bronsted-Lowry definition of acids and bases?
I get that the acid donates an H ion and the base excepts. However, it says, "To recognize a Bronsted-Lowry acid, look for the H at the beginning of the formula. Then it says, "To recognize a Bronsted-Lowry base, first make sure it is not an acid. Then, look for the N in the formula. Where ...