#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Course {
string courseCode;
int creditHours;
string section;
};
vector<Course> courses;
bool isEnrolled(string studentID, string courseCode) {
for (Course course : courses) {
if (course.courseCode == courseCode) {
return true;
}
}
return false;
}
void enrollStudent() {
string studentID;
cout oaicite:{"index":2,"invalid_reason":"Malformed citation << \"Enter student ID: \";\n cin >>"} studentID;
cout << "Courses offered: " << endl;
cout << "Code\tCredits\tSection" << endl;
cout << "----------------------------" << endl;
// display list of subjects with credit hours offered
string courseCode;
int creditHours;
string section;
cout ​`oaicite:{"index":3,"invalid_reason":"Malformed citation << \"Enter course code: \";\n cin >>"}`​ courseCode;
if (isEnrolled(studentID, courseCode)) {
cout << "Error: student is already enrolled in this course." << endl;
} else {
// get credit hours and section for chosen course
cout ​`oaicite:{"index":4,"invalid_reason":"Malformed citation << \"Enter credit hours: \";\n cin >>"}`​ creditHours;
cout ​`oaicite:{"index":5,"invalid_reason":"Malformed citation << \"Enter section: \";\n cin >>"}`​ section;
// add course to array
Course course;
course.courseCode = courseCode;
course.creditHours = creditHours;
course.section = section;
courses.push_back(course);
}
}
int main() {
enrollStudent();
return 0;
}