itsshivamku / CPP-Programming

C++ Programming Projects
0 stars 0 forks source link

STUDENT GRADING SYSTEM using C++ Programming #2

Open itsshivamku opened 1 year ago

itsshivamku commented 1 year ago

include

include

include

using namespace std;

class Student { public: string name; double score;

Student(const string& n, double s) : name(n), score(s) {}

};

char getGrade(double score) { if (score >= 90) return 'A'; if (score >= 80) return 'B'; if (score >= 70) return 'C'; if (score >= 60) return 'D'; return 'F'; }

int main() { const int numStudents = 5; Student students[numStudents];

cout << "Student Grading System\n";

for (int i = 0; i < numStudents; ++i) {
    string name;
    double score;

    cout << "Enter name of student " << i+1 << ": ";
    getline(cin >> ws, name);  // To handle spaces in the name

    cout << "Enter score of student " << i+1 << ": ";
    cin >> score;

    students[i] = Student(name, score);
}

double totalScore = 0;
for (int i = 0; i < numStudents; ++i) {
    totalScore += students[i].score;
}

double averageScore = totalScore / numStudents;

cout << "\nStudent Report:\n";
cout << "-------------------------------------\n";
cout << setw(20) << left << "Name" << setw(10) << "Score" << setw(10) << "Grade" << endl;
cout << "-------------------------------------\n";

for (int i = 0; i < numStudents; ++i) {
    char grade = getGrade(students[i].score);
    cout << setw(20) << left << students[i].name << setw(10) << students[i].score << setw(10) << grade << endl;
}

cout << "-------------------------------------\n";
cout << "Average Score: " << averageScore << endl;

return 0;

}