Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLESE HELP my last post didnt go too well. ;) Need help with this. Thanks! I nee

ID: 3750682 • Letter: P

Question

PLESE HELP my last post didnt go too well. ;)

Need help with this. Thanks! I need the .cpp and the .h files if you could show where those begin please, thanks! (the student list does not need to be in order).

Design a class Student that requires a student name, student ID, and phone number.

Using linked lists, create a list of students in order by student ID. Create a menu-driven program to provide the following options:

Add a new entry to the student list.

Delete an entry from the student list

Display the list

Extra Credit: When the program terminates, write the data in the address book to a disk.

Explanation / Answer

(1)student.h

#include <iostream>

using namespace std;

struct node{

string name;

string id;

string phone_number;

struct node*next;

};

class students{

struct node*list;

public:

students();

~students();

void addnode(node*);

void deletenode(string);

void display();

};

(2)student.cpp

#include"student.h"

students::students(){

list=NULL;

}

students::~students(){

struct node*temp;

while(list){

temp=list;

list=list->next;

delete(temp);

}

}

void students::addnode(node* newnode){

if(list==NULL)list=newnode;

else list->next=newnode;

}

void students::deletenode(string i){

struct node*temp=list,*prev;

if (temp != NULL && temp->id == i)

{

list = temp->next;

delete(temp);

return;

}

while (temp != NULL && temp->id != i)

{

prev = temp;

temp = temp->next;

}

  

if (temp == NULL) {

cout<<i <<" not found in list ";

return ;

}

prev->next = temp->next;

  

delete(temp);  

}

void students::display(){

struct node*temp=list;

while(temp!=NULL){

cout<<"id : "<<temp->id<<" Name : "<<temp->name<<" PNo : "<<temp->phone_number<<" ";

temp=temp->next;

}

}

(3)main.cpp

#include "student.cpp"

int main(){

struct node*newnode;

students s;

int choice;

string name ,id,pno;

do{

cout<<"1:Add student 2:Delete student 3:Print list 4:Quit ";

cin>>choice;

getline(cin,name);

switch(choice){

case 1:{

newnode =new struct node;

cout<<"Enter name : ";

getline(cin,newnode->name);

cout<<"Enter id : ";

getline(cin,newnode->id);

cout<<"Enter phone number : ";

getline(cin,newnode->phone_number);

s.addnode(newnode);

break;

}

case 2:{

cout<<"Enter id : ";

getline(cin,id);

s.deletenode(id);

break;

}

case 3:{

cout<<" List of students ";

s.display();

break;

}

default:{

cout<<"Invalid input ";

break;

}

}

}while(choice!=4);

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote