0% found this document useful (0 votes)
15 views53 pages

Group 1 - Student Management System 2

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

Group 1 - Student Management System 2

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

Final - exam

Class : Cấu trúc dữ liệu và giải thuật INS305002


Group : 1
Project topic : Student management project using linked list
Member of group 1 :

Tạ Duy Minh (Leader) 21070412


Nguyễn Minh Đức 21070820
Phạm Nguyễn Minh Tuấn 21070571

Trương Văn An 21070551

Nguyễn Đức Huy 21070086

1
Table of content
I. Project Information ................................................................................. 2
A. Project’s plan ................................................................................... 3
B. Analysis of requirements .................................................................. 4
II. Design of the project ............................................................................. 5
A. Data structure : Linked list ................................................................ 5
B. Design algorithm ( diagram ) ............................................................ 5
III. Development of the project :............................................................... 14
A. Student class define ....................................................................... 14
B. Menu .............................................................................................. 16
C. Main functions : .............................................................................. 21
1. Insert student ............................................................................. 21
2. Delete student ........................................................................... 24
3. Update student .......................................................................... 30
4. Search Student .......................................................................... 35
5. Sort student ............................................................................... 47
6. View list ..................................................................................... 50
IV. Discussion ......................................................................................... 52
A. Advantages .................................................................................... 52
B. Disadvantages ............................................................................... 52
V. Conclusion .......................................................................................... 53
A. Lessons learned through project .................................................... 53
B. Member Contribution...................................................................... 53

I. Project Information
2
A. Project’s plan

1. Project topic : Student management system - Developed for admins to manage student
records

2. Project description : The system will allow users to perform various operations such as
adding, deleting, and updating, searching and sorting student records, as well as displaying
student information.The system’s functions should work smoothly as intended without any bugs
or unexpected behaviors.

3. Programming language of choice : C++ .

4. Data structure : Linked list.

5. Main functions

⚫ Add student - Trương Văn An


The system should allow users to add new student records, including information such as
name, student ID, student class, etc.
⚫ Delete student - Nguyễn Đức Huy
Users should be able to delete a student record from the system based on the student's ID or
other unique identifier.
⚫ Update student - Nguyễn Minh Đức
The system should provide functionality to update student information, such as modifying
name, class.
⚫ Search student - Phạm Nguyễn Minh Tuấn
Users should be able to search for a student record based on various criteria, such as name,
ID, or class.
⚫ Sort student - Tạ Duy Minh
Users should be able to sort students based on studentID or name.
⚫ View all student - Tạ Duy Minh
The system should be able to display the details of all students currently stored.

3
B. Analysis of requirements
1. Project’s application : The system will allow users to perform various operations such as adding,
deleting, and updating, searching and sorting student records, as well as displaying student
information.
2. User Interface: The system should have a user-friendly interface that is intuitive and easy to
navigate for users.
3. Performance: The system should be able to handle a large number of student records efficiently.
4. Error Handling : The system’s functions should work smoothly as intended without any bugs or
unexpected behaviors.

4
II. Design of the project

A. Data structure : Linked list


Student class (node) will have 7 variables : Studentid, surname, firstname, major, class,
phonenumber, LastUpdate( store the time in which the student’s information is updated). Finally, a
pointer to point to the next node to create a linked list structure.

- Data system : The data of this program will be stored in a txt file named “studentrecords.txt”
and the data updates in real time.

B. Design algorithm ( diagram )

5
1. Menu

6
2. Insert Student

7
3. Delete student

8
4. Update student

9
5. Search student

10
11
6. Sort student

12
7. View all student

13
III. Development of the project :
A. Student class define
Student class (node) will have 7 variables : Studentid, surname, firstname, major, class,
phonenumber, LastUpdate( store the time in which the student’s information is updated). Finally, a
pointer to point to the next node to create a linked list structure.

This code defines a student class with member variables representing student information and a
constructor to initialize a student object with specific attributes.

class student { ... };: Defines a class named student with several public data members (Studentid,
Surname, Firstname, Major, Class, Phonenumber, LastUpdate, next) and member functions
(student constructor and updateStudent function).

student::student(...) : This constructor initializes a student object with the provided values for the
student's ID, surname, first name, major, class, phone number, last update time, and the pointer to
the next student in a linked list.

