-
Notifications
You must be signed in to change notification settings - Fork 0
/
StudentGradingSystem.cpp
73 lines (59 loc) · 1.63 KB
/
StudentGradingSystem.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
#include <iostream>
#include <string>
using namespace std;
class Student {
private:
string name;
int marks;
char grade;
public:
// Function to input student details
void inputDetails() {
cout << "Enter student name: ";
getline(cin, name);
cout << "Enter marks (0-100): ";
cin >> marks;
// Input validation
while (marks < 0 || marks > 100) {
cout << "Invalid marks! Please enter marks between 0 and 100: ";
cin >> marks;
}
calculateGrade();
}
// Function to calculate grade
void calculateGrade() {
if (marks >= 90) {
grade = 'A';
}
else if (marks >= 75) {
grade = 'B';
}
else if (marks >= 50) {
grade = 'C';
}
else {
grade = 'F';
}
}
// Function to display student details
void displayDetails() {
cout << "\nStudent Details:" << endl;
cout << "Name: " << name << endl;
cout << "Marks: " << marks << "%" << endl;
cout << "Grade: " << grade << endl;
}
};
int main() {
Student student;
char choice;
do {
// Clear input buffer
cin.ignore(numeric_limits<streamsize>::max(), '\n');
student.inputDetails();
student.displayDetails();
cout << "\nDo you want to calculate grades for another student? (y/n): ";
cin >> choice;
} while (choice == 'y' || choice == 'Y');
cout << "\nThank you for using the Student Grading System!" << endl;
return 0;
}