-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainV2.cpp
84 lines (71 loc) · 2.2 KB
/
mainV2.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <chrono>
#include <iostream>
#include <limits>
#include <thread>
class cGPAcalculator {
private:
unsigned int total_Subject;
double total_Marks;
unsigned int total_max_Marks;
public:
cGPAcalculator() : total_Subject(0), total_Marks(0), total_max_Marks(0) {}
void inputMarks() {
std::cout << "CGPA Calculator:-" << std::endl;
std::cout << "[$] Enter the total number of subjects: ";
std::cin >> total_Subject;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
for (unsigned int i = 0; i < total_Subject; ++i) {
double obtMarks;
std::cout << "[$] Enter your marks obtained for subject " << (i + 1)
<< ": ";
std::cin >> obtMarks;
total_Marks += obtMarks;
}
total_max_Marks = total_Subject * 100;
}
void showProgressBar(int progress, int total, int barWidth = 50) {
float ratio = static_cast<float>(progress) / total;
int filleWidth = static_cast<int>(ratio * barWidth);
std::cout << "[";
for (int i = 0; i < barWidth; ++i) {
if (i < filleWidth) {
// std::cout << "\033[32m=\033[0m";
std::cout << "\033[32m#\033[0m";
} else {
std::cout << " ";
}
}
std::cout << "] progress " << int(ratio * 100.0) << "%\r";
std::cout.flush();
}
double calculatePercentage() const {
if (total_max_Marks == 0) {
std::cout << "[!] Error: The maximum number can't be zero..."
<< std::endl;
return 1;
}
return (total_Marks / total_max_Marks) * 100;
}
double calculateCGPA(double percentage) const { return percentage / 9.5; }
void displayResults() const {
double percentage = calculatePercentage();
if (percentage > 0) {
std::cout << "[@] The total percentage: " << percentage << "%"
<< std::endl;
double cgpa = calculateCGPA(percentage);
std::cout << "[@] The CGPA is: " << cgpa << std::endl;
}
}
};
int main() {
cGPAcalculator calc;
calc.inputMarks();
const int total = 100;
for (int i = 0; i <= total; ++i) {
calc.showProgressBar(i, total);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
std::cout << std::endl;
calc.displayResults();
return 0;
}