Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you fix my code: #include #include #include #include using namespace std; ifstream infile; struct Student { string firstName; string lastName; string id; double gpa;
Can you fix my code: #include
#include
#include
#include
using namespace std;
ifstream infile;
struct Student
string firstName;
string lastName;
string id;
double gpa;
;
class StudentList
list students;
public:
void addStudentconst Student &student
students.pushfrontstudent;
void deleteStudentconst string &id
auto it findifstudentsbegin students.end&const Student &s
return sid id;
;
if it students.end
students.eraseit;
cout "Student ID: id has been deleted" endl;
else
cout "Student ID: id not found" endl;
void print const
for const auto &student : students
cout student.firstName student.lastName student.id student.gpa endl;
cout endl;
Student findStudentconst string &id
auto it findifstudentsbegin students.end&const Student &s
return sid id;
;
if it students.end
return ⁢
else
return nullptr;
void changeStudentconst string &id double newGpa
Student student findStudentid;
if student
studentgpa newGpa;
else
cout "Student ID: id not found" endl;
;
void processAddStudentList &students
Student s;
infile sfirstName slastName sid sgpa;
students.addStudents;
students.print;
void processDeleteStudentList &students
string id;
infile id;
students.deleteStudentid;
students.print;
void processSearchconst StudentList &students
string id;
infile id;
Student student students.findStudentid;
if student
cout "Information Located: studentfirstName studentlastName studentid studentgpa endl;
else
cout "Information for Student ID: id not found." endl;
void processChangeStudentList &students
string id;
double newGpa;
infile id newGpa;
students.changeStudentid newGpa;
students.print;
int main
char code;
StudentList students;
infile.openupdatestxt;
while infile code
switch code
case A:
case a:
processAddstudents;
break;
case D:
case d:
processDeletestudents;
break;
case S:
case s:
processSearchstudents;
break;
case C:
case c:
processChangestudents;
break;
default:
cout "Invalid code code endl;
break;
infile.close;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started