-
Notifications
You must be signed in to change notification settings - Fork 0
/
SGPA Calculation Program By Arrays and Functions with Validations.cpp
201 lines (157 loc) · 3.31 KB
/
SGPA Calculation Program By Arrays and Functions with Validations.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
#include <iostream>
#include<string>
using namespace std;
const int SIZE = 8;
void GetData(string Courses[], int CrHrs[],int Marks[]);
void AssignGrades(int Marks[], string Grade[], float score[]);
void GetSGPA(float score[], int CrHrs[], int& CrErnd, float& SGPA);
void PrintData(string Courses[], int Marks[], string Grade[], int SGPA, int CrErnd);
bool CoursenameValidation(string, string Courses[],int);
int main()
{
string Courses[SIZE];
int CrHrs[SIZE];
int Marks[SIZE];
string Grade[SIZE];
float score[SIZE];
float SGPA;
int CrErnd;
GetData(Courses, CrHrs,Marks);
AssignGrades(Marks, Grade, score);
GetSGPA(score, CrHrs,CrErnd,SGPA);
PrintData(Courses,Marks,Grade,SGPA,CrErnd);
system("pause");
}
void GetData(string Courses[], int CrHrs[], int Marks[])
{
for (int i = 0; i < SIZE; i++)
{
cout << "Enter the Course Name: ";
getline(cin,Courses[i]);
while (!(CoursenameValidation(Courses[i], Courses, i)))
{
cout << "Invalid Input...This Course Already Exists.";
cout << "Enter the Course Name: ";
getline(cin, Courses[i]);
}
cout << "\nEnter the Credit Hours of " << Courses[i] << ": ";
cin >> CrHrs[i];
while (CrHrs[i] <= 0)
{
cout << "\n Invalid Input...";
cout << "\nEnter the Credit Hours of " << Courses[i] << ": ";
cin >> CrHrs[i];
}
cout << "\nEnter the Marks of Student in " << Courses[i] << ":";
cin >> Marks[i];
while (Marks[i] < 0||Marks[i] > 100)
{
cout << "\n Invalid Input....";
cout << "\nEnter the Credit Hours of " << Courses[i] << ": ";
cin >> Marks[i];
}
cin.ignore(256, '\n');
}
}
void AssignGrades(int Marks[], string Grade[], float score[])
{
for (int i = 0; i < SIZE; i++)
{
if (Marks[i] >= 90)
{
Grade[i] = "A+";
score[i] = 4.00;
}
else if (Marks[i] >= 86)
{
Grade[i] = "A";
score[i] = 4.00;
}
else if (Marks[i] >= 82)
{
Grade[i] = "A-";
score[i] = 3.67;
}
else if (Marks[i] >= 78)
{
Grade[i] = "B+";
score[i] = 3.33;
}
else if (Marks[i] >= 74)
{
Grade[i] = "B";
score[i] = 3.00;
}
else if (Marks[i] >= 70)
{
Grade[i] = "B-";
score[i] = 2.67;
}
else if (Marks[i] >= 66)
{
Grade[i] = "C+";
score[i] = 2.33;
}
else if (Marks[i] >= 62)
{
Grade[i] = "C";
score[i] = 2.00;
}
else if (Marks[i] >= 58)
{
Grade[i] = "C-";
score[i] = 1.67;
}
else if (Marks[i] >= 54)
{
Grade[i] = "D+";
score[i] = 1.33;
}
else if (Marks[i] >= 50)
{
Grade[i] = "D";
score[i] = 1.00;
}
else if (Marks[i] >=0)
{
Grade[i] = "F";
score[i] = 0.00;
}
}
}
void GetSGPA(float score[], int CrHrs[], int &CrErnd, float &SGPA)
{
CrErnd = 0;
float temp=0;
float totalCr=0;
for (int i = 0; i < SIZE; i++)
{
totalCr += CrHrs[i];
if (score[i]>=1)
{
CrErnd+=CrHrs[i];
temp += score[i] * CrHrs[i];
}
}
SGPA = temp / totalCr;
}
void PrintData(string Courses[], int Marks[], string Grade[], int SGPA, int CrErnd)
{
for (int i = 0; i < SIZE; i++)
{
cout << Courses[i] << "\t" << Marks[i] << "\t" << Grade[i] << endl;
}
cout << "SGPA: " << SGPA << endl;
cout << "Earned Credit Hours: "<<CrErnd << endl;
}
bool CoursenameValidation(string course, string Courses[SIZE],int index)
{
for (int i = 0; i < index; i++)
{
if (Courses[i] == course)
{
return false;
}
}
return true;
}