-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_funcs.cpp
61 lines (52 loc) · 1.17 KB
/
helper_funcs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "main.h"
#include <chrono>
#include <thread>
/**
* calculateCGPA - calculate cgpa for a particular student
* @student: student node for a particular student
*
* Return: calculated cgpa
*/
double calculateGPA(StudentNode* student)
{
double totalGradePoints = 0.0;
int totalCreditHours = 0;
SubjectNode* current = student->subjects;
while (current != nullptr)
{
totalGradePoints += current->gradePoint * current->creditHours;
totalCreditHours += current->creditHours;
current = current->next;
}
if (totalCreditHours == 0)
{
return 0.0;
}
return totalGradePoints / totalCreditHours;
}
/**
* waitForEnterKey - just a dummy func to wait for enter key
*
* Return: Nothing
*/
void waitForEnterKey()
{
std::cout << "Press Enter to continue...";
std::cin.get(); // Wait for a single character input (Enter key)
}
/**
* clearTerminal - clears terminal after a certain operation
*
* Return: nothing
*/
void clearTerminal()
{
// std::this_thread::sleep_for(std::chrono::seconds(1));
#ifdef _WIN32
// Use the "cls" command on Windows
system("cls");
#else
// Use the "clear" command on Unix-like systems
system("clear");
#endif
}