College of Science, Engineering and Technology
⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄⋄
COS3711: Advanced Programming
Assignment 3 — 2026
⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄⋄
COS3711
Module Code:
Advanced Programming
Module Name:
Assignment 3
Assignment:
2026
Year:
Submitted in partial fulfilment of the require-
ments for Advanced Programming — UNISA 2026
, UNISA | COS3711 Advanced Programming – Assignment 3
Question 1: GetStudent – GUI with Input Masks and Regular Expression Validation
The GetStudent application is a standalone Qt GUI program that collects a student number,
module code, and mark from the user. Input masks provide first-level formatting guidance,
while QRegularExpression validators enforce the exact rules specified in the assignment.
On submission, the data is printed to standard output so that a parent process can read it in
Question 2 (Blanchette and Summerfield, 2008).
1.1 Validation Rules
The three fields and their rules are:
Table 1: Input validation rules for GetStudent
Field Rule Regex Pattern
Student Number Exactly 4 digits ^[0-9]{4}$
Module Code 3 uppercase letters, then 1/2/3, ^[A-Z]{3}[123][0-9]{2}[A-Za-z0-9]$
then 2 digits, then 1 alphanumeric
Mark Integer 0 to 100 ^(100|[0-9]{1,2})$
1.2 getstudent.h
1 # ifndef GETSTUDENT_H
2 # define GETSTUDENT_H
3
4 # include < QMainWindow >
5 # include < QRegularExpressionValidator >
6
7 Q T_ BE GI N_NA ME SP AC E
8 namespace Ui { class GetStudent ; }
9 QT_END_NAMESPACE
10
11 class GetStudent : public QMainWindow {
12 Q_OBJECT
13 public :
14 explicit GetStudent ( QWidget * parent = nullptr ) ;
15 ~ GetStudent () ;
16
17 private slots :
Page 2 of 23
, UNISA | COS3711 Advanced Programming – Assignment 3
18 void o n _ a d d B u t t o n _ c l i c k e d () ;
19
20 private :
21 Ui :: GetStudent * ui ;
22 bool validateInputs ( QString & errorMsg ) ;
23 };
24
25 # endif // GETSTUDENT_H
1.3 getstudent.cpp
1 # include " getstudent . h "
2 # include " ui_getstudent . h "
3 # include < QRegularExpression >
4 # include < QRegularExpressionValidator >
5 # include < QMessageBox >
6 # include < QTextStream >
7 # include < iostream >
8
9 GetStudent :: GetStudent ( QWidget * parent )
10 : QMainWindow ( parent ) , ui ( new Ui :: GetStudent )
11 {
12 ui - > setupUi ( this ) ;
13
14 // -- Input masks give the user a visual format guide --
15 // Student number : 4 digits
16 ui - > studentNumberEdit - > setInputMask ( " 9999 " ) ;
17
18 // Module code : 3 uppercase letters + [123] + 2 digits + 1 alphanum
19 // No built - in mask for mixed alpha / digit at position 4 , so we use
20 // a validator instead and guide with placeholder text .
21 ui - > moduleCodeEdit - > set Pl ac eh ol de rT ex t ( " e . g . COS3711A " ) ;
22 ui - > moduleCodeEdit - > setMaxLength (7) ;
23
24 // Mark : up to 3 digits
25 ui - > markEdit - > setInputMask ( " 900 " ) ; // allows 0 -999; regex tightens
to 0 -100
26
Page 3 of 23