void updateStudent(...) : This function is declared within the class but not defined in the provided
code snippet. It is intended to update a student's information based on the provided parameters
(new student ID, surname, first name, major, class, and phone number).

14
15
B. Menu

16
When first running the program, the terminal will display :

The readFile() function will run first.

The switch (choice) statement starts a switch statement based on the user’s input. Within the
switch statement, each case corresponds to a menu option that the user can choose:

Case 1: calls the insertStudent() function to allow the user to add new student.
Case 2: calls the deleteStudent() function to allow user to delete a student or all students.
Case 3: calls the updateStudent() function to allow the user to update a student’s info.
Case 4: calls the searchStudent() function to allow the user to search a student.
Case 5: calls the sortStudent() function to allow the user to sort students.
Case 6: calls the viewStudent() function to allow the user to view all students
Case 0: exit the program.

Finally, the default will handle any invalid input from the user and display an error message.

After case 1,2 and existing the program, safeFile() will run.

17
1. readFile()

This function is designed to read student records from a file named "studentrecords.txt" and
construct a linked list of student objects using the data from the file.

Various int variables and string variables containing student’s information are declared.

ifstream infile("studentrecords.txt", ios::in); opens the file "studentrecords.txt" in input mode


(ios::in) using an input file stream (ifstream) named infile.

infile >> numstudents;: This line reads the number of students from the file and stores it in the
variable numstudents.

infile.ignore(500, '\n');: It skips the rest of the current line after reading the number of students.

for (int count = 0; count < numstudents; count++): Starts a loop to read data for each student,
iterating numstudents times.

getline(infile, studentid, '\n');: Reads a line from the file and assigns the content to the studentid
variable.

18
Subsequent getline calls read and assign the surname, firstname, major, class, phone number,
and last update time of each student from the file.

Finally , root = new student(studentid, surname, firstname, major, clas, phonenumber,


lastUpdate, root);: Constructs a new student object using the read data and sets the root pointer
to point to this new student object.

2. safeFile()

This function is to writes student records stored in a linked list to a file named
"studentrecords.txt".

int count = countNodes(temp);: Calls a function countNodes to count the number of nodes
(students) in the linked list.

ofstream outFile("studentrecords.txt", ios::out);: Creates/open the file "studentrecords.txt"


for writing using an output file stream (ofstream) named outFile. The mode ios::out specifies that
the file will be opened for output operations.

outFile << count << "\n";: Writes the count of nodes (number of students) to the file.

while (temp != NULL) { ... }: Initiates a loop that iterates through each node of the linked list until it
reaches the end.

19
Inside the loop:
outFile << ... << "\n"; statements write the student's id, surname, first name, major, class, phone
number, and last update time to the file, each followed by a newline character.

temp = temp->next;: Moves temp to point to the next node in the linked list.

3. countNode()

The function starts by initializing an integer variable countB to 0. This variable will be used to keep
track of the number of nodes encountered in the linked list.

It uses a while loop that iterates through the linked list. The loop continues as long as the pointer
temp is not NULL, signifying the end of the list.

Within the loop, for each node visited, the countB counter is incremented by 1. This action
effectively counts the nodes in the linked list.

After incrementing the counter, the pointer temp is updated to point to the next node in the list
(temp = temp->next). This step moves the pointer forward to the subsequent node in the list.

The loop continues until temp becomes NULL, indicating the end of the linked list. At this point, the
loop terminates.
Finally, the function returns the total count of nodes stored in the countB variable. This count
represents the number of nodes in the linked list.

20
C. Main functions :
1. Insert student

When choosing 1 the below code will run :

First, the code will Declares variables to store student information: studentid, surname, firstname,
major, clas, phonenumber, lastUpdate.

21
Next, Prompts the user to enter the student's details using cout and getline for input.
Cout << “Enter student’s ID:\t” : will print a prompt asking the user to enter their student’s ID.

cin.ignore(500, '\n') : tells the input stream (cin) to discard up to 500 characters, or until it
encounters a newline character ('\n'), whichever comes first.

getline(cin, studentid, '\n') : will wait for the user to input their student ID and store the value in
the variable studentid as an integer.

Next, the code will check for Duplicate IDs :


⚫ Creates a temporary pointer temp to iterate through the linked list.
⚫ Loops through the list while temp is not nullptr:
◆ Compares the current node's Studentid with the entered studentid.
◆ If they match, prints a message indicating a duplicate ID, returns from the function
without inserting.

