Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

change this code to stl: #include #include #include #include using namespace std; ifstream infile; struct studentNode { string firstName; string lastName; string id; double gpa;

change this code to stl: #include
#include
#include
#include
using namespace std;
ifstream infile;
struct studentNode
{
string firstName;
string lastName;
string id;
double gpa;
studentNode * next;
};
class studentList
{
studentNode * students;
public:
void addStudent(studentNode);
void deleteStudent(studentNode*, studentNode*);
void locateStudent(string id, bool &end, studentNode *&curr, studentNode *&prev);
void changeStudent(string, bool, double, studentNode *curr);
void print();
};
void studentList::addStudent(studentNode studentRec)
{
studentNode *temp = new studentNode;
*temp = studentRec;
temp->next = students;
students = temp;
}
void studentList::deleteStudent(studentNode *curr, studentNode *prev)
{
if (prev == NULL){
students = students -> next;
}
else if (curr == NULL){
prev -> next = NULL;
}
else{
prev -> next = curr -> next;
}
}
void studentList::locateStudent(string id, bool &end, studentNode *&curr, studentNode *&prev)
{
for (studentNode *s = students; (s!= NULL) && (end == false); s = s -> next){
if (s -> id == id){
end = true;
curr = s;
}
else
prev = s;
}
}
void studentList::changeStudent(string id, bool end, double gpa, studentNode *curr)
{
if (end == true){
curr -> gpa = gpa;
}
else if (end == false){
curr == NULL;
cout <<" Student ID "<< id <<" not found" << endl;
}
}
void studentList :: print()
{
for(studentNode *s = students; s != NULL; s = s->next){
cout << s->firstName <<""<< s->lastName <<""<< s->id <<""<< s->gpa << endl;
}
cout << endl;
}
void processAdd(studentList &students)
{
studentNode s;
infile >> s.firstName;
infile >> s.lastName;
infile >> s.id;
infile >> s.gpa;
students.addStudent(s);
}
void processDelete(studentList &students)
{
bool end = false;
string id;
studentNode *curr = NULL;
studentNode *prev = NULL;
infile >> id;
students.locateStudent(id ,end ,curr ,prev);
if (end == true){
students.deleteStudent(curr,prev);
cout << "Student ID: "<< id <<" has been deleted" << endl;
}
else if (end == false){
cout << "Student cannot be found." << endl;
}
cout << endl;
}
void processSearch(studentList &students)
{
bool end = false;
string id;
studentNode *curr = NULL;
studentNode *prev = NULL;
infile >> id;
students.locateStudent(id,end,curr,prev);
if (end == true){
cout << "Information Located: "<< curr -> firstName <<""<< curr -> lastName <<""<< curr->id <<""<< curr-> gpa << endl;
}
else{
cout << "Information: "<< id <<" cannot be found.";
}
}
void processChange(studentList &students)
{
bool end = false;
string id;
double gpa;
studentNode *curr = NULL;
studentNode *prev = NULL;
infile >> id;
students.locateStudent(id,end,curr,prev);
}
int main()
{
char code;
studentList students;
infile.open("updates.txt");
while (!infile.eof())
{
infile >> code;
if (code =='A'|| code =='a')
{
processAdd(students);
students.print();
}
else if (code =='D'|| code =='d')
{
processDelete(students);
students.print();
}
else if (code =='S'|| code =='s')
processSearch(students);
else if (code =='C'|| code =='c')
{
processChange(students);
students.print();
}
else
{
cout << "Invalid code "<< code <

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building The Data Lakehouse

Authors: Bill Inmon ,Mary Levins ,Ranjeet Srivastava

1st Edition

1634629663, 978-1634629669

More Books

Students also viewed these Databases questions

Question

Describe the factors influencing of performance appraisal.

Answered: 1 week ago

Question

What is quality of work life ?

Answered: 1 week ago