College of Science, Engineering and Technology
⋄
ASSIGNMENT 3
Year Module — 2026
⋄
Module Code: COS3711
Module Name: Advanced Programming
Assignment No.: 3
Semester: Year Module 2026
, UNISA | COS3711 Assignment 3 — Advanced Programming
Question 1: GetStudent GUI with Input Masks and Regex Validation
This question asks for a standalone Qt GUI application (called GetStudent) that collects a
student number, module code, and mark from the user, then prints them to standard output.
The output is deliberately kept simple because Question 2 reads it via QProcess.
1.1 Input Validation Rules
The three fields have precise format requirements. A QRegularExpression validator is ap-
plied to each QLineEdit so the user cannot submit malformed data.
Table 1: Validation rules for GetStudent fields
Field Rule Regex
Student number Exactly 4 digits ^\d{4}$
Module code 3 uppercase letters, then 1/2/3, ^[A-Z]{3}[123]\d{2}[\w]$
then 2 digits, then any char
Mark Integer 0 to 100 ^(100|[1-9]?\d)$
1.2 Project Structure
The GetStudent project consists of: main.cpp, getstudentwindow.h, and getstudentwindow.cpp.
No .ui file is required; the layout is built in code.
getstudentwindow.h
Listing 1: getstudentwindow.h
1 # ifndef G ETSTUDENTWINDOW_H
2 # define G ETSTUDENTWINDOW_H
3
4 # include < QWidget >
5 # include < QLineEdit >
6 # include < QPushButton >
7 # include < QLabel >
8
9 class GetStudentWindow : public QWidget {
10 Q_OBJECT
11 public :
12 explicit GetStudentWindow ( QWidget * parent = nullptr ) ;
13
Page 2 of 27
, UNISA | COS3711 Assignment 3 — Advanced Programming
14 private slots :
15 void onAdd () ;
16
17 private :
18 QLineEdit * studentNumEdit ;
19 QLineEdit * moduleCodeEdit ;
20 QLineEdit * markEdit ;
21 QPushButton * addBtn ;
22 QLabel * statusLabel ;
23
24 bool validate () ;
25 };
26
27 # endif // GETSTUDENTWINDOW_H
getstudentwindow.cpp
Listing 2: getstudentwindow.cpp
1 # include " getstudentwindow . h "
2 # include < QVBoxLayout >
3 # include < QHBoxLayout >
4 # include < QFormLayout >
5 # include < QRegularExpression >
6 # include < QRegularExpressionValidator >
7 # include < QMessageBox >
8 # include < QTextStream >
9 # include < iostream >
10
11 GetStudentWindow :: GetStudentWindow ( QWidget * parent )
12 : QWidget ( parent )
13 {
14 setWindowTitle ( " GetStudent " ) ;
15
16 // -- Student number : exactly 4 digits
17 studentNumEdit = new QLineEdit ;
18 studentNumEdit - > setInputMask ( " 9999 " ) ; // forces 4 - digit entry
19 studentNumEdit - > setPlaceholderText ( " e . g . 1234 " ) ;
20
21 // -- Module code validator : [A - Z ]{3}[123]\ d {2}[\ w ]
22 moduleCodeEdit = new QLineEdit ;
23 Q Reg ularExpression modRx ( " ^[ A - Z ]{3}[123]\\ d {2}[ A - Za - z0 -9] $ " ) ;
Page 3 of 27