Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you fix my code the error are line 2 5 ' it ' does not name a type, line 2 7 expected primary -

Can you fix my code the error are line 25'it' does not name a type, line 27 expected primary-expression before ')' token, line 29'it' was not declared in this scope, line 38 range-based 'for' loops are not allowed in C++98 mode, line 39 request for member 'firstName', 'lastName', 'id', 'gpa' in student, which is of non class type 'const int', line 45'it does not name a type, line 47 expected primary expression before ')' token, line 49'it' was not declared in this scope, line 52 'nullptr' was not declared in this scope, line 83 passing 'const StudentList' as ;this' argument of 'Student* StudentList::findStudent(const string&)' discards qualifiers [-fpermissive] : #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 addStudent(const Student &student){
students.push_front(student);
}
void deleteStudent(const string &id){
line 25: auto it = find_if(students.begin(), students.end(),[&](const Student &s){
line 27: });
line 29: if (it != students.end()){
students.erase(it);
cout << "Student ID: "<< id <<" has been deleted" << endl;
} else {
cout << "Student ID: "<< id <<" not found" << endl;
}
}
void print() const { line 38: for (const auto &student : students){
line 39: cout << student.firstName <<""<< student.lastName <<""<< student.id <<""<< student.gpa << endl;
}
cout << endl;
}
Student* findStudent(const string &id){
line 45: auto it = find_if(students.begin(), students.end(),[&](const Student &s){
return s.id == id;
line 47: });
line 49: if (it != students.end()){
return &(*it);
} else {
line 52: return nullptr;
}
}
void changeStudent(const string &id, double newGpa){
Student *student = findStudent(id);
if (student){
student->gpa = newGpa;
} else {
cout << "Student ID: "<< id <<" not found" << endl;
}
}
};
void processAdd(StudentList &students){
Student s;
infile >> s.firstName >> s.lastName >> s.id >> s.gpa;
students.addStudent(s);
students.print();
}
void processDelete(StudentList &students){
string id;
infile >> id;
students.deleteStudent(id);
students.print();
}
void processSearch(const StudentList &students){
string id;
infile >> id;
line 83: Student *student = students.findStudent(id);
if (student){
cout << "Information Located: "<< student->firstName <<""<< student->lastName <<""<< student->id <<""<< student->gpa << endl;
} else {
cout << "Information for Student ID: "<< id <<" not found." << endl;
}
}
void processChange(StudentList &students){
string id;
double newGpa;
infile >> id >> newGpa;
students.changeStudent(id, newGpa);
students.print();
}
int main(){
char code;
StudentList students;
infile.open("updates.txt");
while (infile >> code){
switch (code){
case 'A':
case 'a':
processAdd(students);
break;
case 'D':
case 'd':
processDelete(students);
break;
case 'S':
case 's':
processSearch(students);
break;
case 'C':
case 'c':
processChange(students);
break;
default:
cout << "Invalid code "<< code << endl;
break;
}
}
infile.close();
return 0;
}

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

More Books

Students also viewed these Databases questions