◆ If no match is found, moves temp to the next node in the list.

cout << "Enter student's surname:\t" : will print a prompt asking the user to enter their
surname.

22
getline(cin, surname, '\n') : will wait for the user to input their full surname and store the value
in the variable surname as a string.

cout << "Enter student's firstname:\t" : will print a prompt asking the user to enter their first
name.

getline(cin, firstname, '\n') : will wait for the user to input their first name and store the value
in the variable firstname as a string.

cout << "Enter student's major:\t" : will print a prompt asking the user to enter their major.
getline(cin, major, '\n') : will wait for the user to input their major and store the value in the
variable major as a string.

cout << "Enter student's class:\t" : will print a prompt asking the user to enter their class.
getline(cin, clas, '\n') : will wait for the user to input their class and store the value in the
variable clas as a string.

cout << "Enter student's phonenumber:\t" : will print a prompt asking the user to enter their
phone number.

getline(cin, phonenumber, '\n') : will wait for the user to input their phone number and store
the value in the variable phonenumber as a string.

Assigns the string "null" to the variable lastUpdate.

root = new student(studentid, surname, firstname, major, clas, phonenumber, lastUpdate,


root); :

23
⚫ new student(...) : Calls the constructor of the student class to create a new student object.
⚫ root = … :
Assigns the newly created student object (which is a pointer to the new node) to
the root variable.
This updates the head of the linked list to reference the newly inserted node.

cout << "Student record inserted successfully! Going back to menu." : inform the user that
the record has been successfully inserted by printing out the line, and the code will return back to
the menu.

2. Delete student

Choose 3: Delete Student or all students:


When running the code the terminal will display:

The provided code snippet is a function that provides a user interface for deleting student records.
Here's a detailed line-by-line explanation:

24
1. void deleteStudent(studentPtr &root): This line declares a function called deleteStudent
that takes a single argument: a reference to a studentPtr. The & symbol denotes that this is
a reference parameter, meaning changes made to root within the function will affect the
original variable passed in.
2. deleteRestart:: This is a label that can be used for goto statements.
3. int choice;: This line declares an integer variable named choice. This variable will later hold
the user's selection from the menu.
4. cout << "Choose an option:\n"; ,cout << "1. Delete a student\n"; ,cout << "2. Delete
ALL records\n"; ,cout << "3. Exit to menu\n"; These lines prints out all the options
available
5. cout << "\nEnter your Choice:\n";: This line prints another prompt to the console, asking
the user to enter their choice.
6. cin >> choice;: This line reads the user's input from the console and stores it in the choice
variable.
If the user choose 1 the below code will run:

25
1. int studentid; - This line declares an integer variable studentid, which will be used to store
the ID of the student to be deleted.
2. cout << "Enter student ID to delete: "; - This line outputs a message to the console asking
the user to enter the student ID to be deleted.

3. cin.ignore(500, '\n'); - This line ignores up to 500 characters until a newline ('\n') character
is found. This is used to clear the input buffer.
4. cin >> studentid; - This line reads the student ID entered by the user from the console and
stores it in the studentid variable.
5. studentPtr p = locateNode(root, studentid); - This line calls the locateNode function,
passing the root of the linked list and the student ID as arguments. The function returns a
pointer to the node containing the student with the specified ID, or NULL if no such student
exists. The returned pointer is stored in p.
6. The if (p == NULL) block checks if p is NULL. If it is, it means the student with the specified
ID does not exist and display a message before returning to options menu.

7. If p is not NULL, that means a student ID is found and the code display all the student
informations with these code.The code will display the student informations along with a
confirmation promt:

26
If the user chooses “n” or “N” the code will display a message saying “Deletion canceled.” and
return to the menu

If the user choose “y” or “Y” the code below will run:

1. if (root == p) checks if the node to be deleted (p) is the root of the list. If it is, the next line
changes the root to the next node in the list.
2. root = p->next; If the node to be deleted is the root, this line updates the root pointer to skip
over the deleted node.
3. This begins the else clause of the previous if statement, which executes if the node to be
deleted is not the root and declares a new pointer q and studentPtr q = root; sets it to the
root of the list. This pointer will be used to traverse the list until it finds the node preceding
the one to be deleted.
4. while (q->next != p) This while loop continues as long as the next node pointed to by q is not
the node to be deleted. It moves q along the list one step at a time.
5. q = q->next; This line moves the q pointer one step forward in the list.
6. q->next = p->next; Once the correct node has been found (i.e., the node preceding the one

27
to be deleted), this line bypasses the node to be deleted by setting the next pointer of the
preceding node to point to the node after the one to be deleted.
7. delete p; This line deallocates the memory occupied by the node to be deleted. Then the
code will display a message saying “Record deleted successfully!”.

