0% found this document useful (0 votes)
7 views3 pages

Student Enrollment System Code

The document contains a C++ implementation of an Enrollment System for managing student records. It includes functionalities to add, display, search, update, and delete student information using a linked list structure. The main function provides a user interface for interacting with the system through a menu-driven approach.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Student Enrollment System Code

The document contains a C++ implementation of an Enrollment System for managing student records. It includes functionalities to add, display, search, update, and delete student information using a linked list structure. The main function provides a user interface for interacting with the system through a menu-driven approach.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

\\source code

#include <iostream>
#include <string>

using namespace std;

struct Student {
int id;
string name;
int age;
string course;
Student* next;
};

class EnrollmentSystem {
private:
Student* head;

public:
EnrollmentSystem() : head(nullptr) {}

void addStudent(int id, const string& name, int age, const string& course) {
Student* newStudent = new Student{id, name, age, course, head};
head = newStudent;
}

void displayStudents() {
Student* current = head;
while (current != nullptr) {
cout << "\nID: " << current->id << "\nName: " << current->name
<< "\nAge: " << current->age << "\nCourse: " << current->course <<
endl;
current = current->next;
}
}

Student* searchStudentById(int id) {


Student* current = head;
while (current != nullptr) {
if (current->id == id) {
return current;
}
current = current->next;
}
return nullptr;
}

Student* searchStudentByName(const string& name) {


Student* current = head;
while (current != nullptr) {
if (current->name == name) {
return current;
}
current = current->next;
}
return nullptr;
}

void updateStudent(int id, const string& name, int age, const string& course) {
Student* student = searchStudentById(id);
if (student != nullptr) {
student->name = name;
student->age = age;
student->course = course;
} else {
cout << "Student not found!" << endl;
}
}

void deleteStudent(int id) {


Student* current = head;
Student* previous = nullptr;
while (current != nullptr && current->id != id) {
previous = current;
current = current->next;
}
if (current == nullptr) {
cout << "Student not found!" << endl;
return;
}
if (previous == nullptr) {
head = current->next;
} else {
previous->next = current->next;
}
delete current;
cout << "Student deleted successfully." << endl;
}
};

int main() {
EnrollmentSystem system;
int choice, id, age;
string name, course;

while (true) {
cout << "\n**********ENROLLMENT SYSTEM***************\n";
cout << "\n1. Add Student\n2. Display Students\n3. Search Student by ID\n4.
Search Student by Name\n5. Update Student\n6. Delete Student\n7. Exit\n";
cout << "Enter your choice: ";
cin >> choice;

switch (choice) {
case 1:
cout << "Enter ID: ";
cin >> id;
[Link]();
cout << "Enter Name: ";
getline(cin, name);
cout << "Enter Age: ";
cin >> age;
[Link]();
cout << "Enter Course: ";
getline(cin, course);
[Link](id, name, age, course);
cout << "\nStudent Added Successfully!\n";
break;
case 2:
[Link]();
break;
case 3:
cout << "Enter ID: ";
cin >> id;
if (Student* student = [Link](id)) {
cout << "ID: " << student->id << "\nName: " << student->name
<< "\nAge: " << student->age << "\nCourse: " << student-
>course << endl;
} else {
cout << "Student not found!" << endl;
}
break;
case 4:
[Link]();
cout << "Enter Name: ";
getline(cin, name);
if (Student* student = [Link](name)) {
cout << "ID: " << student->id << "\nName: " << student->name
<< "\nAge: " << student->age << "\nCourse: " << student-
>course << endl;
} else {
cout << "Student not found!" << endl;
}
break;
case 5:
cout << "Enter ID: ";
cin >> id;
[Link]();
cout << "Enter new Name: ";
getline(cin, name);
cout << "Enter new Age: ";
cin >> age;
[Link]();
cout << "Enter new Course: ";
getline(cin, course);
[Link](id, name, age, course);
cout << "\nUpdate Successful!\n";
break;
case 6:
cout << "Enter ID: ";
cin >> id;
[Link](id);
cout << "\nDeletion is sucessful.\n";
break;
case 7:
return 0;
default:
cout << "Invalid choice. Please try again." << endl;
}
}

return 0;
}

You might also like