System Overview
A course selection system for educational institutions with three primary roles: Student, Administrator, and Instructor.
Core Functionalities
- Authentication: All users log in with credentials; system identifies role upon successufl login.
- Course Selection: Students enroll in available courses.
- User Management: Administrators create student and instructor accounts.
- Data Viewing:
- Students view their enrolled courses.
- Administrators access all student records and enrollment data.
- Instructors see assigned classes and student rosters.
Role-Specific Workflows
Student
- Browse available courses
- Select courses
- View personal course selections
- Exit system
Administrator
- Create new courses
- Register student accounts
- View all courses
- View all students
- Review student enrollments
- Register instructors
- Assign classes to instructors
- Create class groups
- Assign students to classes
- Exit system
Instructor
- View available courses
- See assigned classes
- View class rosters
- Exit system
Technical Implemantation
File Structure
project/
├── bin/
│ └── start.py # Entry point
├── conf/
│ └── settings.py # Path configurations
├── core/
│ ├── auth.py # Authentication logic
│ └── cores.py # Main application logic
└── db/ # Data storage
├── courseinfo
├── gradeinfo
├── select_course
├── student_grade
├── tearch_grade
└── userinfo
Key Code Snippets
Entry Point (bin/start.py)
import os
import sys
from core import cores
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)
if __name__ == '__main__':
cores.start()
Configuration (conf/settings.py)
import os
DB_DIR = os.path.join(os.path.dirname(__file__), '../db')
PATHS = {
'USER_DATA': os.path.join(DB_DIR, 'userinfo'),
'COURSE_DATA': os.path.join(DB_DIR, 'courseinfo'),
'ENROLLMENT_DATA': os.path.join(DB_DIR, 'select_course'),
'CLASS_DATA': os.path.join(DB_DIR, 'gradeinfo'),
'INSTRUCTOR_ASSIGNMENTS': os.path.join(DB_DIR, 'tearch_grade'),
'STUDENT_CLASSES': os.path.join(DB_DIR, 'student_grade')
}
Authentication (core/auth.py)
import hashlib
from conf.settings import PATHS
SALT = 'system_salt'
def hash_password(password: str) -> str:
hasher = hashlib.md5(SALT.encode())
hasher.update(password.encode())
return hasher.hexdigest()
def authenticate():
username = input('Username: ')
password = input('Password: ')
with open(PATHS['USER_DATA'], 'r') as f:
for line in f:
user, pwd_hash, role = line.strip().split('|')
if user == username and pwd_hash == hash_password(password):
return {'username': username, 'role': role}
print('Invalid credentials')
return {'username': None, 'role': None}
Main Application Logic (core/cores.py)
import sys
import pickle
from core.auth import authenticate
from conf.settings import PATHS
class CourseCatalog:
@staticmethod
def display_courses():
with open(PATHS['COURSE_DATA'], 'rb') as f:
try:
while True:
course = pickle.load(f)
print(f"Course: {course.name}, Price: {course.price}, Duration: {course.duration}, Instructor: {course.instructor}")
except EOFError:
pass
class Course:
def __init__(self, name, price, duration, instructor):
self.name = name
self.price = price
self.duration = duration
self.instructor = instructor
class Student:
ACTIONS = [
('Browse Courses', 'view_catalog'),
('Enroll in Course', 'enroll'),
('View My Courses', 'view_enrollments'),
('Exit', 'exit')
]
def __init__(self, username):
self.username = username
self.enrolled = []
def view_catalog(self):
CourseCatalog.display_courses()
def enroll(self):
CourseCatalog.display_courses()
course_name = input('Course to enroll: ')
if course_name in self.enrolled:
print('Already enrolled')
return
self.enrolled.append(course_name)
with open(PATHS['ENROLLMENT_DATA'], 'ab') as f:
pickle.dump({self.username: self.enrolled}, f)
print(f'Enrolled in {course_name}')
def view_enrollments(self):
print(f"Your courses: {', '.join(self.enrolled)}")
def exit(self):
sys.exit()
# Administrator and Instructor classes follow similar patterns
# Full implementation would include all specified functionalities
def start():
user = authenticate()
if not user['role']:
return
role_class = getattr(sys.modules[__name__], user['role'])
user_instance = role_class(user['username'])
while True:
print("Available actions:")
for idx, (desc, _) in enumerate(user_instance.ACTIONS, 1):
print(f"{idx}. {desc}")
choice = int(input("Selection: ")) - 1
action_name = user_instance.ACTIONS[choice][1]
getattr(user_instance, action_name)()
Data Storage
Database files (db/ directory) store:
userinfo: User credentials and rolescourseinfo: Course detailsselect_course: Student enrollmentsgradeinfo: Class informationtearch_grade: Instructor-class assignmentsstudent_grade: Student-class assignments