If the user choose 2 the below code will run:

1. The code first promt the user with a char confirmation just like the code above (note in the
code there are two confirmation to the user if they really want to delete all student
informations).
2. studentPtr current = root; This line initializes a pointer variable named current and
assigns it the address of the root node of the linked list.
3. while (current != nullptr) This line starts a loop that will continue as long as current is not
nullptr, which means as long as we have not reached the end of the linked list.
4. studentPtr next = current->next; This line creates another pointer variable named next
and assigns it the address of the next node in the linked list. This is done before deleting the
current node to avoid losing access to the rest of the list.
5. delete current; This line deletes the current node from memory. It doesn't automatically
update any pointers to this node, so those pointers become dangling pointers.

28
6. current = next; This line updates the current pointer to point to the next node in the list.
This allows us to move through the list one node at a time.
7. After the loop finishes, root = nullptr; sets the root of the linked list to nullptr, effectively
making the list empty.
8. Finally, the last two lines print out success messages to the console. These messages
indicate that all records have been deleted successfully and that the program is going back
to the menu.

(note this part of the code does not check if the list is already empty and will just simple delete
nothing if the list is empty)

locateNode():
The locateNode() function is a utility function in the code that helps locate a specific student node
in a linked list based on the student's ID. Let's break down the function line by line:

1. studentPtr locateNode(studentPtr temp, int studentid) This line declares the function
locateNode(). The function takes two parameters: temp, which is a pointer to a student
node, and studentid, which is the ID of the student to locate. The function returns a
studentPtr, which is a pointer to a student node.
2. while (temp != NULL) This line starts a while loop that continues as long as temp is not
NULL. temp is initially set to the root of the linked list and gets updated to point to the next
node in each iteration of the loop.
3. if (temp->Studentid == studentid) Inside the while loop, this line checks if the Studentid of

29
the current node (pointed to by temp) matches the studentid passed to the function. If they
match, it means the student has been found.
4. return temp; If the IDs match, the function immediately returns the temp pointer, which
currently points to the desired student node.
5. temp = temp->next; If the IDs don't match, this line updates temp to point to the next node
in the linked list by setting temp to temp->next. The loop then continues with the next node.
6. return NULL; If the function traverses the entire linked list without finding a student with the
matching ID, it returns NULL. This indicates that no student with the given ID was found in
the linked list.

In summary, the locateNode() function is a simple linear search algorithm used to find a specific
student node in a linked list based on their ID.

3. Update student
Before we get in to our main function, we have to go through our declaration for the parameter in
class student which is void student : : updateStudent function:

1.Parameter List:
⚫ int newStudentid: The new student ID to be assigned.
⚫ const string &newSurname: The new surname to be assigned.
⚫ const string &newFirstname: The new firstname to be assigned.
⚫ const string &newMajor: The new major to be assigned.
⚫ const string &newClass: The new class to be assigned.
⚫ const string newPhonenumber: The new phone number to be assigned.
2. Updating data members:
⚫ Studentid = newStudentid;
⚫ Surname = newSurname;
⚫ Firstname = newFirstname;
⚫ Major = newMajor;
⚫ Class = newClass;
⚫ Phonenumber = newPhonenumber;
3. Updating Last Update Time:
⚫ The function records the current timestamp as the last update time. This is achieved using the
C++ <chrono> library:

30
⚫ Here, ‘now’ represents the current time point, and time_t_now is a time_t type representing
the same time point.
4.Formatting Timestamp as a String:
⚫ The std::put_time function is then used to format the timestamp as a string. This string is
formatted according to the specified format ("%d-%m-%Y %H:%M:%S"):

⚫ The formatted string is stored in the LastUpdate data member of the student object.
⚫ Noted that the reason why we still used the std prefix because ostringstream, put_time and
localtime even though were not necessary but just to avoiding naming conflict might happen.

*When choose 3 the terminal will display as follows:

While screen play, the code below will run:

