-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathmain.cpp
217 lines (194 loc) · 6.66 KB
/
main.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*This C++ PROGRAM is developed by NemonET TYP and
special right is given to TEAM TYP for educational purpose */
//Don't copy source code without permission
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
using namespace std;
void calculateGPA();
void calculateCGPA();
void method();
void inputValidation(int& input, int lowerInputLeveler, int aboveInputLeveler, const string& labelMessage);
int main()
{
system("cls");
int input;
int aboveLabel = 4;
int lowerLabel = 1;
cout<<"--------------------------------------------------------------------------"<<endl;
cout<<" GPA & CGPA Calculator (Developed by Nemo) "<<endl;
cout<<"--------------------------------------------------------------------------\n"<<endl;
cout<<" MENU:"<<endl;
cout<<" 1. Calculate GPA (Grade Point Average)"<<endl;
cout<<" 2. Calculate CGPA (Cummulative Grade Point Average)"<<endl;
cout<<" 3. Method that is applied here for calclating GPA & CGPA"<<endl;
cout<<" 4. Exit Application"<<endl;
cout<<"--------------------------------------------------------------------------"<<endl;
cout << "Enter your choice: ";
inputValidation(input, lowerLabel, aboveLabel, "Ente your choice");
switch (input)
{
case 1:
calculateGPA();
break;
case 2:
calculateCGPA();
break;
case 3:
method();
break;
case 4:
exit(EXIT_SUCCESS);
break;
}
}
void calculateGPA()
{
int q;
system("cls");
//in this case the validation is not made to label rather the size of array, we make the lower 1 because we cannot calculate anything for 0 subjects
int lowerArraysizePossible = 1;
int bigArraySizePossible = numeric_limits<int>::max();
int lowerGrade = 0;
int aboveGrade = 4;
int lowerCredit = 0;
int aboveCredit = 10;
cout<<"-------------- GPA Calculating -----------------"<<endl;
cout<<" How many subject's points do you want to calculate? : ";
inputValidation(q, lowerArraysizePossible, bigArraySizePossible, "how many subject's points do you want to calculate");
vector<int> credit(q);
vector<int> point(q);
cout<<endl;
for(int i=0;i<q;i++)
{
cout<<"Enter the credit for the subject "<<i+1<<": ";
inputValidation(credit[i], lowerGrade, aboveGrade, "Enter the credit for the subject");
cout<<endl;
cout<<"Enter the point of the subject "<<i+1<<": ";
inputValidation(point[i], lowerGrade, aboveGrade, "Enter the point for the subject");
cout<<"-----------------------------------\n\n"<<endl;
}
float sum=0;
float tot;
for(int j=0;j<q;j++)
{
tot=credit[j]*point[j];
sum=sum+tot;
}
float totCr=0;
for(int k=0;k<q;k++)
{
totCr=totCr+credit[k];
}
cout<<"\n\n\nTotal Points: "<<sum<<" . Total Credits: "<<totCr<<" .Total GPA: "<<sum/totCr<<" ."<<endl;
//there are 3 labeles to be validated
int lowerLabeler = 1;
int higherLabeler = 4;
int inmenu;
cout<<"\n\n\n1. Calculate Again"<<endl;
cout<<"2. Go Back to Main Menu"<<endl;
cout<<"3. Exit This App \n\n"<<endl;
cout<<"Your Input: "<<endl;
inputValidation(inmenu, lowerLabeler, higherLabeler, "Your label input");
switch(inmenu)
{
case 1:
calculateGPA();
break;
case 2:
main();
break;
case 3:
exit(EXIT_SUCCESS);
}
}
void calculateCGPA()
{
system("cls");
//the validation parameter for the semister size and the grade input
int lowerSemisterSizePossible = 2;
int higherSemisterSizePossible = numeric_limits<int>::max();
int lowerGradePossible = 0;//(f)
int higherGradePossible = 4;//(A);
int l;
cout<<"-------------- CGPA Calculating -----------------\n\n"<<endl;
cout<<"How many semester results do you want input? :";
inputValidation(l, lowerSemisterSizePossible, higherSemisterSizePossible, "how many semseter results do you want input");
cout<<"\n\n"<<endl;
vector<int> semrs(l);
int i;
for(i=0;i<l;i++)
{
cout<<" Enter Semester "<<i+1<<" Result(GPA): ";
inputValidation(semrs[i], lowerGradePossible, higherGradePossible, "Result CGPA");
cout<<"\n"<<endl;
}
float semtot=0;
for(int j=0;j<l;j++)
{
semtot=semtot+semrs[j];
}
//the validation paramater for the label
int lowerLabel = 1;
int aboveLabel = 3;
cout << "******** Your CGPA is " << semtot / l << " **********" << endl;
int inmenu;
cout<<"\n\n\n1. Calculate Again"<<endl;
cout<<"2. Go Back to Main Menu"<<endl;
cout<<"3. Exit This App \n\n"<<endl;
cout<<"Your Input: "<<endl;
inputValidation(inmenu, lowerLabel, aboveLabel, "your label input");
switch(inmenu)
{
case 1:
calculateCGPA();
break;
case 2:
main();
break;
case 3:
exit(EXIT_SUCCESS);
}
}
void method()
{
//since there are only two leveles that are (go back to mainmenu and exit app)
int lowerLabel = 1;
int aboveLabel = 2;
system("cls");
cout<<"--------------- Method of Calculating GPA & CGPA ---------------\n\n"<<endl;
cout<<" GPA= Sum of (Credit*Point) / total of credits \n"<<endl;
cout<<" CGPA= Sum of GPA / number of semesters "<<endl;
cout<<"-----------------------------------------------------------------\n\n"<<endl;
int inmenu;
cout<<"1. Go Back to Main Menu"<<endl;
cout<<"2. Exit This App \n\n"<<endl;
cout<<"Your Input: "<<endl;
inputValidation(inmenu, lowerLabel, aboveLabel, "your label input");
switch(inmenu)
{
case 1:
main();
break;
case 2:
exit(EXIT_SUCCESS);
}
};
void inputValidation(int& input, int lowerBound, int upperBound, const std::string& labelMessage) {
while (true) {
if (std::cin >> input) {
if (input >= lowerBound && input <= upperBound) {
break;
}
else {
std::cout << "Please enter a number between " << lowerBound << " and " << upperBound << " (" << labelMessage << ")" << std::endl;
}
}
else {
std::cout << "Invalid input. Please enter a valid number (" << labelMessage << ")" << std::endl;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
}
}