0% found this document useful (0 votes)
7 views

Course Management System Code

The document contains a C++ implementation of a university registration system, featuring classes for students, courses, a registration queue, and a drop action stack. It allows students to enroll in and drop courses, view available courses, and undo drop actions. The main function demonstrates user login and provides a menu for interacting with the system.

Uploaded by

f2023376146
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Course Management System Code

The document contains a C++ implementation of a university registration system, featuring classes for students, courses, a registration queue, and a drop action stack. It allows students to enroll in and drop courses, view available courses, and undo drop actions. The main function demonstrates user login and provides a menu for interacting with the system.

Uploaded by

f2023376146
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

NAME: Fajar Eman & Abdullah Tariq

ID: F2023376120 & F2023376146

#include <iostream>

#include <string>

using namespace std;

class Student;

class CourseNode {

public:

string courseName;

CourseNode* left;

CourseNode* right;

CourseNode(string name) {

courseName = name;

left = right = NULL;

};

class QueueNode {

public:

Student* student;
QueueNode* next;

QueueNode(Student* stu) : student(stu), next(NULL) {}

};

class RegistrationQueue {

private:

QueueNode* front;

QueueNode* rear;

public:

RegistrationQueue() : front(NULL), rear(NULL) {}

void enqueue(Student* student) {

QueueNode* newNode = new QueueNode(student);

if (rear == NULL) {

front = rear = newNode;

} else {

rear->next = newNode;

rear = newNode;

Student* dequeue() {

if (front == NULL) {

return NULL;

}
QueueNode* temp = front;

Student* student = front->student;

front = front->next;

delete temp;

if (front == NULL) {

rear = NULL;

return student;

bool isEmpty() {

return front == NULL;

};

class StackNode {

public:

string action;

StackNode* next;

StackNode(string actionValue) : action(actionValue), next(NULL) {}

};

class DropActionStack {

private:

StackNode* top;
public:

DropActionStack() : top(NULL) {}

void push(string action) {

StackNode* newNode = new StackNode(action);

newNode->next = top;

top = newNode;

string pop() {

if (top == NULL) {

return "";

StackNode* temp = top;

string action = top->action;

top = top->next;

delete temp;

return action;

bool isEmpty() {

return top == NULL;

};

class Student {

public:
string studentName;

string studentID;

string password;

string enrolledCourses[8];

int courseCount;

Student(string name, string id, string pwd) {

studentName = name;

studentID = id;

password = pwd;

courseCount = 0;

void enrollCourse(string courseName) {

if (courseCount < 8) {

enrolledCourses[courseCount] = courseName;

courseCount++;

void dropCourse(string courseName) {

for (int i = 0; i < courseCount; i++) {

if (enrolledCourses[i] == courseName) {

for (int j = i; j < courseCount - 1; j++) {

enrolledCourses[j] = enrolledCourses[j + 1];

courseCount--;
break;

void viewEnrolledCourses() {

if (courseCount == 0) {

cout << "You are not enrolled in any courses.\n";

} else {

cout << "Your Enrolled Courses:\n";

for (int i = 0; i < courseCount; i++) {

cout << (i + 1) << ". " << enrolledCourses[i] << endl;

};

class UniversitySystem {

private:

CourseNode* root;

RegistrationQueue regQueue;

DropActionStack dropStack;

public:

UniversitySystem() {

root = NULL;

}
void addCourse(CourseNode*& node, string courseName) {

if (node == NULL) {

node = new CourseNode(courseName);

} else if (courseName < node->courseName) {

addCourse(node->left, courseName);

} else {

addCourse(node->right, courseName);

void initializeCourses() {

addCourse(root, "Islamiyat");

addCourse(root, "DSA");

addCourse(root, "Programming Fundamentals");

addCourse(root, "Pak Studies");

addCourse(root, "Applied Physics");

addCourse(root, "Linear Algebra");

addCourse(root, "Probability and Statistics");

addCourse(root, "Civics");

void displayCourses(CourseNode* node, int& counter) {

if (node != NULL) {

displayCourses(node->left, counter);

cout << counter << ". " << node->courseName << endl;

counter++;
displayCourses(node->right, counter);

void showCourses() {

cout << "Available Courses: \n";

int counter = 1;

displayCourses(root, counter);

void enrollStudentInCourse(Student* student, int courseNumber) {

string courseName = getCourseByNumber(courseNumber);

if (!courseName.empty()) {

student->enrollCourse(courseName);

cout << student->studentName << " has been successfully enrolled


in " << courseName << "!\n";

regQueue.enqueue(student);

void dropStudentCourse(Student* student, int courseNumber) {

if (courseNumber < 1 || courseNumber > student->courseCount) {

cout << "Invalid course number.\n";

return;

string courseName = student->enrolledCourses[courseNumber - 1];

student->dropCourse(courseName);
cout << student->studentName << " has successfully dropped the
course " << courseName << ".\n";

dropStack.push(student->studentName + " dropped " + courseName);

void undoDrop(Student* student) {

string action = dropStack.pop();

if (!action.empty()) {

cout << "Undo action: " << action << endl;

string courseName = action.substr(action.find("dropped") + 8);

student->enrollCourse(courseName);

} else {

cout << "No drop action to undo.\n";

string getCourseByNumber(int courseNumber) {

CourseNode* node = root;

int counter = 1;

string courseName = "";

string courseList[8];

int index = 0;

storeCoursesInOrder(node, courseList, index);

if (courseNumber >= 1 && courseNumber <= index) {

courseName = courseList[courseNumber - 1];

}
return courseName;

void storeCoursesInOrder(CourseNode* node, string* courseList, int&


index) {

if (node != NULL) {

storeCoursesInOrder(node->left, courseList, index);

courseList[index++] = node->courseName;

storeCoursesInOrder(node->right, courseList, index);

Student* login(string id, string password, Student* students[], int


numStudents) {

for (int i = 0; i < numStudents; i++) {

if (students[i]->studentID == id && students[i]->password ==


password) {

return students[i];

return NULL;

void processRegistration() {

if (!regQueue.isEmpty()) {

Student* student = regQueue.dequeue();

if (student != NULL) {
cout << student->studentName << " has been successfully
registered.\n";

} else {

cout << "No registration requests in the queue.\n";

};

int main() {

Student* students[2];

students[0] = new Student("Abdullah Tariq", "F2023376146", "12345");

students[1] = new Student("Fajar Eman", "F2023376120", "123456");

UniversitySystem uniSystem;

uniSystem.initializeCourses();

string id, password;

cout << "Enter Student ID: ";

getline(cin, id);

cout << "Enter Password: ";

getline(cin, password);

Student* loggedInStudent = uniSystem.login(id, password, students, 2);

if (loggedInStudent == NULL) {

cout << "Invalid login credentials!\n";

return 0;
} else {

cout << "Login successful! Welcome, " << loggedInStudent-


>studentName << "!\n";

int choice;

do {

cout << "\nMenu:\n";

cout << "1. Enroll in a course\n";

cout << "2. Drop a course\n";

cout << "3. Undo last drop action\n";

cout << "4. View available courses\n";

cout << "5. View your enrolled courses\n";

cout << "6. Exit\n";

cout << "Enter your choice: ";

cin >> choice;

switch (choice) {

case 1:

uniSystem.showCourses();

int courseChoice;

cout << "Enter the number of the course you want to enroll in: ";

cin >> courseChoice;

uniSystem.enrollStudentInCourse(loggedInStudent, courseChoice);

break;

case 2:
loggedInStudent->viewEnrolledCourses();

int dropChoice;

cout << "Enter the number of the course you want to drop: ";

cin >> dropChoice;

uniSystem.dropStudentCourse(loggedInStudent, dropChoice);

break;

case 3:

uniSystem.undoDrop(loggedInStudent);

break;

case 4:

uniSystem.showCourses();

break;

case 5:

loggedInStudent->viewEnrolledCourses();

break;

case 6:

cout << "Exiting program.\n";

break;

default:

cout << "Invalid choice, please try again.\n";

} while (choice != 6);


return 0;

You might also like