First the function using if-else if-else conditional will give you 3 options going as choices:
1. Update a student (choice 1)
2. View all updated student records (choice 2)
3. Go back to menu (choice 3)

⚫ If we choose none of the above the following code will run

⚫ As we set our updateStudent function in the start with updateRestart, all the input that’s none
of the options we gave, it will prints out a notification and goto updateRestart as we set at the
beginning of the function to make our decision again.

Option 1. Update a student:


First the function will ask for the id of the student that need to update, the terminal will display as

follows:
And the code that is running was:

31
After input the id(int studentIDToUpdate) that need to update the function will use function
locateNode to find the student with the value (temp, studentIDToUpdate). It check if the pointer
studentToUpdate is exist or not.(Noted that in the rest of the updateStudent function the
studentToUpdate is the pointer that save the information of the student.)
So in my case there a 2 possibilities might happen:
1. The input id wasn’t exist:
It will display:

2. The input id exist:

It continue to proceed with a if conditional statement,if studentToUpdate is


existed(!=nullptr) the next step as you can see it ask for the updated id first and the reason for it
was there’s gonna be 3 case that might happen:
1. The id that updated is the same as the id’s used to find the student.
2. The id that updated is different to the id’s used to find the student and duplicated to other
student’s id.
3. The id that updated is different to the id’s used to find the student nut not duplicated to other
student’s id.

1. The id that updated is the same as the id’s used to find the student.
(studentid ==studentIDToUpdate)

⚫ The function start with a if conditional statement which if the Id is the same as the one
we find the student with so it’s continue to ask for the rest updates which is surname,
firstname, major, class, phone number.
⚫ After input all the information, the function proceed to save s to updateStudent. It

32
updates the record
⚫ It prints a success message and go back to menu after a set of time.

2. The id that updated is different to the id’s used to find the student and duplicated to other
student’s id.
⚫ As mention with other declaration, the check =false was set by default, it was set to check if
the id is duplicated or not.

⚫ We run a while loop to go through all the student in the record with temp as a pointer for class
student. The while loop ends when it gone through all the student.
⚫ Next thing we using if conditional statement to check if the student id in the record (temp-
>Studentid) is duplicated to the id we update (student), if it is, the check will be true and a
message will display to say the id’s already existed. After this the while loop would break
immediately and return to the main menu.

⚫ If after the while loop ended, and the check still false, it means there is not duplicated id, we go
to the next case.
3. The id that updated is different to the id’s used to find the student nut not duplicated to other
student’s id.
⚫ From the previous code we will receive the default check, which is check = false, the code
below will run:

⚫ Again the function using if conditional statement, then it proceed to get the rest updates which

33
is surname, firstname, major, class, phone number.
⚫ After input all the information, the function proceed to save information to updateStudent. It
updates the record
⚫ In the end, a message would pop up to show that it updated succesfully and go back to the
menu with a set of time:

Option 2:View all updated student records


- For the context, the intentional of this option was to show all and only the Updated student with a
real time.

- The function viewAllUpdates was call and it value was temp, here’s the full function:

⚫ There’s only one declaration for this function which was count = 1, which was for counting how
many record we get.
⚫ It run a while loop to go through all the student records, but it only prints the student that had a
real value with lastUpdate, the function is going to print all the student records with satisfied
the if condition.
⚫ After it print all out, the function is pause by system until we press any button. It will display a
message “Going back to menu” with a set of time and clear the screen.

Option 3: Go back to menu


-The context for this function is just when you press 3(update student) in the menu by mistake, it
will bring you back to the main menu within a set of time and clear the screen:

34
4. Search Student

1. Menu of the Function 4:


Output:

Function 4 has 8 search options corresponding to each item: ID, full name, first name, sur
name, major, class, phone number. The last option is Exit, used to return to the main menu of
the management program.
Code:

- “ int searchOption”: declare a variable named “searchOption” with data type int. This
variable will be used to store the user's search selection.
- Use “cout” to output messages to the console screen.
- “ cin >> searchOption” : use “cin” to get the value the user enters from the keyboard and
store that value in the “searchOption” variable.
- “ system(“cls”) “: used to clear the console screen. This command helps clean the screen
before displaying search results.

35
- Declare a "bool" variable named "exist" with value "false" to check whether the search data
exists or not
2. Switch – Case:

