A small course-scheduling demo that combines a Flask backend, a browser UI, and a C++ scheduling executable.
- Python 3
- Flask
- A C++ compiler such as
g++ - Windows can use the committed
output/schedule.exedirectly
Start the Flask server from the project root:
venv\Scripts\python.exe connector.pyOpen:
http://127.0.0.1:5000/
Live Server is no longer required. The Flask server serves the HTML, JavaScript, CSS, and API from the same port.
Each course must include:
name: non-empty course name, max 50 charactersnum: non-empty course number, max 30 charactersday: integer from1to7starttime: strictHH:MM, for example08:00endtime: strictHH:MM, and later thanstarttime
The frontend validates these rules before adding a course. The backend validates them again before calling C++.
Windows:
g++ schedule.cpp -std=c++17 -O2 -o output\schedule.exemacOS/Linux:
g++ schedule.cpp -std=c++17 -O2 -o output/scheduleThe backend looks for output/schedule.exe on Windows and output/schedule on other systems. If the executable is missing, the API response includes the compile command.
The C++ program returns structured JSON. The backend forwards it as:
{
"status": "success",
"message": "排课完成",
"schedule": {
"has_conflict": false,
"courses": [],
"conflicts": []
}
}The browser renders courses as a schedule table and conflicts as conflict details.
The page stores the current course list and last scheduling result in localStorage, so accidental refreshes do not lose data. Use clear courses and clear output to clear saved browser data.