Use the switch - case to create search cases, in this program there are a total of 8 cases: 1
for search by ID, 2 for search by Name (Full Name), 3 for search by First name, 4 for search
by Surname, 5 for search by Major, 6 for search by Class, 7 for search by Phone number and
finally 0 to return to the main Menu.
Case 1:
Output:

Code:

- Declare the variable "studentid" with data type int, used to store the student code the user
wants to search
- Use “cout” to output messages to the console screen.
- "cin.ignore(500, '\n')" is used to remove any extra characters in the input buffer after the
previous output command and before using the "getline". It will skip up to 500 characters or
stop when it encounters a newline character ('\n') .
- "getline(cin, student, '\n')" is used to get input from keyboard and store in "studentid",
function "getline" will read data from input buffer until encounter the line break character ('\n
'). Where "cin" is used to read data from the keyboard or from a standard input data source.

- Use a "while" loop to iterate over the list of available students until the end of the list as
long as the temp pointer is non-null ( temp != NULL ).
o If temp is not NULL, meaning it is pointing to a valid object, the loop will execute the
statements inside.

36
o If temp equals NULL, the condition “temp != NULL” becomes false, and the loop
ends.

- "temp->next" is the pointer to the next element in the list. Give " temp = temp -> next” to
make the loop iterate over each element in the list.

- Use the "if" statement with the condition "studentid == temp->Studentid" to check if the
entered student code is the same as the current student code (temp->Studentid)
- Use “cout” to output messages to the console screen.
- The temporary object being pointed to (temp->Studentid, temp->Surname, temp-
>Firstname, temp->Major, temp->Class, temp->Phonenumber) will be output to the
console screen if it is finds and matches the student code entered from the keyboard.
- "exist" is used to check after the loop ends (or after the search has completed) whether any
students were found.
- Assign the value "true" to the variable "exist" to mark the student found corresponding to
the value entered from the keyboard.
Case 1: Search by ID is a case with a unique value, each student will have a different ID
and that ID is unique

Case 2:
Output:

Code:

37
- Declare the variable "fname" with data type string (str), used to store the full name of
students and users searching
- Use “cout” to output messages to the console screen.
- "cin.ignore(500, '\n')" is used to remove any extra characters in the input buffer after the
previous output command and before using the "getline". It will skip up to 500 characters or
stop when it encounters a newline character ('\n') .
- "getline(cin, fname, '\n')" is used to get input from keyboard and store in "fname", function
"getline" will read data from input buffer until encounter the line break character ('\n ').
Where "cin" is used to read data from the keyboard or from a standard input data source.
- Declare the variable "count" with data type number ( int ) with an initial value of 1. This
variable will be used to count the number of students found.

- Use a "while" loop to iterate over the list of available students until the end of the list as long
as the temp pointer is non-null ( temp != NULL ).
o If temp is not NULL, meaning it is pointing to a valid object, the loop will execute the
statements inside.
o If temp equals NULL, the condition “temp != NULL” becomes false, and the loop
ends.

38
- "temp->next" is the pointer to the next element in the list. Give " temp = temp -> next” to
make the loop iterate over each element in the list.

- This line of code creates a new string (full_name) by concatenating two strings: temp-
>Surname and temp->Firstname, with a space between them.
o “temp->Surname”: temp pointer points to "Surname"
o " ": is a space
o “temp->Firstname”: temp pointer points to "Firstname"

- "full_name.begin()", "full_name.end()": Are the first and last iterators of the string
"full_name". This code will apply the conversion to all characters within this range.
- "full_name.begin()": Is the iterator of the starting position of the full_name string. The
conversion results will be saved immediately at this location.
- "::toupper": Is a global function in the C++ <cctype> library, converting lowercase letters to
uppercase letters.
- The same goes for "Fname"
- Using the + operator to concatenate the above strings together will create a new string that
is stored in the “full_name” variable.

- Use the "if" statement with the condition "fname == full_name" to check whether the
entered student's full name matches the existing student's full name.
- Use “cout” to output messages to the console screen.
- The temporary object being pointed to (temp->Studentid, temp->Surname, temp-
>Firstname, temp->Major, temp->Class, temp->Phonenumber) will be output to the
console screen if it is finds and matches the student code entered from the keyboard.
- "exist" is used to check after the loop ends (or after the search has completed) whether any
students were found.
- Assign the value "true" to the variable "exist" to mark the student found corresponding to
the value entered from the keyboard.

- Because we declare "count = 1" and "count" is a count variable that is increased gradually
after finding each student in the loop, when counting the total number of students found, use
"count - 1" to display the exact number student was found on the console screen.
Case 2 of searching by Name (Full name) is the case where more than 1 student is found
because that student's full name can be duplicated. So it will print to the console screen
adding "total number of students found"

39
Case 3:
Output:

Code:

Case 4:
Output:

Code:

40
Case 5:
Output:

Code:

41
Case 6:
Output:

Code:

42
The code commands and code functions in cases 3 (search by Firstname), 4 (search by
Surname) , 5 (search by Major), 6 (search by Class) have the same usage and operating
method as case 2. In addition, these cases will also be added "total number of students
found" because they are not cases containing unique data.

Case 7:
Output:

Code:

43
The code statements and code functions in case 7: search by Phonenumber have the same
usage and operation as case 1 and this case is also a case containing unique data because
phone numbers cannot be duplicated.
Case 8:

- Show the console screen message "back to menu"


- Set the "exist" variable to "true", it can be assumed that this variable is used to mark
whether a student is found and the program continues.
- system("cls"): Use system commands to clear the screen. This creates the impression that
the program is "going back to menu" by clearing the current screen.

- If the value in the switch expression does not match any of the cases, the program will
execute the statements under default
- Output to the console screen the message "Invalid option".
- Set the "exist" variable to "true", it can be assumed that this variable is used to mark
whether a student is found and the program continues.

3. If with the condition “exist = false”:

44
Output:

Code:

- If “exist” is “false”, it means no students were found during the search, so the message
"Student not found in the records." will be output to the console screen
- “std::endl” is a manipulator used to add a newline to the output and refresh the output
buffer.

4. Countdown to return to menu

- Creates a delay between the output of the message "Going back to menu."
- "std::this_thread::sleep_for(std::chrono::seconds(1));": Used to pause program
execution for 1 second. The <chrono> and <thread> libraries are used to implement this
functionality.

Getline():

These two functions have the common function of reading data from the "istream" object and
assigning that value to a variable of type:
- "std::string" in the case of the first function .

45
- "int" in the case of the second function.

- "istream &stream": The input parameter, a reference to the "istream" object, is the data
source from which the data is read.
- "string &string": Output parameter, which is a reference to the "string" object. The value
read from "stream" will be assigned to this variable.
- "char delimiter": The input parameter, which is the delimiter, is the character the function
will use to complete reading data from the "stream".
- "char temp[500];": Declare a temporary character array "temp" of size "500". This array is
used to store data from "istream" until the "delimiter" character is encountered.
- "stream.get(temp, 500, delimiter);": Call the "get" method on the "istream" object to read
data from "stream" into the "temp" array. This method will read up to "499" characters or
until the "delimiter" character is encountered. Data is stored in temp and ends with the
character "null"
- "stream.ignore(500, delimiter);": Call the "ignore" method to ignore the "delimiter"
character after reading data into "temp", ignoring up to "500" characters. This is necessary
to prepare for subsequent reads, avoiding reading the old "delimiter" character in the next
step.
- "string = temp;": Assign the value of the array "temp" (containing data read from "stream")
to the variable "string". This is possible because "string" can usually be assigned a value
from an array of characters.

- "int &num": Output parameter, which is a reference to an integer variable. The value read
from "stream" will be assigned to this variable.
- "int temp": A temporary variable to store integer value read from "stream".
- "stream >> temp": The ">>" operator is used to read an integer value from "stream" and
assign it to the variable "temp".

46
- "num = temp;": Assign the value of variable "temp" to variable "num" via reference

5. Sort student

When choosing 5 the screen will illustrate 4 options :

This menu run by if else based on user input by cin<<choice.


This function allows user to sort Students in ascending order based on 3 keywords.

Choice 1: Sorting by StudentID


Choice 2: Sorting by Name.
Choice 3: Sorting by Class.

Because all there option works very similary and all based on Bubble Sort, I will only explain the
first option: Sorting by Student ID

The Sorting:

The code first checks if the root pointer is NULL. If it is NULL, it returns from the function.

47
The sorting algorithm used is a variation of Bubble Sort . In this option, it sorts students based on
Studentid.

Inside the do-while loop:


swapped variable is used to track whether any swapping occurred during the iteration.
ptr is set to root, and tptr is initialized to NULL.

Within the inner while loop, it iterates through the linked list nodes.

For each node, it compares the Studentid of the current node (ptr) with the Studentid of its next
node (ptr->next).

If the Studentid of the current node is greater than the Studentid of the next node, it swaps the
nodes by calling a function swapNodes(ptr, ptr->next) and sets swapped to 1.

The other two options (Choice 2: Sorting by Name; Choice 3: Sorting by Class ) use the same
principal but different condition in the if statement to compare to Nodes.
swapNodes():

This function use a very commonly used technique to swap nodes or variables .

48
After iterating through the list, tptr is updated to the last checked node.

The loop continue until there is no swapping occur.

After the swapping is done, two options will be presented to users:

And this is the code :

Option 1: Display the sorted student records by calling viewAll() function.

Option 2: Return to the main menu by calling main() function (using recursion).

If the user enters an invalid choice, it displays an error message, delays the output, and redirects
the user back to the choice input prompt (goto redirectRestart;).

49
After everything is done, the program then returns to the menu.

6. View list

After pressing 6, the program will show user the student list, here is an example:

Here is the corresponding code:


int count = 0;
while (temp != NULL)
{
cout << "<================================================>\n";
cout << "No:\t" << count++ << "\n";
cout << "StudentID:\t" << temp->Studentid << "\n";
cout << "Surname:\t" << temp->Surname << "\n";
cout << "Firstname:\t" << temp->Firstname << "\n";
cout << "Major:\t" << temp->Major << "\n";
cout << "Class:\t" << temp->Class << "\n";
cout << "Phone number:\t" << temp->Phonenumber << "\n";
temp = temp->next;
}
cout << "\n<==== Total number of student : "
<< count
<< " ====>\n\n";

system("pause");

50
cout << "Going back to menu.";

int count = 0;: Initializes a counter.


while (temp != NULL) { ... }: Initiates a while loop to traverse through the linked list of students.

Inside the loop:


Outputs formatted information about each student's attributes (StudentID, Surname, Firstname,
Major, Class, Phone number) using cout statements.
Increments the count variable to keep track of the number of students displayed.

After the loop:


Displays the total number of students using cout.

After the user see the student, user can press any key one more time to return to the menu.

51
IV. Discussion
A. Advantages

⚫ Modular Design: The code is well-structured and modular. Each function performs a specific
task, making the code easier to understand and maintain
⚫ Data Persistence: The program reads and writes student records from a file, ensuring that the
data isn't lost when the program exits. It also updates the file whenever changes are made to
the student records
⚫ Error Handling: The program checks for errors, such as attempting to delete a non-existent
student or update a student with an ID that already exists
⚫ User Interface: The program provides a simple and intuitive interface for users to interact with
the student records. Users can create, delete, update, and search for student records, as well
as sort the records by student ID, name, or class
⚫ Efficient Data Management: The program uses a linked list to store student records, which
allows for efficient insertions and deletions. This is because these operations can be done in
constant time, unlike arrays where they require shifting elements
⚫ Customizable Sorting: The program allows the user to sort the student records by student ID,
name, or class. This provides flexibility in how the data can be organized
⚫ Real-Time Updates: The program records the last update time for each student, which allows
for tracking changes in real time

B. Disadvantages

⚫ Singer-user Usage: the application appears to be designed for a single user. It doesn’t have
features to support multiple users or user authentication, which limits its usability in a shared
environment.
⚫ No Data Backup: although the application automatically saves the contact data to a file upon
exit, there is no provision for creating regular backups or restoring previous versions of the
contact list in case of data loss or accidental changes.
⚫ Use of goto Statement: The use of the goto statement in the code can make the control flow
hard to follow. The goto statement can lead to spaghetti code, which is hard to read, debug,
and maintain. It's generally recommended to avoid using goto and instead use structured
programming const
⚫ Limited Error Checking: While the program does some error checking (e.g., checking if a
student ID already exists), it doesn't check for other potential errors, such as invalid input
formats or missing required fields.

52
V. Conclusion
A. Lessons learned through project
Through this topic, we learn several important aspects of developing and understanding a student
management system. Here are some points we’ve learned from this topic:
- Basic Application Programming
- File Interaction
- Validation and Error Handling
- Creating a Command-Line Interface
- Data Management
- Integrating User Interaction
- Understanding User Requirements

B. Member Contribution

53

You might also like